23 changed files with 190 additions and 323 deletions
@ -1,125 +0,0 @@ |
|||
#!/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/^#mainnet=1/mainnet=1/g" $NETWORK_CONFIG |
|||
sed -i "s/^#mainnet=1/mainnet=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/^mainnet=1/#mainnet=1/g" $NETWORK_CONFIG |
|||
sed -i "s/^mainnet=1/#mainnet=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=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} listchannels 2>/dev/null | grep chan_id -c) |
|||
if [ ${openChannels} -gt 0 ]; then |
|||
echo "" |
|||
echo "!!!!!!!!!!!!!!!!!!!" |
|||
echo "FAIL - You have still open channels and could loose funds !! - close those first with 'lncli closeallchannels' or main menu option." |
|||
echo "!!!!!!!!!!!!!!!!!!!" |
|||
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 admin user" |
|||
cp $NETWORK_CONFIG /home/admin/.${network}/ |
|||
chown admin:admin /home/admin/.${network}/${network}.conf |
|||
cp $LND_CONFIG /home/admin/.lnd/ |
|||
chown admin:admin /home/admin/.lnd/lnd.conf |
|||
|
|||
# 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 |
|||
sudo sed -i "s/^setupStep=.*/setupStep=60/g" /home/admin/raspiblitz.info |
|||
|
|||
# run again the complete LND init procedure |
|||
./70initLND.sh |
|||
|
|||
else |
|||
echo "No starting of network, because it was not running before" |
|||
fi |
@ -1,17 +1,96 @@ |
|||
#!/bin/bash |
|||
|
|||
# LOAD DATA & PRECHECK |
|||
|
|||
# path to old or init configuration of RaspiBlitz |
|||
configFile="/mnt/hdd/raspiblitz.conf" |
|||
|
|||
# check if there is a config file |
|||
configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf') |
|||
if [ ${configExists} -eq 0 ]; then |
|||
echo "FAIL: no config file (${configFile}) found to init or upgrade!" |
|||
exit 1 |
|||
fi |
|||
|
|||
# load old or init raspiblitz config |
|||
source ${configFile} |
|||
|
|||
# check if config files contains basic: network |
|||
if [ ${#network} -eq 0 ]; then |
|||
echo "FAIL: missing network in (${configFile})!" |
|||
exit 1 |
|||
fi |
|||
|
|||
# check if config files contains basic: chain |
|||
if [ ${#chain} -eq 0 ]; then |
|||
echo "FAIL: missing chain in (${configFile})!" |
|||
exit 1 |
|||
fi |
|||
|
|||
# check if config files contains basic: hostname |
|||
if [ ${#hostname} -eq 0 ]; then |
|||
echo "FAIL: missing hostname in (${configFile})!" |
|||
exit 1 |
|||
fi |
|||
|
|||
# load codeVersion |
|||
source ./_version.info |
|||
source /home/admin/_version.info |
|||
|
|||
# check if code version was loaded |
|||
if [ ${#codeVersion} -eq 0 ]; then |
|||
echo "FAIL: no code version (/home/admin/_version.info) found!" |
|||
exit 1 |
|||
fi |
|||
|
|||
# load raspiblitz config |
|||
source /mnt/hdd/raspiblitz.conf |
|||
# DEFAULT VALUES - MISSING data fields on init or upadte |
|||
|
|||
echo "" |
|||
echo "*****************************" |
|||
echo "Version Migration RaspiBlitz" |
|||
echo "Default Values" |
|||
echo "*****************************" |
|||
|
|||
# AUTOPILOT |
|||
# autoPilot=off|on |
|||
if [ ${#autoPilot} -eq 0 ]; then |
|||
echo "autoPilot=off" >> $configFile |
|||
fi |
|||
|
|||
# AUTO NAT DISCOVERY |
|||
# autoNatDiscovery=off|on |
|||
if [ ${#autoNatDiscovery} -eq 0 ]; then |
|||
echo "autoNatDiscovery=off" >> $configFile |
|||
fi |
|||
|
|||
# TOR |
|||
# runBehindTor=off|on |
|||
if [ ${#runBehindTor} -eq 0 ]; then |
|||
echo "runBehindTor=off" >> $configFile |
|||
fi |
|||
|
|||
# RideTheLightning RTL |
|||
# rtlWebinterface=off|on |
|||
if [ ${#rtlWebinterface} -eq 0 ]; then |
|||
echo "rtlWebinterface=off" >> $configFile |
|||
fi |
|||
|
|||
# MIGRATION - DATA CONVERSION when updating config |
|||
# this is the place if on a future version change |
|||
# a conversion of config data or app data is needed |
|||
|
|||
echo "" |
|||
echo "*****************************" |
|||
echo "Version Migration Steps" |
|||
echo "*****************************" |
|||
echo "Version Code: ${codeVersion}" |
|||
echo "Version Data: ${raspiBlitzVersion}" |
|||
|
|||
echo "TODO: Update Migration check ..." |
|||
if [ "${raspiBlitzVersion}" != "${codeVersion}" ]; then |
|||
echo "detected version change ... starting migration script" |
|||
echo "TODO: Update Migration check ... only needed after version 1.0" |
|||
else |
|||
echo "OK - version of config data is up to date" |
|||
fi |
|||
|
|||
echo "" |
|||
exit 0 |
|||
|
|||
|
Loading…
Reference in new issue