Merge pull request #839 from josepfo/feat/update-cores-upon-l-s-update

feat: add script to update nodes
This commit is contained in:
Rafael Taranto 2021-11-19 14:09:32 +00:00 committed by GitHub
commit 86e9204a28
8 changed files with 172 additions and 10 deletions

View file

@ -0,0 +1,36 @@
#!/usr/bin/env node
const _ = require('lodash/fp')
const common = require('../lib/blockchain/common')
const { utils: coinUtils } = require('lamassu-coins')
const cryptos = coinUtils.cryptoCurrencies()
const PLUGINS = {
BTC: require('../lib/blockchain/bitcoin.js'),
LTC: require('../lib/blockchain/litecoin.js'),
ETH: require('../lib/blockchain/ethereum.js'),
DASH: require('../lib/blockchain/dash.js'),
ZEC: require('../lib/blockchain/zcash.js'),
BCH: require('../lib/blockchain/bitcoincash.js')
}
function plugin (crypto) {
const plugin = PLUGINS[crypto.cryptoCode]
if (!plugin) throw new Error(`No such plugin: ${crypto.cryptoCode}`)
return plugin
}
function run () {
_.forEach((crypto) => {
if (!_.includes(crypto.cryptoCode, _.keys(PLUGINS))) return
const cryptoPlugin = plugin(crypto)
const status = common.es(`sudo supervisorctl status ${crypto.code} | awk '{ print $2 }'`).trim()
if (status === 'RUNNING') cryptoPlugin.updateCore(common.getBinaries(crypto.cryptoCode), true)
if (status === 'STOPPED') cryptoPlugin.updateCore(common.getBinaries(crypto.cryptoCode), false)
}, cryptos)
}
run()

View file

@ -16,9 +16,9 @@ function setup (dataDir) {
common.writeSupervisorConfig(coinRec, cmd)
}
function updateCore (coinRec) {
common.logger.info('Updating Bitcoin Core. This may take a minute.')
common.es(`sudo supervisorctl stop bitcoin`)
function updateCore (coinRec, isCurrentlyRunning) {
common.logger.info('Updating Bitcoin Core. This may take a minute...')
if (isCurrentlyRunning) common.es(`sudo supervisorctl stop bitcoin`)
common.es(`curl -#o /tmp/bitcoin.tar.gz ${coinRec.url}`)
common.es(`tar -xzf /tmp/bitcoin.tar.gz -C /tmp/`)
@ -27,8 +27,10 @@ function updateCore (coinRec) {
common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`)
common.es(`rm /tmp/bitcoin.tar.gz`)
common.logger.info('Starting wallet...')
common.es(`sudo supervisorctl start bitcoin`)
if (isCurrentlyRunning) {
common.logger.info('Starting wallet...')
common.es(`sudo supervisorctl start bitcoin`)
}
common.logger.info('Bitcoin Core is updated!')
}

View file

@ -4,7 +4,7 @@ const { utils: coinUtils } = require('lamassu-coins')
const common = require('./common')
module.exports = {setup}
module.exports = { setup, updateCore }
const coinRec = coinUtils.getCryptoCurrency('BCH')
@ -16,6 +16,26 @@ function setup (dataDir) {
common.writeSupervisorConfig(coinRec, cmd)
}
function updateCore (coinRec, isCurrentlyRunning) {
common.logger.info('Updating Bitcoin Cash. This may take a minute...')
if (isCurrentlyRunning) common.es(`sudo supervisorctl stop bitcoincash`)
common.es(`curl -#Lo /tmp/bitcoincash.tar.gz ${coinRec.url}`)
common.es(`tar -xzf /tmp/bitcoincash.tar.gz -C /tmp/`)
common.logger.info('Updating wallet...')
common.es(`cp /tmp/${coinRec.dir}/bitcoind /usr/local/bin/bitcoincashd`)
common.es(`cp /tmp/${coinRec.dir}/bitcoin-cli /usr/local/bin/bitcoincash-cli`)
common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`)
common.es(`rm /tmp/bitcoincash.tar.gz`)
if (isCurrentlyRunning) {
common.logger.info('Starting wallet...')
common.es(`sudo supervisorctl start bitcoincash`)
}
common.logger.info('Bitcoin Cash is updated!')
}
function buildConfig () {
return `rpcuser=lamassuserver
rpcpassword=${common.randomPass()}

View file

@ -4,7 +4,7 @@ const { utils: coinUtils } = require('lamassu-coins')
const common = require('./common')
module.exports = {setup}
module.exports = { setup, updateCore }
const coinRec = coinUtils.getCryptoCurrency('DASH')
@ -16,6 +16,52 @@ function setup (dataDir) {
common.writeSupervisorConfig(coinRec, cmd)
}
function updateCore (coinRec, isCurrentlyRunning) {
common.logger.info('Updating Dash Core. This may take a minute...')
if (isCurrentlyRunning) common.es(`sudo supervisorctl stop dash`)
common.es(`curl -#Lo /tmp/dash.tar.gz ${coinRec.url}`)
common.es(`tar -xzf /tmp/dash.tar.gz -C /tmp/`)
common.logger.info('Updating wallet...')
common.es(`cp /tmp/${coinRec.dir}/* /usr/local/bin/`)
common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`)
common.es(`rm /tmp/dash.tar.gz`)
if (common.es(`grep -x "enableprivatesend=." /mnt/blockchains/dash/dash.conf`)) {
common.logger.info(`Switching from 'PrivateSend' to 'CoinJoin'...`)
common.es(`sed -i 's/enableprivatesend/enablecoinjoin/g' /mnt/blockchains/dash/dash.conf`)
} else if (common.es(`grep -x "enablecoinjoin=." /mnt/blockchains/dash/dash.conf`)) {
common.logger.info(`enablecoinjoin already defined, skipping...`)
} else {
common.logger.info(`Enabling CoinJoin in config file...`)
common.es(`echo -e "enablecoinjoin=1" >> /mnt/blockchains/dash/dash.conf`)
}
if (common.es(`grep -x "privatesendautostart=." /mnt/blockchains/dash/dash.conf`)) {
common.logger.info(`Switching from 'PrivateSend' to 'CoinJoin'...`)
common.es(`sed -i 's/privatesendautostart/coinjoinautostart/g' /mnt/blockchains/dash/dash.conf`)
} else if (common.es(`grep -x "coinjoinautostart=." /mnt/blockchains/dash/dash.conf`)) {
common.logger.info(`coinjoinautostart already defined, skipping...`)
} else {
common.logger.info(`Enabling CoinJoin AutoStart in config file...`)
common.es(`echo -e "coinjoinautostart=1" >> /mnt/blockchains/dash/dash.conf`)
}
if (common.es(`grep -x "litemode=." /mnt/blockchains/dash/dash.conf`)) {
common.logger.info(`Switching from 'LiteMode' to 'DisableGovernance'...`)
common.es(`sed -i 's/litemode/disablegovernance/g' /mnt/blockchains/dash/dash.conf`)
} else {
common.es(`echo "disablegovernance already defined, skipping..."`)
}
if (isCurrentlyRunning) {
common.logger.info('Starting wallet...')
common.es(`sudo supervisorctl start dash`)
}
common.logger.info('Dash Core is updated!')
}
function buildConfig () {
return `rpcuser=lamassuserver
rpcpassword=${common.randomPass()}

View file

@ -2,7 +2,26 @@ const { utils: coinUtils } = require('lamassu-coins')
const common = require('./common')
module.exports = {setup}
module.exports = { setup, updateCore }
function updateCore (coinRec, isCurrentlyRunning) {
common.logger.info('Updating the Geth Ethereum wallet. This may take a minute...')
if (isCurrentlyRunning) common.es(`sudo supervisorctl stop ethereum`)
common.es(`curl -#o /tmp/ethereum.tar.gz ${coinRec.url}`)
common.es(`tar -xzf /tmp/ethereum.tar.gz -C /tmp/`)
common.logger.info('Updating wallet...')
common.es(`cp /tmp/${coinRec.dir}/geth /usr/local/bin/geth`)
common.es(`rm -r /tmp/${coinRec.dir}`)
common.es(`rm /tmp/ethereum.tar.gz`)
if (isCurrentlyRunning) {
common.logger.info('Starting wallet...')
common.es(`sudo supervisorctl start ethereum`)
}
common.logger.info('Geth is updated!')
}
function setup (dataDir) {
const coinRec = coinUtils.getCryptoCurrency('ETH')

View file

@ -4,7 +4,7 @@ const { utils: coinUtils } = require('lamassu-coins')
const common = require('./common')
module.exports = {setup}
module.exports = { setup, updateCore }
const coinRec = coinUtils.getCryptoCurrency('LTC')
@ -16,6 +16,25 @@ function setup (dataDir) {
common.writeSupervisorConfig(coinRec, cmd)
}
function updateCore (coinRec, isCurrentlyRunning) {
common.logger.info('Updating Litecoin Core. This may take a minute...')
if (isCurrentlyRunning) common.es(`sudo supervisorctl stop litecoin`)
common.es(`curl -#o /tmp/litecoin.tar.gz ${coinRec.url}`)
common.es(`tar -xzf /tmp/litecoin.tar.gz -C /tmp/`)
common.logger.info('Updating wallet...')
common.es(`cp /tmp/${coinRec.dir}/* /usr/local/bin/`)
common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`)
common.es(`rm /tmp/litecoin.tar.gz`)
if (isCurrentlyRunning) {
common.logger.info('Starting wallet...')
common.es(`sudo supervisorctl start litecoin`)
}
common.logger.info('Litecoin Core is updated!')
}
function buildConfig () {
return `rpcuser=lamassuserver
rpcpassword=${common.randomPass()}

View file

@ -4,11 +4,30 @@ const { utils: coinUtils } = require('lamassu-coins')
const common = require('./common')
module.exports = {setup}
module.exports = { setup, updateCore }
const es = common.es
const logger = common.logger
function updateCore (coinRec, isCurrentlyRunning) {
common.logger.info('Updating your Zcash wallet. This may take a minute...')
if (isCurrentlyRunning) common.es(`sudo supervisorctl stop zcash`)
common.es(`curl -#Lo /tmp/zcash.tar.gz ${coinRec.url}`)
common.es(`tar -xzf /tmp/zcash.tar.gz -C /tmp/`)
common.logger.info('Updating wallet...')
common.es(`cp /tmp/${coinRec.dir}/* /usr/local/bin/`)
common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`)
common.es(`rm /tmp/zcash.tar.gz`)
if (isCurrentlyRunning) {
common.logger.info('Starting wallet...')
common.es(`sudo supervisorctl start zcash`)
}
common.logger.info('Zcash is updated!')
}
function setup (dataDir) {
es('sudo apt-get update')
es('sudo apt-get install libgomp1 -y')

View file

@ -101,6 +101,7 @@
"lamassu-ofac-update": "./bin/lamassu-ofac-update",
"lamassu-send-coins": "./bin/lamassu-send-coins",
"lamassu-update-to-mnemonic": "./bin/lamassu-update-to-mnemonic",
"lamassu-update-wallet-nodes": "./bin/lamassu-update-wallet-nodes",
"lamassu-configure-frontcamera": "./bin/lamassu-configure-frontcamera",
"lamassu-ofac-update-sources": "./bin/lamassu-ofac-update-sources",
"lamassu-devices": "./bin/lamassu-devices",