From d96d1138147b443a9d37f58ddd10448a4b2d77e5 Mon Sep 17 00:00:00 2001 From: jash Date: Sun, 7 Oct 2018 00:10:48 +0200 Subject: [PATCH] added simple config file template support --- .../generators/app/features/000_cyphernode.js | 3 +++ .../generators/app/features/100_bitcoin.js | 3 +++ .../generators/app/features/200_lightning.js | 10 +++++++ .../generators/app/features/300_electrum.js | 3 +++ .../app/features/400_opentimestamps.js | 3 +++ .../generators/app/index.js | 25 ++++++++++------- .../app/templates/bitcoin/bitcoin.conf | 20 ++++++++++++++ .../templates/lightning/c-lightning/config | 4 +++ .../app/templates/lightning/lnd/lnd.conf | 27 +++++++++++++++++++ 9 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 install/generator-cyphernode/generators/app/templates/bitcoin/bitcoin.conf create mode 100644 install/generator-cyphernode/generators/app/templates/lightning/c-lightning/config create mode 100644 install/generator-cyphernode/generators/app/templates/lightning/lnd/lnd.conf diff --git a/install/generator-cyphernode/generators/app/features/000_cyphernode.js b/install/generator-cyphernode/generators/app/features/000_cyphernode.js index 301a9a4..d861437 100644 --- a/install/generator-cyphernode/generators/app/features/000_cyphernode.js +++ b/install/generator-cyphernode/generators/app/features/000_cyphernode.js @@ -36,5 +36,8 @@ module.exports = { }, env: function( props ) { return 'VAR0=VALUE0\nVAR1=VALUE1' + }, + templates: function( props ) { + return []; } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/features/100_bitcoin.js b/install/generator-cyphernode/generators/app/features/100_bitcoin.js index b9cb878..71ff5b4 100644 --- a/install/generator-cyphernode/generators/app/features/100_bitcoin.js +++ b/install/generator-cyphernode/generators/app/features/100_bitcoin.js @@ -67,5 +67,8 @@ module.exports = { }, env: function( props ) { return 'VAR0=VALUE0\nVAR1=VALUE1' + }, + templates: function( props ) { + return ['bitcoin.conf'] } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/features/200_lightning.js b/install/generator-cyphernode/generators/app/features/200_lightning.js index 580ca17..768fddf 100644 --- a/install/generator-cyphernode/generators/app/features/200_lightning.js +++ b/install/generator-cyphernode/generators/app/features/200_lightning.js @@ -1,8 +1,15 @@ +const path = require('path'); + const name = 'lightning'; const featureCondition = function(props) { return props.features && props.features.indexOf( name ) != -1; } +const templates = { + 'lnd': [ path.join('lnd','lnd.conf') ], + 'c-lightning': [ path.join('c-lightning','config') ] +} + module.exports = { name: function() { return name; @@ -36,5 +43,8 @@ module.exports = { }, env: function( props ) { return 'VAR0=VALUE0\nVAR1=VALUE1' + }, + templates: function( props ) { + return templates[props.lightning_implementation] } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/features/300_electrum.js b/install/generator-cyphernode/generators/app/features/300_electrum.js index 137e3df..e0b7deb 100644 --- a/install/generator-cyphernode/generators/app/features/300_electrum.js +++ b/install/generator-cyphernode/generators/app/features/300_electrum.js @@ -28,5 +28,8 @@ module.exports = { }, env: function( props ) { return 'VAR0=VALUE0\nVAR1=VALUE1' + }, + templates: function( props ) { + return []; } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/features/400_opentimestamps.js b/install/generator-cyphernode/generators/app/features/400_opentimestamps.js index 789f319..fba60f2 100644 --- a/install/generator-cyphernode/generators/app/features/400_opentimestamps.js +++ b/install/generator-cyphernode/generators/app/features/400_opentimestamps.js @@ -13,5 +13,8 @@ module.exports = { }, env: function( props ) { return 'VAR0=VALUE0\nVAR1=VALUE1'; + }, + templates: function( props ) { + return []; } }; \ No newline at end of file diff --git a/install/generator-cyphernode/generators/app/index.js b/install/generator-cyphernode/generators/app/index.js index 19445f5..3582907 100644 --- a/install/generator-cyphernode/generators/app/index.js +++ b/install/generator-cyphernode/generators/app/index.js @@ -19,8 +19,8 @@ module.exports = class extends Generator { constructor(args, opts) { super(args, opts); - if( fs.existsSync('/data/props.json') ) { - this.props = require('/data/props.json'); + if( fs.existsSync(this.destinationPath('props.json')) ) { + this.props = require(this.destinationPath('props.json')); } else { this.props = {}; } @@ -48,17 +48,22 @@ module.exports = class extends Generator { } writing() { - fs.writeFileSync('/data/props.json', JSON.stringify(this.props, null, 2)); + fs.writeFileSync(this.destinationPath('props.json'), JSON.stringify(this.props, null, 2)); for( let m of featurePromptModules ) { - fs.writeFileSync('/data/'+m.name(), m.env()); + const name = m.name(); + fs.writeFileSync(this.destinationPath(name+'.properties'), m.env()); + + for( let t of m.templates(this.props) ) { + const p = path.join(name,t); + this.fs.copyTpl( + this.templatePath(p), + this.destinationPath(p), + this.props + ); + } + } - /* - this.fs.copy( - this.templatePath('dummyfile.txt'), - this.destinationPath('dummyfile.txt') - ); - */ } install() { diff --git a/install/generator-cyphernode/generators/app/templates/bitcoin/bitcoin.conf b/install/generator-cyphernode/generators/app/templates/bitcoin/bitcoin.conf new file mode 100644 index 0000000..44c6232 --- /dev/null +++ b/install/generator-cyphernode/generators/app/templates/bitcoin/bitcoin.conf @@ -0,0 +1,20 @@ +<% if (cyphernode_net === 'testnet') { %> +# testnet +testnet=1 +<% } %> + +<% if (lightning_implementation === 'lnd') { %> +#lnd opts +txindex=1 +zmqpubrawblock=tcp://0.0.0.0:18501 +zmqpubrawtx=tcp://0.0.0.0:18502 +<% } %> + +#tor +#proxy=127.0.0.1:9050 +#listen=1 + +rpcconnect=btcnode +rpcuser=<%= bitcoin_rpcuser %> +rpcpassword=<%= bitcoin_rpcpassword %> +rpcwallet=ln01.dat diff --git a/install/generator-cyphernode/generators/app/templates/lightning/c-lightning/config b/install/generator-cyphernode/generators/app/templates/lightning/c-lightning/config new file mode 100644 index 0000000..77c25c0 --- /dev/null +++ b/install/generator-cyphernode/generators/app/templates/lightning/c-lightning/config @@ -0,0 +1,4 @@ +alias=SatoshiPortal01 +rgb=008000 +#port=9735 +network=testnet diff --git a/install/generator-cyphernode/generators/app/templates/lightning/lnd/lnd.conf b/install/generator-cyphernode/generators/app/templates/lightning/lnd/lnd.conf new file mode 100644 index 0000000..071ea40 --- /dev/null +++ b/install/generator-cyphernode/generators/app/templates/lightning/lnd/lnd.conf @@ -0,0 +1,27 @@ +[Application Options] +debuglevel=info +maxpendingchannels=10 +externalip=88.198.55.131 +color=#a111ff +alias=SatoshiPortal01 +rpclisten=0.0.0.0:10009 +tlsextraip=lnd +tlsextradomain=lnd + +[Bitcoin] +bitcoin.active=1 +bitcoin.node=bitcoind +bitcoin.mainnet=1 + +[Bitcoind] +bitcoind.rpcuser=<%= bitcoin_rpcuser %> +bitcoind.rpcpass=<%= bitcoin_rpcpassword %> +bitcoind.zmqpubrawblock=tcp://bitcoin:18501 +bitcoind.zmqpubrawtx=tcp://bitcoin:18502 +#bitcoind.zmqpath=tcp://bitcoin:18501 +bitcoind.rpchost=bitcoin + +[autopilot] +autopilot.active=1 +autopilot.maxchannels=5 +autopilot.allocation=0.6 \ No newline at end of file