rootzoll
6 years ago
6 changed files with 208 additions and 16 deletions
@ -0,0 +1,116 @@ |
|||||
|
#!/usr/bin/env bash |
||||
|
# based on pull request from vnnkl |
||||
|
|
||||
|
# load network |
||||
|
network=`cat .network` |
||||
|
|
||||
|
echo "" |
||||
|
echo "*** Switch between Testnet/Mainnet ***" |
||||
|
|
||||
|
# allow only on bitcoin network |
||||
|
if [ "${network}" = "bitcoin" ]; then |
||||
|
echo "Bitcoin network can be switched between testnet/mainnet ..." |
||||
|
else |
||||
|
echo "FAIL - Only Bitcoin Network can be switched between man/tast at the moment." |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
NETWORK_CONFIG="/home/bitcoin/.${network}/${network}.conf" |
||||
|
NETWORK_TEMPLATE="/home/admin/assets/${network}.conf" |
||||
|
LND_CONFIG="/home/bitcoin/.lnd/lnd.conf" |
||||
|
LND_TEMPLATE="/home/admin/assets/lnd.${network}.conf" |
||||
|
echo "NETWORK_CONFIG(${NETWORK_CONFIG})" |
||||
|
echo "LND_CONFIG(${LND_CONFIG})" |
||||
|
echo "NETWORK_TEMPLATE(${NETWORK_TEMPLATE})" |
||||
|
echo "LND_TEMPLATE(${LND_TEMPLATE})" |
||||
|
|
||||
|
# function to detect main/testnet |
||||
|
function isMainnet(){ |
||||
|
grep "^#testnet=1$" -q $NETWORK_CONFIG && return 1 |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
function switchToMainnet { |
||||
|
echo "switching to mainnet" |
||||
|
sed -i 's/^testnet=1/#testnet=1/g' $NETWORK_CONFIG |
||||
|
sed -i 's/^testnet=1/#testnet=1/g' $NETWORK_TEMPLATE |
||||
|
sed -i 's/^${network}.testnet=1/#${network}.testnet=1/g' $LND_CONFIG |
||||
|
sed -i 's/^#${network}.mainnet=1/${network}.mainnet=1/g' $LND_CONFIG |
||||
|
sed -i 's/^${network}.testnet=1/#${network}.testnet=1/g' $LND_TEMPLATE |
||||
|
sed -i 's/^#${network}.mainnet=1/${network}.mainnet=1/g' $LND_TEMPLATE |
||||
|
echo "OK switched to mainnet" |
||||
|
} |
||||
|
|
||||
|
function switchToTestnet { |
||||
|
echo "switching to testnet" |
||||
|
sed -i 's/^#testnet=1/testnet=1/g' $NETWORK_CONFIG |
||||
|
sed -i 's/^#testnet=1/testnet=1/g' $NETWORK_TEMPLATE |
||||
|
sed -i 's/^#${network}.testnet=1/${network}.testnet=1/g' $LND_CONFIG |
||||
|
sed -i 's/^${network}.mainnet=1/#${network}.mainnet=1/g' $LND_CONFIG |
||||
|
sed -i 's/^#${network}.testnet=1/${network}.testnet=1/g' $LND_TEMPLATE |
||||
|
sed -i 's/^${network}.mainnet=1/#${network}.mainnet=1/g' $LND_TEMPLATE |
||||
|
echo "OK switched to testnet" |
||||
|
} |
||||
|
|
||||
|
# LND Service |
||||
|
lndInstalled=$(systemctl status lnd.service | grep loaded -c) |
||||
|
if [ ${lndInstalled} -gt 0 ]; then |
||||
|
|
||||
|
echo "check for open channels" |
||||
|
openChannels=$(lncli listchannels 2>/dev/null | grep chan_id -c) |
||||
|
if [ ${openChannels} -gt 0 ]; then |
||||
|
echo "FAIL - You have still open channels and could loose funds !! - close those first with lncli closeallchannels" |
||||
|
exit 1 |
||||
|
else |
||||
|
echo "no open channels found" |
||||
|
fi |
||||
|
|
||||
|
echo "stopping lnd client" |
||||
|
systemctl stop lnd |
||||
|
sleep 4 |
||||
|
|
||||
|
else |
||||
|
echo "LND not running" |
||||
|
fi |
||||
|
|
||||
|
# NETWORK Service |
||||
|
networkInstalled=$(systemctl status ${network}d.service | grep loaded -c) |
||||
|
if [ ${networkInstalled} -gt 0 ]; then |
||||
|
echo "stopping bitcoind client" |
||||
|
systemctl stop bitcoind |
||||
|
sleep 4 |
||||
|
else |
||||
|
echo "Network ${network} not running" |
||||
|
fi |
||||
|
|
||||
|
# TURN THE SWITCH |
||||
|
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 $NETWORK_CONFIG /home/admin/.${network}/ |
||||
|
|
||||
|
# restarting network |
||||
|
if [ ${networkInstalled} -gt 0 ]; then |
||||
|
|
||||
|
# start network |
||||
|
systemctl start bitcoind |
||||
|
echo "started ${network}d back up, giving it a 120 SECONDS to prepare" |
||||
|
sleep 120 |
||||
|
|
||||
|
# set setup info again |
||||
|
echo "60" > /home/admin/.setup |
||||
|
|
||||
|
# run again the complete LND init procedure |
||||
|
./70initLND.sh |
||||
|
|
||||
|
else |
||||
|
echo "No starting of network, because it was not running before" |
||||
|
fi |
@ -0,0 +1,53 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
# load network and chain info |
||||
|
network=`cat .network` |
||||
|
chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') |
||||
|
|
||||
|
command="lncli closeallchannels -f" |
||||
|
|
||||
|
clear |
||||
|
echo "***********************************" |
||||
|
echo "Closing All Channels (EXPERIMENTAL)" |
||||
|
echo "***********************************" |
||||
|
echo "" |
||||
|
echo "COMMAND LINE: " |
||||
|
echo $command |
||||
|
echo "" |
||||
|
echo "RESULT:" |
||||
|
|
||||
|
# PRECHECK) check if chain is in sync |
||||
|
chainInSync=$(lncli getinfo | grep '"synced_to_chain": true' -c) |
||||
|
if [ ${chainInSync} -eq 0 ]; then |
||||
|
command="" |
||||
|
result="FAIL PRECHECK - lncli getinfo shows 'synced_to_chain': false - wait until chain is sync " |
||||
|
fi |
||||
|
|
||||
|
# TODO PRECHECK) are any channels open at all |
||||
|
|
||||
|
# TODO PRECHECK) are there INACTIVE channels that would need a force close (and manual YES) |
||||
|
# remember that for info below |
||||
|
|
||||
|
# execute command |
||||
|
if [ ${#command} -gt 0 ]; then |
||||
|
result=$($command) |
||||
|
fi |
||||
|
|
||||
|
# on no result TODO: check if there is any result at all |
||||
|
if [ ${#result} -eq 0 ]; then |
||||
|
echo "Sorry something went wrong - thats unusual." |
||||
|
echo "" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
# when result is available |
||||
|
echo "$result" |
||||
|
|
||||
|
# TODO parse out closing transactions and monitor those with blockchain for confirmations |
||||
|
|
||||
|
# TODO give final info - let user know if its now safe to update RaspiBlitz or change test/main |
||||
|
# ask to make sure user has list for seed words still safe |
||||
|
echo "" |
||||
|
echo "******************************" |
||||
|
echo "INFO" |
||||
|
echo "******************************" |
Loading…
Reference in new issue