66# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
77# Source: https://netbird.io/ | Github: https://github.com/netbirdio/netbird
88
9- function header_info {
10- clear
11- cat << "EOF "
12- _ __ __ ____ _ __
13- / | / /__ / /_/ __ )(_)________/ /
14- / |/ / _ \/ __/ __ / / ___/ __ /
15- / /| / __/ /_/ /_/ / / / / /_/ /
16- /_/ |_/\___/\__/_____/_/_/ \__,_/
9+ APP=" add-netbird-lxc"
10+ APP_TYPE=" addon"
1711
18- EOF
19- }
20- header_info
21- set -e
22-
23- # Telemetry
12+ if ! command -v curl & > /dev/null; then
13+ printf " \r\e[2K%b" ' \033[93m Setup Source \033[m' >&2
14+ if [[ -f /etc/alpine-release ]]; then
15+ apk update > /dev/null 2>&1
16+ apk add --no-cache curl > /dev/null 2>&1
17+ else
18+ apt-get update > /dev/null 2>&1
19+ apt-get install -y curl > /dev/null 2>&1
20+ fi
21+ fi
22+ source <( curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func)
23+ source <( curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/tools.func)
24+ source <( curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/error_handler.func)
2425source <( curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2> /dev/null || true
2526declare -f init_tool_telemetry & > /dev/null && init_tool_telemetry " add-netbird-lxc" " addon"
2627
28+ # Enable error handling
29+ set -Eeuo pipefail
30+ trap ' error_handler' ERR
31+
32+ # Initialize all core functions (colors, formatting, icons, STD mode)
33+ load_functions
34+
35+ header_info
36+ require_pve_host
37+
2738while true ; do
28- read -p " This will add NetBird to an existing LXC Container ONLY. Proceed(y/n)?" yn
39+ read -r - p " This will add NetBird to an existing LXC Container ONLY. Proceed(y/n)? " yn
2940 case $yn in
3041 [Yy]* ) break ;;
31- [Nn]* ) exit ;;
42+ [Nn]* ) exit 0 ;;
3243 * ) echo " Please answer yes or no." ;;
3344 esac
3445done
35- header_info
36- echo " Loading..."
3746
38- function msg() {
39- local TEXT=" $1 "
40- echo -e " $TEXT "
41- }
47+ echo -e " Loading container list..."
4248
4349NODE=$( hostname)
4450MSG_MAX_LENGTH=0
6167
6268LXC_STATUS=$( pct status " $CTID " | awk ' {print $2}' )
6369if [[ " $LXC_STATUS " != " running" ]]; then
64- msg " \e[1;33m The container $CTID is not running. Starting it now...\e[0m "
70+ msg_info " Container $CTID is not running. Starting it now..."
6571 pct start " $CTID "
6672 while [[ " $( pct status " $CTID " | awk ' {print $2}' ) " != " running" ]]; do
67- msg " \e[1;33m Waiting for the container to start...\e[0m "
73+ msg_info " Waiting for the container to start..."
6874 sleep 2
6975 done
70- msg " \e[1;32m Container $CTID is now running.\e[0m "
76+ msg_ok " Container $CTID is now running."
7177fi
7278
7379DISTRO=$( pct exec " $CTID " -- cat /etc/os-release | grep -w " ID" | cut -d' =' -f2 | tr -d ' "' )
7480if [[ " $DISTRO " != " debian" && " $DISTRO " != " ubuntu" ]]; then
75- msg " \e[1;31m Error: This script only supports Debian or Ubuntu LXC containers. Detected: $DISTRO . Aborting...\e[0m "
81+ msg_error " This script only supports Debian or Ubuntu LXC containers. Detected: $DISTRO . Aborting..."
7682 exit 238
7783fi
7884
79- CTID_CONFIG_PATH=/etc/pve/lxc/${CTID} .conf
80- cat << EOF >>$CTID_CONFIG_PATH
85+ CTID_CONFIG_PATH=" /etc/pve/lxc/${CTID} .conf"
86+ cat << EOF >>" $CTID_CONFIG_PATH "
8187lxc.cgroup2.devices.allow: c 10:200 rwm
8288lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
8389EOF
84- header_info
85- msg " Installing NetBird... "
90+
91+ msg_info " Installing NetBird"
8692pct exec " $CTID " -- bash -c '
93+ set -e
8794if ! command -v curl &>/dev/null; then
8895 apt-get update -qq
8996 apt-get install -y curl >/dev/null
9097fi
91- apt install -y ca-certificates gpg &>/dev/null
92- curl -fsSL "https://pkgs.netbird.io/debian/public.key" | gpg --dearmor >/usr/share/keyrings/netbird-archive-keyring.gpg
93- echo "deb [signed-by=/usr/share/keyrings/netbird-archive-keyring.gpg] https://pkgs.netbird.io/debian stable main" >/etc/apt/sources.list.d/netbird.list
94- apt-get update &>/dev/null
98+ apt-get install -y ca-certificates gpg &>/dev/null
99+
100+ # Reuse the shared repository helper instead of hand-rolling the sources entry
101+ source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func)
102+ source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/tools.func)
103+ load_functions
104+
105+ # Drop the legacy keyring from the pre-deb822 layout
106+ rm -f /usr/share/keyrings/netbird-archive-keyring.gpg
107+
108+ setup_deb822_repo \
109+ "netbird" \
110+ "https://pkgs.netbird.io/debian/public.key" \
111+ "https://pkgs.netbird.io/debian" \
112+ "stable" \
113+ "main"
114+
95115apt-get install -y netbird-ui &>/dev/null
96116if systemctl list-unit-files docker.service &>/dev/null; then
97117 mkdir -p /etc/systemd/system/netbird.service.d
@@ -103,6 +123,5 @@ OVERRIDE
103123 systemctl daemon-reload
104124fi
105125'
106- msg " \e[1;32m ✔ Installed NetBird.\e[0m"
107- sleep 2
108- msg " \e[1;31m Reboot ${CTID} LXC to apply the changes, then run netbird up in the LXC console\e[0m"
126+ msg_ok " Installed NetBird."
127+ echo -e " ${YW} Reboot ${CTID} LXC${CL} to apply the changes, then run 'netbird up' in the LXC console"
0 commit comments