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.
This commit is contained in:
masterofrpm 2025-08-04 11:37:11 -05:00 committed by GitHub
parent 86d438c3a1
commit 7d6806e1fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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