From 928a5cb9e5b686b760bbd494ae7bb8069c4e2a44 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:54:44 +0100 Subject: [PATCH] Patch Netbird Script | Container Boot-Check | Debian/Ubuntu Only (#528) * Update Add-Netbird - Container Online-Check (Boot if LXC stopped) - Alpine Check -> Abort if not Debian/Ubuntu * Improve Netbird Json for website * remove dev comments * Change copyright --- json/add-netbird-lxc.json | 10 +++++++--- misc/add-netbird-lxc.sh | 25 ++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/json/add-netbird-lxc.json b/json/add-netbird-lxc.json index 4a1c4a39..597f142b 100644 --- a/json/add-netbird-lxc.json +++ b/json/add-netbird-lxc.json @@ -33,11 +33,15 @@ "notes": [ { "text": "After the script finishes, reboot the LXC then run `netbird up` in the LXC console", - "type": "warning" + "type": "info" }, { - "text": "Execute within the Proxmox shell", + "text": "Execute within the Proxmox main shell", + "type": "info" + } + { + "text": "The script only works in Debian/Ubuntu, not in Alpine!", "type": "warning" } ] -} \ No newline at end of file +} diff --git a/misc/add-netbird-lxc.sh b/misc/add-netbird-lxc.sh index 098e7692..c543bed0 100644 --- a/misc/add-netbird-lxc.sh +++ b/misc/add-netbird-lxc.sh @@ -2,6 +2,7 @@ # Copyright (c) 2021-2024 tteck # Author: tteck (tteckster) +# Co-Author: MickLesk (Canbiz) # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE @@ -10,9 +11,9 @@ clear cat <<"EOF" _ __ __ ____ _ __ / | / /__ / /_/ __ )(_)________/ / - / |/ / _ \/ __/ __ / / ___/ __ / - / /| / __/ /_/ /_/ / / / / /_/ / -/_/ |_/\___/\__/_____/_/_/ \__,_/ + / |/ / _ \/ __/ __ / / ___/ __ / + / /| / __/ /_/ /_/ / / / / /_/ / +/_/ |_/\___/\__/_____/_/_/ \__,_/ EOF } @@ -28,6 +29,7 @@ while true; do done header_info echo "Loading..." + function msg() { local TEXT="$1" echo -e "$TEXT" @@ -52,6 +54,23 @@ while [ -z "${CTID:+x}" ]; do "${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || exit 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" + pct start "$CTID" + while [[ "$(pct status "$CTID" | awk '{print $2}')" != "running" ]]; do + msg "\e[1;33m Waiting for the container to start...\e[0m" + sleep 2 + done + msg "\e[1;32m Container $CTID is now running.\e[0m" +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" + exit 1 +fi + CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf cat <>$CTID_CONFIG_PATH lxc.cgroup2.devices.allow: c 10:200 rwm