diff --git a/tools/addon/add-netbird-lxc.sh b/tools/addon/add-netbird-lxc.sh index 5c21e672f..ce2599670 100644 --- a/tools/addon/add-netbird-lxc.sh +++ b/tools/addon/add-netbird-lxc.sh @@ -6,6 +6,19 @@ # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # Source: https://netbird.io/ | Github: https://github.com/netbirdio/netbird +APP="add-netbird-lxc" +APP_TYPE="addon" + +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/tools.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/error_handler.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2>/dev/null || true +declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "add-netbird-lxc" "addon" + +# Enable error handling +set -Eeuo pipefail +trap 'error_handler' ERR + function header_info { clear cat <<"EOF" @@ -17,28 +30,22 @@ function header_info { EOF } -header_info -set -e -# Telemetry -source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2>/dev/null || true -declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "add-netbird-lxc" "addon" +# Initialize all core functions (colors, formatting, icons, STD mode) +load_functions + +header_info while true; do - read -p "This will add NetBird to an existing LXC Container ONLY. Proceed(y/n)?" yn + read -r -p "This will add NetBird to an existing LXC Container ONLY. Proceed(y/n)?" yn case $yn in [Yy]*) break ;; - [Nn]*) exit ;; + [Nn]*) exit 0 ;; *) echo "Please answer yes or no." ;; esac done header_info -echo "Loading..." - -function msg() { - local TEXT="$1" - echo -e "$TEXT" -} +msg_info "Loading container list..." NODE=$(hostname) MSG_MAX_LENGTH=0 @@ -61,28 +68,28 @@ done LXC_STATUS=$(pct status "$CTID" | awk '{print $2}') if [[ "$LXC_STATUS" != "running" ]]; then - msg "\e[1;33m The container $CTID is not running. Starting it now...\e[0m" + msg_info "Container $CTID is not running. Starting it now..." pct start "$CTID" while [[ "$(pct status "$CTID" | awk '{print $2}')" != "running" ]]; do - msg "\e[1;33m Waiting for the container to start...\e[0m" + msg_info "Waiting for the container to start..." sleep 2 done - msg "\e[1;32m Container $CTID is now running.\e[0m" + msg_ok "Container $CTID is now running." fi DISTRO=$(pct exec "$CTID" -- cat /etc/os-release | grep -w "ID" | cut -d'=' -f2 | tr -d '"') if [[ "$DISTRO" != "debian" && "$DISTRO" != "ubuntu" ]]; then - msg "\e[1;31m Error: This script only supports Debian or Ubuntu LXC containers. Detected: $DISTRO. Aborting...\e[0m" + msg_error "This script only supports Debian or Ubuntu LXC containers. Detected: $DISTRO. Aborting..." exit 238 fi -CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf -cat <>$CTID_CONFIG_PATH +CTID_CONFIG_PATH="/etc/pve/lxc/${CTID}.conf" +cat <>"$CTID_CONFIG_PATH" lxc.cgroup2.devices.allow: c 10:200 rwm lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file EOF header_info -msg "Installing NetBird..." +msg_info "Installing NetBird" pct exec "$CTID" -- bash -c ' if ! command -v curl &>/dev/null; then apt-get update -qq @@ -103,6 +110,5 @@ OVERRIDE systemctl daemon-reload fi ' -msg "\e[1;32m ✔ Installed NetBird.\e[0m" -sleep 2 -msg "\e[1;31m Reboot ${CTID} LXC to apply the changes, then run netbird up in the LXC console\e[0m" +msg_ok "Installed NetBird." +echo -e "${YW}Reboot ${CTID} LXC${CL} to apply the changes, then run 'netbird up' in the LXC console" diff --git a/tools/addon/add-tailscale-lxc.sh b/tools/addon/add-tailscale-lxc.sh index 70e883c2e..76487ad83 100644 --- a/tools/addon/add-tailscale-lxc.sh +++ b/tools/addon/add-tailscale-lxc.sh @@ -5,8 +5,18 @@ # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # Source: https://tailscale.com/ | Github: https://github.com/tailscale/tailscale +APP="add-tailscale-lxc" +APP_TYPE="addon" + +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/tools.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/error_handler.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2>/dev/null || true +declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "add-tailscale-lxc" "addon" + +# Enable error handling set -Eeuo pipefail -trap 'echo -e "\n[ERROR] in line $LINENO: exit code $?"' ERR +trap 'error_handler' ERR function header_info() { clear @@ -20,13 +30,8 @@ function header_info() { EOF } -function msg_info() { echo -e " \e[1;36m➤\e[0m $1"; } -function msg_ok() { echo -e " \e[1;32m✔\e[0m $1"; } -function msg_error() { echo -e " \e[1;31m✖\e[0m $1"; } - -# Telemetry -source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2>/dev/null || true -declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "add-tailscale-lxc" "addon" +# Initialize all core functions (colors, formatting, icons, STD mode) +load_functions header_info @@ -168,4 +173,4 @@ TAGS="${TAGS:+$TAGS; }tailscale" pct set "$CTID" -tags "$TAGS" msg_ok "Tailscale installed on CT $CTID" -msg_info "Reboot the container, then run 'tailscale up' inside the container to activate." +echo -e "${YW}Reboot the container${CL}, then run 'tailscale up' inside the container to activate."