From 5d24b427caec898fd0f5cabad0397526c56acced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 2 Mar 2022 21:40:19 +0000 Subject: [PATCH 1/5] fix: handle grep error output --- lib/blockchain/bitcoin.js | 14 ++++++++++++++ lib/blockchain/dash.js | 10 +++++----- lib/blockchain/litecoin.js | 7 +++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/blockchain/bitcoin.js b/lib/blockchain/bitcoin.js index a1bfb22b..2f26ad21 100644 --- a/lib/blockchain/bitcoin.js +++ b/lib/blockchain/bitcoin.js @@ -27,6 +27,20 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/bitcoin.tar.gz`) + if (common.es(`ps -ef | grep -q "changetype=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { + common.logger.info(`changetype already defined, skipping...`) + } else { + common.logger.info(`Enabling bech32 change addresses in config file..`) + common.es(`echo -e "\nchangetype=bech32" >> /mnt/blockchains/bitcoin/bitcoin.conf`) + } + + if (common.es(`ps -ef | grep -q "listenonion=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { + common.logger.info(`listenonion already defined, skipping...`) + } else { + common.logger.info(`Setting 'listenonion=0' in config file...`) + common.es(`echo -e "\nlistenonion=0" >> /mnt/blockchains/bitcoin/bitcoin.conf`) + } + if (isCurrentlyRunning) { common.logger.info('Starting wallet...') common.es(`sudo supervisorctl start bitcoin`) diff --git a/lib/blockchain/dash.js b/lib/blockchain/dash.js index e688326f..5ea965cd 100644 --- a/lib/blockchain/dash.js +++ b/lib/blockchain/dash.js @@ -27,27 +27,27 @@ function updateCore (coinRec, isCurrentlyRunning) { 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`)) { + if (common.es(`ps -ef | grep -q "enableprivatesend=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { 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`)) { + } else if (common.es(`ps -ef | grep -q "enablecoinjoin=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { 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`)) { + if (common.es(`ps -ef | grep -q "privatesendautostart=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { 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`)) { + } else if (common.es(`ps -ef | grep -q "coinjoinautostart=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { 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`)) { + if (common.es(`ps -ef | grep -q "litemode=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { common.logger.info(`Switching from 'LiteMode' to 'DisableGovernance'...`) common.es(`sed -i 's/litemode/disablegovernance/g' /mnt/blockchains/dash/dash.conf`) } else { diff --git a/lib/blockchain/litecoin.js b/lib/blockchain/litecoin.js index 41b09967..a07c4db3 100644 --- a/lib/blockchain/litecoin.js +++ b/lib/blockchain/litecoin.js @@ -27,6 +27,13 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/litecoin.tar.gz`) + if (common.es(`ps -ef | grep -q "changetype=" /mnt/blockchains/litecoin/litecoin.conf | { grep -v grep || true; }`)) { + common.logger.info(`changetype already defined, skipping...`) + } else { + common.logger.info(`Enabling bech32 change addresses in config file..`) + common.es(`echo -e "\nchangetype=bech32" >> /mnt/blockchains/litecoin/litecoin.conf`) + } + if (isCurrentlyRunning) { common.logger.info('Starting wallet...') common.es(`sudo supervisorctl start litecoin`) From ae151c741e4d1ba4c816eba82d49761235d6d675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Thu, 3 Mar 2022 00:12:12 +0000 Subject: [PATCH 2/5] fix: remove quite mode from grep --- lib/blockchain/bitcoin.js | 8 ++++---- lib/blockchain/dash.js | 14 +++++++------- lib/blockchain/litecoin.js | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/blockchain/bitcoin.js b/lib/blockchain/bitcoin.js index 2f26ad21..19bd2b6a 100644 --- a/lib/blockchain/bitcoin.js +++ b/lib/blockchain/bitcoin.js @@ -27,18 +27,18 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/bitcoin.tar.gz`) - if (common.es(`ps -ef | grep -q "changetype=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { + if (common.es(`ps -ef | grep "changetype=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { common.logger.info(`changetype already defined, skipping...`) } else { common.logger.info(`Enabling bech32 change addresses in config file..`) - common.es(`echo -e "\nchangetype=bech32" >> /mnt/blockchains/bitcoin/bitcoin.conf`) + common.es(`echo "\nchangetype=bech32" >> /mnt/blockchains/bitcoin/bitcoin.conf`) } - if (common.es(`ps -ef | grep -q "listenonion=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { + if (common.es(`ps -ef | grep "listenonion=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { common.logger.info(`listenonion already defined, skipping...`) } else { common.logger.info(`Setting 'listenonion=0' in config file...`) - common.es(`echo -e "\nlistenonion=0" >> /mnt/blockchains/bitcoin/bitcoin.conf`) + common.es(`echo "\nlistenonion=0" >> /mnt/blockchains/bitcoin/bitcoin.conf`) } if (isCurrentlyRunning) { diff --git a/lib/blockchain/dash.js b/lib/blockchain/dash.js index 5ea965cd..c44b1a8a 100644 --- a/lib/blockchain/dash.js +++ b/lib/blockchain/dash.js @@ -27,27 +27,27 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/dash.tar.gz`) - if (common.es(`ps -ef | grep -q "enableprivatesend=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + if (common.es(`ps -ef | grep "enableprivatesend=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { 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(`ps -ef | grep -q "enablecoinjoin=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + } else if (common.es(`ps -ef | grep "enablecoinjoin=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { 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`) + common.es(`echo "enablecoinjoin=1" >> /mnt/blockchains/dash/dash.conf`) } - if (common.es(`ps -ef | grep -q "privatesendautostart=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + if (common.es(`ps -ef | grep "privatesendautostart=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { 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(`ps -ef | grep -q "coinjoinautostart=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + } else if (common.es(`ps -ef | grep "coinjoinautostart=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { 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`) + common.es(`echo "coinjoinautostart=1" >> /mnt/blockchains/dash/dash.conf`) } - if (common.es(`ps -ef | grep -q "litemode=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + if (common.es(`ps -ef | grep "litemode=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { common.logger.info(`Switching from 'LiteMode' to 'DisableGovernance'...`) common.es(`sed -i 's/litemode/disablegovernance/g' /mnt/blockchains/dash/dash.conf`) } else { diff --git a/lib/blockchain/litecoin.js b/lib/blockchain/litecoin.js index a07c4db3..d3d196bf 100644 --- a/lib/blockchain/litecoin.js +++ b/lib/blockchain/litecoin.js @@ -27,11 +27,11 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/litecoin.tar.gz`) - if (common.es(`ps -ef | grep -q "changetype=" /mnt/blockchains/litecoin/litecoin.conf | { grep -v grep || true; }`)) { + if (common.es(`ps -ef | grep "changetype=" /mnt/blockchains/litecoin/litecoin.conf | { grep -v grep || true; }`)) { common.logger.info(`changetype already defined, skipping...`) } else { common.logger.info(`Enabling bech32 change addresses in config file..`) - common.es(`echo -e "\nchangetype=bech32" >> /mnt/blockchains/litecoin/litecoin.conf`) + common.es(`echo "\nchangetype=bech32" >> /mnt/blockchains/litecoin/litecoin.conf`) } if (isCurrentlyRunning) { From 6bb287ca38a3c82fae803f386858605b83724422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Thu, 3 Mar 2022 00:33:59 +0000 Subject: [PATCH 3/5] fix: remove unnecessary new line --- lib/blockchain/bitcoin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/blockchain/bitcoin.js b/lib/blockchain/bitcoin.js index 19bd2b6a..3273b9c8 100644 --- a/lib/blockchain/bitcoin.js +++ b/lib/blockchain/bitcoin.js @@ -31,14 +31,14 @@ function updateCore (coinRec, isCurrentlyRunning) { common.logger.info(`changetype already defined, skipping...`) } else { common.logger.info(`Enabling bech32 change addresses in config file..`) - common.es(`echo "\nchangetype=bech32" >> /mnt/blockchains/bitcoin/bitcoin.conf`) + common.es(`echo "changetype=bech32" >> /mnt/blockchains/bitcoin/bitcoin.conf`) } if (common.es(`ps -ef | grep "listenonion=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { common.logger.info(`listenonion already defined, skipping...`) } else { common.logger.info(`Setting 'listenonion=0' in config file...`) - common.es(`echo "\nlistenonion=0" >> /mnt/blockchains/bitcoin/bitcoin.conf`) + common.es(`echo "listenonion=0" >> /mnt/blockchains/bitcoin/bitcoin.conf`) } if (isCurrentlyRunning) { From 040d8d5bab4826da54df05a7ae060d6c941658b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Fri, 4 Mar 2022 17:14:57 +0000 Subject: [PATCH 4/5] refactor: simplify confusing chain of commands --- lib/blockchain/bitcoin.js | 4 ++-- lib/blockchain/dash.js | 10 +++++----- lib/blockchain/litecoin.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/blockchain/bitcoin.js b/lib/blockchain/bitcoin.js index 3273b9c8..f436ae93 100644 --- a/lib/blockchain/bitcoin.js +++ b/lib/blockchain/bitcoin.js @@ -27,14 +27,14 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/bitcoin.tar.gz`) - if (common.es(`ps -ef | grep "changetype=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { + if (common.es(`grep "changetype=" /mnt/blockchains/bitcoin/bitcoin.conf || true`)) { common.logger.info(`changetype already defined, skipping...`) } else { common.logger.info(`Enabling bech32 change addresses in config file..`) common.es(`echo "changetype=bech32" >> /mnt/blockchains/bitcoin/bitcoin.conf`) } - if (common.es(`ps -ef | grep "listenonion=" /mnt/blockchains/bitcoin/bitcoin.conf | { grep -v grep || true; }`)) { + if (common.es(`grep "listenonion=" /mnt/blockchains/bitcoin/bitcoin.conf || true`)) { common.logger.info(`listenonion already defined, skipping...`) } else { common.logger.info(`Setting 'listenonion=0' in config file...`) diff --git a/lib/blockchain/dash.js b/lib/blockchain/dash.js index c44b1a8a..cb0c8aa2 100644 --- a/lib/blockchain/dash.js +++ b/lib/blockchain/dash.js @@ -27,27 +27,27 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/dash.tar.gz`) - if (common.es(`ps -ef | grep "enableprivatesend=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + if (common.es(`grep "enableprivatesend=" /mnt/blockchains/dash/dash.conf || true`)) { 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(`ps -ef | grep "enablecoinjoin=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + } else if (common.es(`grep "enablecoinjoin=" /mnt/blockchains/dash/dash.conf || true`)) { common.logger.info(`enablecoinjoin already defined, skipping...`) } else { common.logger.info(`Enabling CoinJoin in config file...`) common.es(`echo "enablecoinjoin=1" >> /mnt/blockchains/dash/dash.conf`) } - if (common.es(`ps -ef | grep "privatesendautostart=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + if (common.es(`grep "privatesendautostart=" /mnt/blockchains/dash/dash.conf || true`)) { 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(`ps -ef | grep "coinjoinautostart=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + } else if (common.es(`grep "coinjoinautostart=" /mnt/blockchains/dash/dash.conf || true`)) { common.logger.info(`coinjoinautostart already defined, skipping...`) } else { common.logger.info(`Enabling CoinJoin AutoStart in config file...`) common.es(`echo "coinjoinautostart=1" >> /mnt/blockchains/dash/dash.conf`) } - if (common.es(`ps -ef | grep "litemode=" /mnt/blockchains/dash/dash.conf | { grep -v grep || true; }`)) { + if (common.es(`grep "litemode=" /mnt/blockchains/dash/dash.conf || true`)) { common.logger.info(`Switching from 'LiteMode' to 'DisableGovernance'...`) common.es(`sed -i 's/litemode/disablegovernance/g' /mnt/blockchains/dash/dash.conf`) } else { diff --git a/lib/blockchain/litecoin.js b/lib/blockchain/litecoin.js index d3d196bf..915d512f 100644 --- a/lib/blockchain/litecoin.js +++ b/lib/blockchain/litecoin.js @@ -27,7 +27,7 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/litecoin.tar.gz`) - if (common.es(`ps -ef | grep "changetype=" /mnt/blockchains/litecoin/litecoin.conf | { grep -v grep || true; }`)) { + if (common.es(`grep "changetype=" /mnt/blockchains/litecoin/litecoin.conf || true`)) { common.logger.info(`changetype already defined, skipping...`) } else { common.logger.info(`Enabling bech32 change addresses in config file..`) From 426c8c70f219221d6ecc76ec195eb10fcbc7f099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Fri, 4 Mar 2022 17:27:24 +0000 Subject: [PATCH 5/5] fix: remove unnecessary new line --- lib/blockchain/litecoin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blockchain/litecoin.js b/lib/blockchain/litecoin.js index 915d512f..7484af8a 100644 --- a/lib/blockchain/litecoin.js +++ b/lib/blockchain/litecoin.js @@ -31,7 +31,7 @@ function updateCore (coinRec, isCurrentlyRunning) { common.logger.info(`changetype already defined, skipping...`) } else { common.logger.info(`Enabling bech32 change addresses in config file..`) - common.es(`echo "\nchangetype=bech32" >> /mnt/blockchains/litecoin/litecoin.conf`) + common.es(`echo "changetype=bech32" >> /mnt/blockchains/litecoin/litecoin.conf`) } if (isCurrentlyRunning) {