Files

117 lines
5.1 KiB
Bash

#!/usr/bin/env bash
DYNR_CORE="https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/core"
eval "$(curl -fsSL ${DYNR_CORE}/api.func)"
eval "$(curl -fsSL ${DYNR_CORE}/core.func)"
APP="NetBird Client"
MODULE_PATH="modules/provision/networking/netbirdclient.sh"
WHIPTITLE="Dynasty Revolution Provisioning"
header_info
INSTALL_MODE="local"
if command -v pveversion >/dev/null 2>&1; then
if whiptail --backtitle "$WHIPTITLE" --title "HOST INSTALL" --yesno "Install NetBird Client on this Proxmox Host?" 10 58; then
INSTALL_MODE="local"
else
INSTALL_MODE="lxc"
fi
fi
MGMT_URL=$(whiptail --backtitle "$WHIPTITLE" --title "CONFIGURATION" --inputbox "Enter Management URL:" 10 58 "https://netbird.dynastyrevolution.com" 3>&1 1>&2 2>&3)
SETUP_KEY=$(whiptail --backtitle "$WHIPTITLE" --title "CONFIGURATION" --inputbox "Enter Setup Key:" 10 58 "" 3>&1 1>&2 2>&3)
if [[ "$INSTALL_MODE" == "local" ]]; then
if [ ! -c /dev/net/tun ]; then
msg_error "/dev/net/tun is not active."
msg_info "Run this script from the Proxmox Host or activate /dev/net/tun manually."
exit 1
fi
header_info
msg_info "Preparing Netbird Client Installation...."
if command -v apt-get &>/dev/null; then
curl -fsSL https://pkgs.netbird.io/install.sh | sh >/dev/null 2>&1
elif command -v apk &>/dev/null; then
apk add curl bash ca-certificates >/dev/null 2>&1
curl -fsSL https://github.com/netbirdio/netbird/releases/latest/download/netbird_linux_amd64.tar.gz | tar -xz -C /usr/local/bin netbird >/dev/null 2>&1
elif command -v dnf &>/dev/null; then
dnf install -y netbird >/dev/null 2>&1
elif command -v pacman &>/dev/null; then
pacman -S --noconfirm netbird >/dev/null 2>&1
fi
netbird up --management-url "$MGMT_URL" --admin-url "$MGMT_URL" --setup-key "$SETUP_KEY" >/dev/null 2>&1
msg_ok "Netbird Client Installed."
LOCAL_IP=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1 || echo "Unknown")
NB_IP=$(netbird status | grep "NetBird IP:" | awk '{print $3}' || echo "Pending")
echo -e "\n${TAB}Local IP: ${BLUE}${LOCAL_IP}${NC}"
echo -e "${TAB}NetBird IP: ${BLUE}${NB_IP}${NC}"
echo -e "\n${GOLD}${BOLD}COMPLETED SUCCESSFULLY! ${NC}\n"
exit 0
fi
CTID_MENU=()
while read -r line; do
TAG=$(echo "$line" | awk '{print $1}')
ITEM=$(echo "$line" | awk '{print substr($0,36)}')
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(pct list | awk 'NR>1')
SELECTED_VMS=$(whiptail --backtitle "$WHIPTITLE" --title "CLIENT INJECTION" --checklist "Select LXC(s) for Injection (Use Spacebar):" 20 60 10 "${CTID_MENU[@]}" 3>&1 1>&2 2>&3)
[ -z "$SELECTED_VMS" ] && exit 1
SELECTED_VMS=$(echo $SELECTED_VMS | tr -d '"')
header_info
rm -f /opt/DYNR/netbirdclient-ips.txt
touch /opt/DYNR/netbirdclient-ips.txt
for VMID in $SELECTED_VMS; do
echo -e "${PURPLE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
msg_info "Adding TUN Kernel Passthrough...."
CONF_PATH=/etc/pve/lxc/${VMID}.conf
if ! grep -q "dev/net/tun" "$CONF_PATH"; then
cat <<EOF >>$CONF_PATH
lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
EOF
fi
LXC_STATUS=$(pct status "$VMID" | awk '{print $2}')
if [[ "$LXC_STATUS" != "running" ]]; then
msg_info "Waking ${VMID}...."
pct start "$VMID"
until [[ "$(pct status "$VMID" | awk '{print $2}')" == "running" ]]; do sleep 1; done
fi
msg_info "Preparing Netbird Client Installation...."
pct exec $VMID -- bash -c "
if command -v apt-get &>/dev/null; then
curl -fsSL https://pkgs.netbird.io/install.sh | sh >/dev/null 2>&1
elif command -v apk &>/dev/null; then
apk add curl bash ca-certificates >/dev/null 2>&1
curl -fsSL https://github.com/netbirdio/netbird/releases/latest/download/netbird_linux_amd64.tar.gz | tar -xz -C /usr/local/bin netbird >/dev/null 2>&1
elif command -v dnf &>/dev/null; then
dnf install -y netbird >/dev/null 2>&1
elif command -v pacman &>/dev/null; then
pacman -S --noconfirm netbird >/dev/null 2>&1
fi
netbird up --management-url $MGMT_URL --admin-url $MGMT_URL --setup-key $SETUP_KEY >/dev/null 2>&1
"
msg_ok "Netbird Client Installed."
LXC_IP=$(pct exec $VMID -- ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1 || echo "Unknown")
NB_IP=$(pct exec $VMID -- netbird status | grep "NetBird IP:" | awk '{print $3}' || echo "Pending")
echo "LXC $VMID IP: $LXC_IP , Netbird IP: $NB_IP" >> /opt/DYNR/netbirdclient-ips.txt
done
echo -e "\n${GOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
cat /opt/DYNR/netbirdclient-ips.txt
echo -e "${GOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "\n${GOLD}${BOLD}COMPLETED SUCCESSFULLY! ${NC}\n"