raspiblitz/home.admin/config.scripts/network.chain.sh

89 lines
3.4 KiB
Bash
Raw Normal View History

2018-12-01 20:25:33 +01:00
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "small config script to change between testnet and mainnet"
echo "network.chain.sh [testnet|mainnet]"
exit 1
fi
# check input
if [ "$1" != "testnet" ] && [ "$1" != "mainnet" ]; then
echo "FAIL - unknnown value: $1"
exit 1
fi
# check and load raspiblitz config
# to know which network is running
source /mnt/hdd/raspiblitz.conf 2>/dev/null
if [ ${#network} -eq 0 ]; then
echo "FAIL - missing /mnt/hdd/raspiblitz.conf"
exit 1
2018-12-02 23:08:20 +01:00
fi
2018-12-01 20:25:33 +01:00
# testnet on litecoin cannot be set
if [ "${network}" = "litecoin" ] && [ "$1" = "testnet" ]; then
echo "FAIL - no lightning support for litecoin testnet"
exit 1
fi
2018-12-02 19:52:01 +01:00
# stop services
echo "making sure services are not running"
sudo systemctl stop lnd 2>/dev/null
sudo systemctl stop ${network}d 2>/dev/null
2018-12-01 20:25:33 +01:00
# editing network config files (hdd & admin user)
echo "edit ${network} config .."
2018-12-02 22:02:20 +01:00
# fix old lnd config file (that worked with switching comment)
sudo sed -i "s/^#testnet=.*/testnet=1/g" /mnt/hdd/${network}/${network}.conf
sudo sed -i "s/^#testnet=.*/testnet=1/g" /home/admin/.${network}/${network}.conf
# changes based on parameter
2018-12-01 20:25:33 +01:00
if [ "$1" = "testnet" ]; then
2018-12-02 22:02:20 +01:00
echo "editing /mnt/hdd/${network}/${network}.conf"
2018-12-01 20:25:33 +01:00
sudo sed -i "s/^testnet=.*/testnet=1/g" /mnt/hdd/${network}/${network}.conf
2018-12-02 22:02:20 +01:00
echo "editing /home/admin/.${network}/${network}.conf"
2018-12-01 20:25:33 +01:00
sudo sed -i "s/^testnet=.*/testnet=1/g" /home/admin/.${network}/${network}.conf
else
2018-12-02 20:43:48 +01:00
echo "editing /mnt/hdd/${network}/${network}.conf"
2018-12-01 20:25:33 +01:00
sudo sed -i "s/^testnet=.*/testnet=0/g" /mnt/hdd/${network}/${network}.conf
2018-12-02 20:43:48 +01:00
echo "editing /home/admin/.${network}/${network}.conf"
2018-12-01 20:25:33 +01:00
sudo sed -i "s/^testnet=.*/testnet=0/g" /home/admin/.${network}/${network}.conf
fi
# editing lnd config files (hdd & admin user)
echo "edit lightning config .."
2018-12-02 22:02:20 +01:00
# fix old lnd config file (that worked with switching comment)
sudo sed -i "s/^#bitcoin.testnet=.*/bitcoin.testnet=1/g" /mnt/hdd/lnd/lnd.conf
sudo sed -i "s/^#bitcoin.testnet=.*/bitcoin.testnet=1/g" /home/admin/.lnd/lnd.conf
# changes based on parameter
2018-12-01 20:25:33 +01:00
if [ "$1" = "testnet" ]; then
2018-12-02 20:43:48 +01:00
echo "editing /mnt/hdd/lnd/lnd.conf"
2018-12-01 20:25:33 +01:00
sudo sed -i "s/^${network}.mainnet.*/${network}.mainnet=0/g" /mnt/hdd/lnd/lnd.conf
sudo sed -i "s/^${network}.testnet.*/${network}.testnet=1/g" /mnt/hdd/lnd/lnd.conf
2018-12-02 20:43:48 +01:00
echo "editing /home/admin/.lnd/lnd.conf"
2018-12-01 20:25:33 +01:00
sudo sed -i "s/^${network}.mainnet.*/${network}.mainnet=0/g" /home/admin/.lnd/lnd.conf
sudo sed -i "s/^${network}.testnet.*/${network}.testnet=1/g" /home/admin/.lnd/lnd.conf
else
2018-12-02 20:43:48 +01:00
echo "editing /mnt/hdd/lnd/lnd.conf"
2018-12-01 20:25:33 +01:00
sudo sed -i "s/^${network}.mainnet.*/${network}.mainnet=1/g" /mnt/hdd/lnd/lnd.conf
sudo sed -i "s/^${network}.testnet.*/${network}.testnet=0/g" /mnt/hdd/lnd/lnd.conf
2018-12-02 20:43:48 +01:00
echo "editing /home/admin/.lnd/lnd.conf"
2018-12-01 20:25:33 +01:00
sudo sed -i "s/^${network}.mainnet.*/${network}.mainnet=1/g" /home/admin/.lnd/lnd.conf
sudo sed -i "s/^${network}.testnet.*/${network}.testnet=0/g" /home/admin/.lnd/lnd.conf
fi
# editing the raspi blitz config file
2018-12-02 20:43:48 +01:00
echo "editing /mnt/hdd/raspiblitz.conf"
2018-12-01 20:25:33 +01:00
if [ "$1" = "testnet" ]; then
sudo sed -i "s/^chain=.*/chain=test/g" /mnt/hdd/raspiblitz.conf
else
sudo sed -i "s/^chain=.*/chain=main/g" /mnt/hdd/raspiblitz.conf
fi
# now a reboot is needed to load all services fresh
# starting up process will display chain sync
# ask user todo reboot
echo "OK - all configs changed to: $1"
echo "needs reboot to activate new setting"