Proxmox/misc/add-tailscale-lxc.sh

64 lines
1.6 KiB
Bash
Raw Normal View History

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