BASH 7188
Proxmox WireGuard LXC Guest on 13th November 2022 09:37:14 AM
  1. To create a new Proxmox WireGuard LXC, run the following in the Proxmox Shell.
  2.  
  3. #!/usr/bin/env bash
  4. echo -e "Loading..."
  5. APP="Wireguard"
  6. var_disk="2"
  7. var_cpu="1"
  8. var_ram="512"
  9. var_os="debian"
  10. var_version="11"
  11. NSAPP=$(echo ${APP,,} | tr -d ' ')
  12. var_install="${NSAPP}-install"
  13. NEXTID=$(pvesh get /cluster/nextid)
  14. INTEGER='^[0-9]+$'
  15. YW=$(echo "\033[33m")
  16. BL=$(echo "\033[36m")
  17. RD=$(echo "\033[01;31m")
  18. BGN=$(echo "\033[4;92m")
  19. GN=$(echo "\033[1;92m")
  20. DGN=$(echo "\033[32m")
  21. CL=$(echo "\033[m")
  22. BFR="\\r\\033[K"
  23. HOLD="-"
  24. CM="${GN}${CL}"
  25. set -o errexit
  26. set -o errtrace
  27. set -o nounset
  28. set -o pipefail
  29. shopt -s expand_aliases
  30. alias die='EXIT=$? LINE=$LINENO error_exit'
  31. trap die ERR
  32. function error_exit() {
  33.   trap - ERR
  34.   local reason="Unknown failure occurred."
  35.   local msg="${1:-$reason}"
  36.   local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  37.   echo -e "$flag $msg" 1>&2
  38.   exit $EXIT
  39. }
  40. if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
  41.   echo "User selected Yes"
  42. else
  43.   clear
  44.   echo -e "⚠ User exited script \n"
  45.   exit
  46. fi
  47. function header_info {
  48.   echo -e "${RD}
  49. __          ___           _____                     _
  50. \ \        / (_)         / ____|                   | |
  51.  \ \  /\  / / _ _ __ ___| |  __ _   _  __ _ _ __ __| |
  52.   \ \/  \/ / | |  __/ _ \ | |_ | | | |/ _  |  __/ _  |
  53.    \  /\  /  | | | |  __/ |__| | |_| | (_| | | | (_| |
  54.     \/  \/ v4|_|_|  \___|\_____|\__,_|\__,_|_|  \__,_|
  55.                   ${YW}With WGDashboard
  56. ${CL}"
  57. }
  58. function msg_info() {
  59.   local msg="$1"
  60.   echo -ne " ${HOLD} ${YW}${msg}..."
  61. }
  62. function msg_ok() {
  63.   local msg="$1"
  64.   echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  65. }
  66. function PVE_CHECK() {
  67.   PVE=$(pveversion | grep "pve-manager/7" | wc -l)
  68.   if [[ $PVE != 1 ]]; then
  69.     echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}"
  70.     echo -e "Exiting..."
  71.     sleep 2
  72.     exit
  73.   fi
  74. }
  75. function default_settings() {
  76.   echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}"
  77.   CT_TYPE="1"
  78.   echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}"
  79.   PW=""
  80.   echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}"
  81.   CT_ID=$NEXTID
  82.   echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}"
  83.   HN=$NSAPP
  84.   echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}"
  85.   DISK_SIZE="$var_disk"
  86.   echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}"
  87.   CORE_COUNT="$var_cpu"
  88.   echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}"
  89.   RAM_SIZE="$var_ram"
  90.   echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}"
  91.   BRG="vmbr0"
  92.   echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}"
  93.   NET=dhcp
  94.   echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}"
  95.   GATE=""
  96.   echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}"
  97.   MAC=""
  98.   echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}"
  99.   VLAN=""
  100.   echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}"
  101. }
  102. function advanced_settings() {
  103.   CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 8 58 2 \
  104.     "1" "Unprivileged" ON \
  105.     "0" "Privileged" OFF \
  106.     3>&1 1>&2 2>&3)
  107.   exitstatus=$?
  108.   if [ $exitstatus = 0 ]; then
  109.     echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}"
  110.   fi
  111.   PW1=$(whiptail --inputbox "Set Root Password" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  112.   exitstatus=$?
  113.   if [ $exitstatus = 0 ]; then
  114.     if [ -z $PW1 ]; then
  115.       PW1="Automatic Login" PW=" "
  116.       echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  117.     else
  118.       PW="-password $PW1"
  119.       echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  120.     fi
  121.   fi
  122.   CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  123.   exitstatus=$?
  124.   if [ -z $CT_ID ]; then
  125.     CT_ID="$NEXTID"
  126.     echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}"
  127.   else
  128.     if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi
  129.   fi
  130.   CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  131.   exitstatus=$?
  132.   if [ -z $CT_NAME ]; then
  133.     HN="$NSAPP"
  134.     echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  135.   else
  136.     if [ $exitstatus = 0 ]; then
  137.       HN=$(echo ${CT_NAME,,} | tr -d ' ')
  138.       echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  139.     fi
  140.   fi
  141.   DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  142.   exitstatus=$?
  143.   if [ -z $DISK_SIZE ]; then
  144.     DISK_SIZE="$var_disk"
  145.     echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"
  146.   else
  147.     if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi
  148.     if ! [[ $DISK_SIZE =~ $INTEGER ]]; then
  149.       echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}"
  150.       advanced_settings
  151.     fi
  152.   fi
  153.   CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  154.   exitstatus=$?
  155.   if [ -z $CORE_COUNT ]; then
  156.     CORE_COUNT="$var_cpu"
  157.     echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  158.   else
  159.     if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi
  160.   fi
  161.   RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  162.   exitstatus=$?
  163.   if [ -z $RAM_SIZE ]; then
  164.     RAM_SIZE="$var_ram"
  165.     echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  166.   else
  167.     if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi
  168.   fi
  169.   BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  170.   exitstatus=$?
  171.   if [ -z $BRG ]; then
  172.     BRG="vmbr0"
  173.     echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
  174.   else
  175.     if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi
  176.   fi
  177.   NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  178.   exitstatus=$?
  179.   if [ -z $NET ]; then
  180.     NET="dhcp"
  181.     echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"
  182.   else
  183.     if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi
  184.   fi
  185.   GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  186.   exitstatus=$?
  187.   if [ $exitstatus = 0 ]; then
  188.     if [ -z $GATE1 ]; then
  189.       GATE1="Default" GATE=""
  190.       echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  191.     else
  192.       GATE=",gw=$GATE1"
  193.       echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  194.     fi
  195.   fi
  196.   MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  197.   exitstatus=$?
  198.   if [ $exitstatus = 0 ]; then
  199.     if [ -z $MAC1 ]; then
  200.       MAC1="Default" MAC=""
  201.       echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  202.     else
  203.       MAC=",hwaddr=$MAC1"
  204.       echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  205.     fi
  206.   fi
  207.   VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  208.   exitstatus=$?
  209.   if [ $exitstatus = 0 ]; then
  210.     if [ -z $VLAN1 ]; then
  211.       VLAN1="Default" VLAN=""
  212.       echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  213.     else
  214.       VLAN=",tag=$VLAN1"
  215.       echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  216.     fi
  217.   fi
  218.   if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then
  219.     echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}"
  220.   else
  221.     clear
  222.     header_info
  223.     echo -e "${RD}Using Advanced Settings${CL}"
  224.     advanced_settings
  225.   fi
  226. }
  227. function start_script() {
  228.   if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
  229.     header_info
  230.     echo -e "${BL}Using Default Settings${CL}"
  231.     default_settings
  232.   else
  233.     header_info
  234.     echo -e "${RD}Using Advanced Settings${CL}"
  235.     advanced_settings
  236.   fi
  237. }
  238. clear
  239. start_script
  240. if [ "$CT_TYPE" == "1" ]; then
  241.   FEATURES="nesting=1,keyctl=1"
  242. else
  243.   FEATURES="nesting=1"
  244. fi
  245. TEMP_DIR=$(mktemp -d)
  246. pushd $TEMP_DIR >/dev/null
  247. export CTID=$CT_ID
  248. export PCT_OSTYPE=$var_os
  249. export PCT_OSVERSION=$var_version
  250. export PCT_DISK_SIZE=$DISK_SIZE
  251. export PCT_OPTIONS="
  252.  -features $FEATURES
  253.  -hostname $HN
  254.  -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN
  255.  -onboot 1
  256.  -cores $CORE_COUNT
  257.  -memory $RAM_SIZE
  258.  -unprivileged $CT_TYPE
  259.  $PW
  260. "
  261. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  262. msg_info "Starting LXC Container"
  263. pct start $CTID
  264. msg_ok "Started LXC Container"
  265. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/$var_install.sh)" || exit
  266. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  267. pct set $CTID -description "# ${APP} LXC
  268. ### https://tteck.github.io/Proxmox/
  269. <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/☕-Buy me a coffee-red' /></a>"
  270. msg_ok "Completed Successfully!\n"
  271. echo -e "WGDashboard should be reachable by going to the following URL.
  272.         ${BL}http://${IP}:10086${CL} \n"

paste.retronerd.at ist fuer Quelltexte und generellen Debugging Text.

Login oder Registrieren um zu bearbeiten, loeschen, um deine Pastes zu verfolgen und mehr.

Raw Paste

Login oder Registrieren um diesen Paste zu bearbeiten oder zu forken. Es ist kostenlos.