diff --git a/misc/add-tailscale-lxc.sh b/misc/add-tailscale-lxc.sh index 52de7c9f..4020ac43 100644 --- a/misc/add-tailscale-lxc.sh +++ b/misc/add-tailscale-lxc.sh @@ -17,9 +17,8 @@ EOF } clear header_info -echo -e "\e[1;33mThis script will add Tailscale to an existing LXC Container ONLY\e[0m" while true; do - read -p "Did you replace 106 with your LXC ID? Proceed(y/n)?" yn + read -p "This will add Tailscale to an existing LXC Container ONLY. Proceed(y/n)?" yn case $yn in [Yy]*) break ;; [Nn]*) exit ;; @@ -48,7 +47,24 @@ function msg() { echo -e "$TEXT" } -CTID=$1 +NODE=$(hostname) +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 + CTID=$(whiptail --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 + CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf cat <>$CTID_CONFIG_PATH lxc.cgroup2.devices.allow: c 10:200 rwm