From 7bf2aeebf7b05ac3197415c46fce0a04c361b6b9 Mon Sep 17 00:00:00 2001 From: Constantin Date: Mon, 6 Aug 2018 15:53:14 +0200 Subject: [PATCH] add switchNet --- home.admin/00mainMenu.sh | 6 ++++- home.admin/95switchNetEnv.sh | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100755 home.admin/95switchNetEnv.sh diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index f395baa..8f15732 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -66,7 +66,8 @@ else CONNECT "Connect to a Peer" \ lnbalance "Detailed Wallet Balances" \ lnchannels "Lightning Channel List" \ - RECKLES "Console / Terminal") + RECKLES "Console / Terminal"\ + REKT "Go Reckless! Switch Testnet/Mainnet") fi @@ -132,6 +133,9 @@ case $CHOICE in RECKLES) lncli -h echo "SUCH WOW come back with ./00mainMenu.sh" + ;; + REKT) # switch configs + sudo ./95switchNetEnv.sh; ;; X) # unlock ./AAunlockLND.sh diff --git a/home.admin/95switchNetEnv.sh b/home.admin/95switchNetEnv.sh new file mode 100755 index 0000000..bf85e6a --- /dev/null +++ b/home.admin/95switchNetEnv.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +BITCOIN_CONFIG="/home/bitcoin/.bitcoin/bitcoin.conf" +LND_CONFIG="/home/bitcoin/.lnd/lnd.conf" +# function to detect main/testnet + +function isMainnet(){ + grep "^#testnet=1$" -q $BITCOIN_CONFIG && return 1 + return 0 +} + +function switchToMainnet { + echo "switching to mainnet" + sed -i 's/^testnet=1/#testnet=1/g' $BITCOIN_CONFIG && \ + sed -i 's/^bitcoin.testnet=1/#bitcoin.testnet=1/g' $LND_CONFIG && \ + sed -i 's/^#bitcoin.mainnet=1/bitcoin.mainnet=1/g' $LND_CONFIG + echo "switched to mainnet" +} + +function switchToTestnet { + echo "switching to testnet" + sed -i 's/^#testnet=1/testnet=1/g' $BITCOIN_CONFIG && \ + sed -i 's/^#bitcoin.testnet=1/bitcoin.testnet=1/g' $LND_CONFIG && \ + sed -i 's/^bitcoin.mainnet=1/#bitcoin.mainnet=1/g' $LND_CONFIG + echo "switched to testnet" +} + +# change to test: check both configs for commented out testnet arguments and mainnet +echo "stopping lnd client" +systemctl stop lnd +sleep 4 +echo "stopping bitcoind client" +systemctl stop bitcoind +sleep 4 +isMainnet +if [ $? -eq 1 ]; then + echo "switching from mainnet to testnet" + switchToTestnet +else + echo "switching from testnet to mainnet" + switchToMainnet +fi +echo "copying over config to bitcoin user" +cp $BITCOIN_CONFIG /home/admin/.bitcoin/ +systemctl start bitcoind +echo "started bitcoind back up, giving it a minute to come up" +sleep 60 +systemctl start lnd +echo "started lnd back up, giving it a minute, you will have to unlock your wallet" +sleep 60 +echo "finished config switch - started back up" +echo "you will still have to unlock your LND wallet" +./00mainMenu.sh \ No newline at end of file