From 7d6806e1fb3789c560ae0ce29e8d4b3709b738b8 Mon Sep 17 00:00:00 2001 From: masterofrpm <31867749+masterofrpm@users.noreply.github.com> Date: Mon, 4 Aug 2025 11:37:11 -0500 Subject: [PATCH] turnkey: add hostname & Fix TUN access (#6512) * Update turnkey.sh Allow choosing container ID & add tun device access to the container. Also notify user that the credentials are stored in a file on the host machine. * Update turnkey.sh fixed how tun access is added by instead modifying the conf file of the container. Also added filtering to only add tun access if required. A few other minor verbiage changes/corrections. * Update turnkey.sh Corrected variable expansion. --- turnkey/turnkey.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/turnkey/turnkey.sh b/turnkey/turnkey.sh index 93337f02e..7cb835470 100644 --- a/turnkey/turnkey.sh +++ b/turnkey/turnkey.sh @@ -98,11 +98,14 @@ turnkey=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "TurnKey LXCs # Setup script environment PASS="$(openssl rand -base64 8)" -CTID=$(pvesh get /cluster/nextid) +# Prompt user to confirm container ID + CTID=$(whiptail --backtitle "Container ID" --title "Choose the Container ID" --inputbox "Enter the conatiner ID..." 8 40 $(pvesh get /cluster/nextid) 3>&1 1>&2 2>&3) +# Prompt user to confirm Hostname + HOST_NAME=$(whiptail --backtitle "Hostname" --title "Choose the Hostname" --inputbox "Enter the containers Hostname..." 8 40 "turnkey-${turnkey}" 3>&1 1>&2 2>&3) PCT_OPTIONS=" -features keyctl=1,nesting=1 - -hostname turnkey-${turnkey} - -tags proxmox-helper-scripts + -hostname $HOST_NAME + -tags community-script -onboot 1 -cores 2 -memory 2048 @@ -199,6 +202,15 @@ pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/ # Save password echo "TurnKey ${turnkey} password: ${PASS}" >>~/turnkey-${turnkey}.creds # file is located in the Proxmox root directory +# If turnkey is "OpenVPN", add access to the tun device +TUN_DEVICE_REQUIRED=("openvpn") # Setup this way in case future turnkeys also need tun access +if printf '%s\n' "${TUN_DEVICE_REQUIRED[@]}" | grep -qw "${turnkey}"; then + info "${turnkey} requires access to /dev/net/tun on the host. Modifying the container configuration to allow this." + echo "lxc.cgroup2.devices.allow: c 10:200 rwm" >> /etc/pve/lxc/${CTID}.conf + echo "lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file 0 0" >> /etc/pve/lxc/${CTID}.conf + sleep 5 +fi + # Start container msg "Starting LXC Container..." pct start "$CTID" @@ -239,4 +251,5 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" +info "(credentials also stored in the root user's root directory in the 'turnkey-${turnkey}.creds' file.)" echo