Browse Source

set lnd adress on ssh tunnel

sshtunnel
Christian Rotzoll 6 years ago
parent
commit
5f5ba7e76e
  1. 15
      home.admin/config.scripts/internet.sshtunnel.py
  2. 29
      home.admin/config.scripts/lnd.setaddress.sh

15
home.admin/config.scripts/internet.sshtunnel.py

@ -47,6 +47,7 @@ if len(LNDPORT) == 0:
# on restore other external scripts dont need calling # on restore other external scripts dont need calling
# #
forwardingLND = False
restoringOnUpdate = False restoringOnUpdate = False
if sys.argv[1] == "restore": if sys.argv[1] == "restore":
print("internet.sshtunnel.py -> running with restore flag") print("internet.sshtunnel.py -> running with restore flag")
@ -99,6 +100,7 @@ if sys.argv[1] == "on":
print("[INTERNAL-PORT]<[EXTERNAL-PORT] external not number '%s'" % (sys.argv[i])) print("[INTERNAL-PORT]<[EXTERNAL-PORT] external not number '%s'" % (sys.argv[i]))
sys.exit(1) sys.exit(1)
if port_internal == LNDPORT: if port_internal == LNDPORT:
forwardingLND = True
if port_internal != port_external: if port_internal != port_external:
print("FAIL: When tunneling your local LND port '%s' it needs to be the same on the external server, but is '%s'" % (LNDPORT,port_external)) print("FAIL: When tunneling your local LND port '%s' it needs to be the same on the external server, but is '%s'" % (LNDPORT,port_external))
print("Try again by using the same port. If you cant change the external port, change local LND port with: /home/config.scripts/lnd.setport.sh") print("Try again by using the same port. If you cant change the external port, change local LND port with: /home/config.scripts/lnd.setport.sh")
@ -152,7 +154,13 @@ if sys.argv[1] == "on":
file_content = re.sub("sshtunnel=.*", "sshtunnel='%s %s'" % (ssh_server, ssh_ports), file_content) file_content = re.sub("sshtunnel=.*", "sshtunnel='%s %s'" % (ssh_server, ssh_ports), file_content)
if restoringOnUpdate == False: if restoringOnUpdate == False:
serverdomain=ssh_server.split("@")[1] serverdomain=ssh_server.split("@")[1]
file_content = re.sub("lndAddress=.*", "lndAddress='%s'" % (serverdomain), file_content) # setting server on DynDomain for all other ports
print("Setting server domain for service dyndomain")
subprocess.call("sudo /home/admin/config.scripts/internet.dyndomain.sh on %s" % (serverdomain), shell=True)
if forwardingLND:
# setting server explicitly on LND if LND port is forwarded
print("Setting server domain for LND Port")
subprocess.call("sudo /home/admin/config.scripts/lnd.setadress.sh on %s" % (serverdomain), shell=True)
file_content = "".join([s for s in file_content.splitlines(True) if s.strip("\r\n")]) + "\n" file_content = "".join([s for s in file_content.splitlines(True) if s.strip("\r\n")]) + "\n"
print(file_content) print(file_content)
with open("/mnt/hdd/raspiblitz.conf", "w") as text_file: with open("/mnt/hdd/raspiblitz.conf", "w") as text_file:
@ -198,11 +206,14 @@ elif sys.argv[1] == "off":
print("OK Done") print("OK Done")
print() print()
print("*** Removing LND Address")
subprocess.call("sudo /home/admin/config.scripts/lnd.setadress.sh off", shell=True)
print()
print("*** Removing SSH Tunnel data from RaspiBlitz config") print("*** Removing SSH Tunnel data from RaspiBlitz config")
with open('/mnt/hdd/raspiblitz.conf') as f: with open('/mnt/hdd/raspiblitz.conf') as f:
file_content = f.read() file_content = f.read()
file_content = re.sub("sshtunnel=.*", "", file_content) file_content = re.sub("sshtunnel=.*", "", file_content)
file_content = re.sub("lndAddress=.*", "lndAddress=''", file_content)
file_content = re.sub("\n\n", "\n", file_content) file_content = re.sub("\n\n", "\n", file_content)
print(file_content) print(file_content)
with open("/mnt/hdd/raspiblitz.conf", "w") as text_file: with open("/mnt/hdd/raspiblitz.conf", "w") as text_file:

29
home.admin/config.scripts/lnd.setaddress.sh

@ -1,13 +1,16 @@
#!/bin/bash #!/bin/bash
# INFO : Does not need to be part of update/provision, because
# all data is already on HDD ready
# command info # command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "small config script to set a fixed domain or IP for LND" echo "small config script to set a fixed domain or IP for LND"
echo "internet.dyndomain.sh [domain|ip|off] [?address]" echo "internet.dyndomain.sh [on|off] [?address]"
exit 1 exit 1
fi fi
# 1. parameter [domain|ip|off] # 1. parameter [on|off]
mode="$1" mode="$1"
echo "number of args($#)" echo "number of args($#)"
@ -25,8 +28,8 @@ if [ ${configExists} -eq 0 ]; then
exit 1 exit 1
fi fi
# FIXED DOMAIN # FIXED DOMAIN/IP
if [ "${mode}" = "domain" ]; then if [ "${mode}" = "on" ]; then
address=$2 address=$2
if [ ${#address} -eq 0 ]; then if [ ${#address} -eq 0 ]; then
@ -54,24 +57,6 @@ if [ "${mode}" = "domain" ]; then
echo "fixedAddress is now ON" echo "fixedAddress is now ON"
fi fi
# FIXED IP
if [ "${mode}" = "ip" ]; then
address=$2
if [ ${#address} -eq 0 ]; then
echo "missing parameter"
exit(1)
fi
echo "switching fixed LND IP ON"
echo "address(${address})"
# setting value in raspi blitz config
sudo sed -i "s/^lndAddress=.*/lndAddress='${address}'/g" /mnt/hdd/raspiblitz.conf
echo "fixedAddress is now ON"
fi
# switch off # switch off
if [ "${mode}" = "off" ]; then if [ "${mode}" = "off" ]; then
echo "switching fixedAddress OFF" echo "switching fixedAddress OFF"

Loading…
Cancel
Save