add-tailscale-lxc.sh 1.6 KB

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