raspiblitz/home.admin/config.scripts/lnd.setname.sh

87 lines
2.3 KiB
Bash
Raw Normal View History

2019-01-14 12:46:19 +01:00
#!/bin/bash
# command info
2019-01-14 12:48:27 +01:00
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
2019-01-14 12:46:19 +01:00
echo "small config script to set a alias of LND (and hostname of raspi)"
echo "lnd.setname.sh [?newName] [?forceHostname]"
2019-01-14 12:46:19 +01:00
exit 1
fi
# 1. parameter [?newName]
newName=$1
# run interactive if 'turn on' && no further parameters
if [ ${#newName} -eq 0 ]; then
sudo rm ./.tmp
2019-01-14 13:45:24 +01:00
dialog --backtitle "Set LND Name/Alias" --inputbox "ENTER the new Name/Alias for LND node:
(free to choose, one word, use basic characters)
2019-01-14 12:50:01 +01:00
" 8 52 2>./.tmp
2019-04-03 00:44:55 +01:00
newName=$( cat ./.tmp | tr -dc '[:alnum:]\n\r' )
2019-01-14 12:46:19 +01:00
if [ ${#newName} -eq 0 ]; then
echo "FAIL input cannot be empty"
exit 1
fi
fi
# config file
blitzConfig="/mnt/hdd/raspiblitz.conf"
# lnd conf file
lndConfig="/mnt/hdd/lnd/lnd.conf"
# check if raspibblitz config file exists
configExists=$(ls ${blitzConfig} | grep -c '.conf')
if [ ${configExists} -eq 0 ]; then
echo "FAIL - missing ${blitzConfig}"
exit 1
fi
# make sure entry line for 'hostname' exists
entryExists=$(cat ${blitzConfig} | grep -c 'hostname=')
if [ ${entryExists} -eq 0 ]; then
echo "hostname=" >> ${blitzConfig}
fi
# make sure entry line for 'setnetworkname' exists
entryExists=$(cat ${blitzConfig} | grep -c 'setnetworkname=')
if [ ${entryExists} -eq 0 ]; then
echo "setnetworkname=" >> ${blitzConfig}
fi
2019-01-14 12:46:19 +01:00
# check if lnd config file exists
configExists=$(ls ${lndConfig} | grep -c '.conf')
if [ ${configExists} -eq 0 ]; then
echo "FAIL - missing ${lndConfig}"
exit 1
fi
# make sure entry line for 'alias' exists
entryExists=$(cat ${lndConfig} | grep -c 'alias=')
if [ ${entryExists} -eq 0 ]; then
echo "alias=" >> ${blitzConfig}
fi
# stop services
echo "making sure services are not running"
sudo systemctl stop lnd 2>/dev/null
# lnd.conf: change name
sudo sed -i "s/^alias=.*/alias=${newName}/g" ${lndConfig}
# raspiblitz.conf: change name
sudo sed -i "s/^hostname=.*/hostname=${newName}/g" ${blitzConfig}
# set name in local network just if forced (not anymore by default)
# see https://github.com/rootzoll/raspiblitz/issues/819
if [ "$2" = "alsoNetwork" ]; then
# OS: change hostname
sudo raspi-config nonint do_hostname ${newName}
sudo sed -i "s/^setnetworkname=.*/setnetworkname=1/g" ${blitzConfig}
else
sudo sed -i "s/^setnetworkname=.*/setnetworkname=0/g" ${blitzConfig}
fi
2019-01-14 12:46:19 +01:00
echo "needs reboot to run normal again"
exit 0