mirror of
https://github.com/tteck/Proxmox.git
synced 2025-02-15 06:09:15 +01:00
Update add-netbird-lxc.sh
Adds the ability to select multiple containers.
This commit is contained in:
parent
0a35b1a5bb
commit
a544f07fec
1 changed files with 46 additions and 18 deletions
|
@ -19,9 +19,9 @@ EOF
|
||||||
header_info
|
header_info
|
||||||
set -e
|
set -e
|
||||||
while true; do
|
while true; do
|
||||||
read -p "This will add NetBird to an existing LXC Container ONLY. Proceed(y/n)?" yn
|
read -p "This will add NetBird to an existing LXC Container ONLY. Proceed (Y/n)? " yn
|
||||||
case $yn in
|
case $yn in
|
||||||
[Yy]*) break ;;
|
[Yy]*|"") break ;;
|
||||||
[Nn]*) exit ;;
|
[Nn]*) exit ;;
|
||||||
*) echo "Please answer yes or no." ;;
|
*) echo "Please answer yes or no." ;;
|
||||||
esac
|
esac
|
||||||
|
@ -35,6 +35,12 @@ function msg() {
|
||||||
|
|
||||||
NODE=$(hostname)
|
NODE=$(hostname)
|
||||||
MSG_MAX_LENGTH=0
|
MSG_MAX_LENGTH=0
|
||||||
|
declare -a CTID_MENU
|
||||||
|
declare -a SELECTED_CTIDS
|
||||||
|
declare -a ERROR_LOG
|
||||||
|
INSTALL_LOG=""
|
||||||
|
|
||||||
|
# Read the list of containers and prepare the menu
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
TAG=$(echo "$line" | awk '{print $1}')
|
TAG=$(echo "$line" | awk '{print $1}')
|
||||||
ITEM=$(echo "$line" | awk '{print substr($0,36)}')
|
ITEM=$(echo "$line" | awk '{print substr($0,36)}')
|
||||||
|
@ -46,26 +52,48 @@ while read -r line; do
|
||||||
done < <(pct list | awk 'NR>1')
|
done < <(pct list | awk 'NR>1')
|
||||||
|
|
||||||
while [ -z "${CTID:+x}" ]; do
|
while [ -z "${CTID:+x}" ]; do
|
||||||
CTID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --radiolist \
|
# Allow the user to select multiple containers
|
||||||
"\nSelect a container to add NetBird to:\n" \
|
SELECTED_CTIDS=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --checklist \
|
||||||
|
"\nSelect containers to add NetBird to:\n" \
|
||||||
16 $(($MSG_MAX_LENGTH + 23)) 6 \
|
16 $(($MSG_MAX_LENGTH + 23)) 6 \
|
||||||
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || exit
|
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || exit
|
||||||
done
|
done
|
||||||
|
|
||||||
CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf
|
# Strip quotations
|
||||||
cat <<EOF >>$CTID_CONFIG_PATH
|
SELECTED_CTIDS=$(echo "$SELECTED_CTIDS" | tr -d '"')
|
||||||
|
|
||||||
|
# Install NetBird on each selected container
|
||||||
|
for CTID in $SELECTED_CTIDS; do
|
||||||
|
CTID_CONFIG_PATH="/etc/pve/lxc/${CTID}.conf"
|
||||||
|
cat <<EOF >>$CTID_CONFIG_PATH
|
||||||
lxc.cgroup2.devices.allow: c 10:200 rwm
|
lxc.cgroup2.devices.allow: c 10:200 rwm
|
||||||
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
|
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
|
||||||
EOF
|
EOF
|
||||||
header_info
|
header_info
|
||||||
msg "Installing NetBird..."
|
msg "Installing NetBird on container $CTID..."
|
||||||
pct exec "$CTID" -- bash -c '
|
if ! pct exec "$CTID" -- bash -c '
|
||||||
apt install -y ca-certificates gpg &>/dev/null
|
apt install -y ca-certificates gpg &>/dev/null
|
||||||
wget -qO- https://pkgs.netbird.io/debian/public.key | gpg --dearmor >/usr/share/keyrings/netbird-archive-keyring.gpg
|
wget -qO- https://pkgs.netbird.io/debian/public.key | gpg --dearmor >/usr/share/keyrings/netbird-archive-keyring.gpg
|
||||||
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
|
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
|
||||||
apt-get update &>/dev/null
|
apt-get update &>/dev/null
|
||||||
apt-get install -y netbird-ui &>/dev/null
|
apt-get install -y netbird-ui &>/dev/null
|
||||||
' || exit
|
'; then
|
||||||
msg "\e[1;32m ✔ Installed NetBird.\e[0m"
|
ERROR_LOG+=("Error installing NetBird on container $CTID")
|
||||||
sleep 2
|
else
|
||||||
msg "\e[1;31m Reboot ${CTID} LXC to apply the changes, then run netbird up in the LXC console\e[0m"
|
# Append the success message to the INSTALL_LOG variable
|
||||||
|
INSTALL_LOG+="\e[1;32m ✔ Installed NetBird on container $CTID.\e[0m\n"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Display the installation log
|
||||||
|
echo -e "$INSTALL_LOG"
|
||||||
|
|
||||||
|
# Display errors, if any
|
||||||
|
if [ ${#ERROR_LOG[@]} -ne 0 ]; then
|
||||||
|
msg "Some containers encountered errors during installation:"
|
||||||
|
for error in "${ERROR_LOG[@]}"; do
|
||||||
|
msg "$error"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
msg "\e[1;31m Reboot the LXC containers to apply the changes, then run \e[0mnetbird up\e[1;31m in the LXC console\e[0m"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue