raspiblitz/home.admin/config.scripts/bonus.zerotier.sh

122 lines
3.3 KiB
Bash
Raw Normal View History

2020-06-10 18:45:50 +02:00
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "config script to install, uninstall ZeroTier"
echo "bonus.zerotier.sh on [?networkid]"
echo "bonus.zerotier.sh off"
echo "bonus.zerotier.sh menu"
exit 1
fi
2020-06-10 18:45:50 +02:00
source /mnt/hdd/raspiblitz.conf
2020-06-10 18:45:50 +02:00
# show info menu
if [ "$1" = "menu" ]; then
networkDetails=$(sudo zerotier-cli listnetworks | grep OK)
2020-06-10 18:45:50 +02:00
whiptail --title " Info ZeroTier " --msgbox "\n\
2020-06-10 18:45:50 +02:00
Manage your ZeroTier account at https://my.zerotier.com. Add additional devices
(desktop/laptop/mobile) to your network so they can communicate.\n\n\
2021-08-27 03:59:21 -04:00
Currently connected to: $(echo $networkDetails | awk '{ print $3}')\n
2020-06-10 18:45:50 +02:00
Assigned IP: $(echo $networkDetails | awk '{ print $9}')\n\n\
Find more information on how to get started:\n
https://zerotier.atlassian.net/wiki/spaces/SD/pages/8454145/Getting+Started+with+ZeroTier
" 20 100
2020-06-10 18:45:50 +02:00
exit 0
fi
# install
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
if [ "${zerotier}" == "on" ]; then
echo "# FAIL - ZeroTier already installed"
sleep 3
exit 1
fi
2024-03-21 21:34:53 +01:00
sshUI=0
networkID=$2
if [ ${#networkID} -eq 0 ]; then
2024-03-21 21:34:53 +01:00
sshUI=1
trap 'rm -f "$_temp"' EXIT
_temp=$(mktemp -p /dev/shm/)
dialog --backtitle "RaspiBlitz - Settings" \
--title "Join ZeroTier Network" \
--inputbox "\nPlease enter the ZeroTier networkID to connect to:" 10 60 2>"$_temp"
networkID=$(cat "$_temp")
# Remove temporary file explicitly, though it's also handled by the EXIT trap
rm -f "$_temp"
if [ -z "$networkID" ]; then
2024-03-21 21:34:53 +01:00
dialog --msgbox "ZeroTier Connection canceled." 8 46
exit 0
fi
2024-03-21 21:34:53 +01:00
clear
fi
echo "# *** INSTALL ZeroTier ***"
2020-06-10 18:45:50 +02:00
# Download ZeroTier GPG key and install ZeroTier
2020-06-23 22:07:42 +02:00
$(curl -s 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' | gpg --import)
if z=$(curl -s 'https://install.zerotier.com/' | gpg); then echo "$z" | sudo bash 1>&2; fi
2020-06-10 18:45:50 +02:00
echo "# ZeroTier is now installed on your RaspiBlitz"
echo "# Joining zerotier network: ${networkID}"
2020-06-10 18:45:50 +02:00
joinOK=$(sudo zerotier-cli join ${networkID} | grep -c '200 join OK')
if [ ${joinOK} -eq 1 ]; then
echo "# OK - joined"
# setting value in raspi blitz config
/home/admin/config.scripts/blitz.conf.sh set zerotier "${networkID}"
2020-06-24 02:21:53 +02:00
# adding zero tier IP to LND TLS cert
# sudo /home/admin/config.scripts/lnd.tlscert.sh ip-add 172.X
# sudo /home/admin/config.scripts/lnd.credentials.sh reset "${chain:-main}net" tls
# sudo /home/admin/config.scripts/lnd.credentials.sh sync "${chain:-main}net"
2020-06-24 02:21:53 +02:00
2024-03-21 21:34:53 +01:00
if [ $sshUI -eq 1 ]; then
dialog --msgbox "Your RaspiBlitz joined the ZeroTier network." 6 46
else
echo "# OK, ZeroTier is joined."
fi
else
2020-06-23 22:07:42 +02:00
sudo -u admin sudo apt -y purge zerotier-one 1>&2
2024-03-21 21:34:53 +01:00
if [ $sshUI -eq 1 ]; then
dialog --msgbox "FAILED: Joining the ZeroTier networkID(${networkID})" 6 46
else
echo "error='ZeroTier join failed'"
fi
fi
2020-06-10 18:45:50 +02:00
exit 0
fi
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
echo "# *** REMOVING ZEROTIER ***"
# leaving network & deinstall
2020-06-23 22:07:42 +02:00
sudo zerotier-cli leave ${zerotier} 1>&2
sudo -u admin sudo apt -y purge zerotier-one 1>&2
2020-06-10 18:45:50 +02:00
# setting value in raspi blitz config
/home/admin/config.scripts/blitz.conf.sh set zerotier "off"
2020-06-10 18:45:50 +02:00
echo "# OK, ZeroTier is removed."
exit 0
fi
echo "error='unknown parameter'"
exit 1