add-tailscale-lxc.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. echo -e "\e[1;33mThis script will add Tailscale to an existing LXC Container ONLY\e[0m"
  3. while true; do
  4. read -p "Did you replace 106 with your LXC ID? Proceed(y/n)?" yn
  5. case $yn in
  6. [Yy]* ) break;;
  7. [Nn]* ) exit;;
  8. * ) echo "Please answer yes or no.";;
  9. esac
  10. done
  11. set -o errexit
  12. set -o errtrace
  13. set -o nounset
  14. set -o pipefail
  15. shopt -s expand_aliases
  16. alias die='EXIT=$? LINE=$LINENO error_exit'
  17. trap die ERR
  18. function error_exit() {
  19. trap - ERR
  20. local reason="Unknown failure occured."
  21. local msg="${1:-$reason}"
  22. local flag="\e[1;31m‼ ERROR\e[0m $EXIT@$LINE"
  23. echo -e "$flag $msg" 1>&2
  24. exit $EXIT
  25. }
  26. function msg() {
  27. local TEXT="$1"
  28. echo -e "$TEXT"
  29. }
  30. CTID=$1
  31. CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf
  32. cat <<EOF >> $CTID_CONFIG_PATH
  33. lxc.cgroup2.devices.allow: c 10:200 rwm
  34. lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
  35. EOF
  36. msg "⏳ Installing Tailscale..."
  37. lxc-attach -n $CTID -- bash -c "$(curl -fsSL https://tailscale.com/install.sh)" &>/dev/null || exit
  38. msg "⌛ Installed Tailscale"
  39. sleep 2
  40. msg "\e[1;32m ✔ Completed Successfully!\e[0m"
  41. msg "\e[1;31m Reboot ${CTID} LXC to apply the changes, then run tailscale up in the LXC console\e[0m"