add-tailscale-lxc.sh 1.5 KB

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