ProxmoxVE-HelperScripts/misc/add-tailscale-lxc.sh

73 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2022-07-03 13:36:31 -04:00
#!/usr/bin/env bash
2023-02-07 12:15:22 -05:00
2024-01-01 12:13:05 -05:00
# Copyright (c) 2021-2024 tteck
2023-02-07 12:15:22 -05:00
# Author: tteck (tteckster)
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
2023-01-10 14:55:44 -05:00
function header_info {
2023-12-22 19:51:33 -05:00
clear
2023-01-10 14:55:44 -05:00
cat <<"EOF"
2023-12-23 09:24:52 -05:00
______ _ __ __
2023-11-25 14:03:23 -05:00
/_ __/___ _(_) /_____________ _/ /__
/ / / __ `/ / / ___/ ___/ __ `/ / _ \
/ / / /_/ / / (__ ) /__/ /_/ / / __/
/_/ \__,_/_/_/____/\___/\__,_/_/\___/
2023-01-10 14:55:44 -05:00
EOF
}
header_info
2023-12-23 06:44:38 -05:00
set -e
2022-07-03 13:36:31 -04:00
while true; do
read -p "This will add Tailscale to an existing LXC Container ONLY. Proceed(y/n)?" yn
2022-10-29 21:04:45 -04:00
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
2022-07-03 13:36:31 -04:00
done
2023-12-22 19:51:33 -05:00
header_info
2023-12-23 09:24:52 -05:00
echo "Loading..."
2022-07-03 13:36:31 -04:00
function msg() {
local TEXT="$1"
echo -e "$TEXT"
}
NODE=$(hostname)
2023-11-25 14:03:23 -05:00
MSG_MAX_LENGTH=0
while read -r line; do
TAG=$(echo "$line" | awk '{print $1}')
ITEM=$(echo "$line" | awk '{print substr($0,36)}')
OFFSET=2
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
fi
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(pct list | awk 'NR>1')
while [ -z "${CTID:+x}" ]; do
2023-09-09 05:13:17 -04:00
CTID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --radiolist \
"\nSelect a container to add Tailscale to:\n" \
16 $(($MSG_MAX_LENGTH + 23)) 6 \
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || exit
done
2022-07-03 13:36:31 -04:00
CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf
2022-10-29 21:04:45 -04:00
cat <<EOF >>$CTID_CONFIG_PATH
2022-07-03 13:36:31 -04:00
lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
EOF
2023-12-23 09:24:52 -05:00
header_info
2023-01-10 14:55:44 -05:00
msg "Installing Tailscale..."
pct exec "$CTID" -- bash -c '
ID=$(grep "^ID=" /etc/os-release | cut -d"=" -f2)
VER=$(grep "^VERSION_CODENAME=" /etc/os-release | cut -d"=" -f2)
wget -qO- https://pkgs.tailscale.com/stable/$ID/$VER.noarmor.gpg >/usr/share/keyrings/tailscale-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/tailscale-archive-keyring.gpg] https://pkgs.tailscale.com/stable/$ID $VER main" >/etc/apt/sources.list.d/tailscale.list
apt-get update &>/dev/null
apt-get install -y tailscale &>/dev/null
' || exit
msg "\e[1;32m ✔ Installed Tailscale\e[0m"
2022-07-03 19:56:54 -04:00
msg "\e[1;31m Reboot ${CTID} LXC to apply the changes, then run tailscale up in the LXC console\e[0m"