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

61 lines
1.8 KiB
Bash
Raw Normal View History

2018-12-01 22:05:42 +01:00
#!/bin/bash
# based on: https://github.com/raspibolt/raspibolt/issues/249
2018-12-01 22:05:42 +01:00
if [ $# -eq 0 ]; then
echo "small config script to switch the LND autoNatDiscovery on or off"
2022-01-29 21:59:16 +01:00
echo "lnd.autonat.sh [on|off|info]"
2018-12-01 22:05:42 +01:00
exit 1
fi
# check lnd.conf exits
lndConfExists=$(sudo ls /mnt/hdd/lnd/lnd.conf | grep -c 'lnd.conf')
if [ ${lndConfExists} -eq 0 ]; then
2022-01-29 21:59:16 +01:00
echo "# FAIL - /mnt/hdd/lnd/lnd.conf not found"
2018-12-01 22:05:42 +01:00
exit 1
fi
2022-01-29 21:59:16 +01:00
# info
if [ "$1" = "info" ]; then
natIsOn=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep -c 'nat=true')
if [ "${natIsOn}" == "1" ]; then
echo "autoNatDiscovery=on"
else
echo "autoNatDiscovery=off"
fi
exit 0
fi
# check if "nat" exists in lnd config
2018-12-01 22:05:42 +01:00
valueExists=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep -c 'nat=')
if [ ${valueExists} -eq 0 ]; then
2022-01-29 21:59:16 +01:00
echo "# Adding autonat config defaults to /mnt/hdd/lnd/lnd.conf"
applicationOptionsLineNumber=$(grep -n "\[Application Options\]" /mnt/hdd/lnd/lnd.conf | cut -d ":" -f1)
applicationOptionsLineNumber="$(($applicationOptionsLineNumber+1))"
2022-01-29 22:03:40 +01:00
sudo sed -i "${applicationOptionsLineNumber}inat=false" /mnt/hdd/lnd/lnd.conf
2018-12-01 22:05:42 +01:00
fi
2022-01-29 21:59:16 +01:00
# delete nat is still in raspiblitz.conf (its OK when just in lnd.conf since v1.7.2)
/home/admin/config.scripts/blitz.conf.sh delete autoNatDiscovery
2018-12-02 21:46:00 +01:00
2018-12-01 22:05:42 +01:00
# switch on
2018-12-02 20:43:48 +01:00
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
2022-01-29 21:59:16 +01:00
echo "# switching the LND autonat ON"
2018-12-01 22:05:42 +01:00
sudo sed -i "s/^nat=.*/nat=true/g" /mnt/hdd/lnd/lnd.conf
2022-01-29 21:59:16 +01:00
echo "# OK - autonat is now ON"
echo "# needs reboot to activate new setting"
2018-12-01 22:05:42 +01:00
exit 0
fi
# switch off
2018-12-02 20:43:48 +01:00
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
2022-01-29 21:59:16 +01:00
echo "# switching the LND autonat OFF"
2018-12-01 22:05:42 +01:00
sudo sed -i "s/^nat=.*/nat=false/g" /mnt/hdd/lnd/lnd.conf
2022-01-29 21:59:16 +01:00
echo "# OK - autonat is now OFF"
echo "# needs reboot to activate new setting"
2018-12-01 22:05:42 +01:00
exit 0
fi
2021-08-27 03:59:21 -04:00
echo "FAIL - Unknown Parameter $1"
2018-12-02 19:52:01 +01:00
echo "may needs reboot to run normal again"
2018-12-01 22:05:42 +01:00
exit 1