From 99fdc2f17ec824739ca7517598cfa4d77afa7da1 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:07:00 +0100 Subject: [PATCH 01/11] Big Update: Build.func Install.Func Create_LXC --- ct/create_lxc.sh | 42 ++++-- misc/build.func | 339 +++++++++++++++++++++++++++++----------------- misc/install.func | 124 ++++++++++++----- 3 files changed, 340 insertions(+), 165 deletions(-) diff --git a/ct/create_lxc.sh b/ct/create_lxc.sh index aae2fcba..8457e4f7 100644 --- a/ct/create_lxc.sh +++ b/ct/create_lxc.sh @@ -2,6 +2,7 @@ # Copyright (c) 2021-2024 tteck # Author: tteck (tteckster) +# Revision 1.0 (MickLesk 12/2024) # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE @@ -9,15 +10,27 @@ # if [ "$VERBOSE" == "yes" ]; then set -x; fi # This function sets color variables for formatting output in the terminal +# Colors YW=$(echo "\033[33m") +YWB=$(echo "\033[93m") BL=$(echo "\033[36m") RD=$(echo "\033[01;31m") +BGN=$(echo "\033[4;92m") GN=$(echo "\033[1;92m") +DGN=$(echo "\033[32m") + +# Formatting CL=$(echo "\033[m") -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" +UL=$(echo "\033[4m") +BOLD=$(echo "\033[1m") BFR="\\r\\033[K" HOLD=" " +TAB=" " + +# Icons +CM="${TAB}✔️${TAB}${CL}" +CROSS="${TAB}✖️${TAB}${CL}" +INFO="${TAB}💡${TAB}${CL}" # This sets error handling options and defines the error_handler function to handle errors set -Eeuo pipefail @@ -36,21 +49,26 @@ function error_handler() { # This function displays a spinner. function spinner() { - local chars="/-\|" + local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') local spin_i=0 - printf "\e[?25l" + local interval=0.1 + printf "\e[?25l" + + local color="${YWB}" + while true; do - printf "\r \e[36m%s\e[0m" "${chars:spin_i++%${#chars}:1}" - sleep 0.1 + printf "\r ${color}%s${CL}" "${frames[spin_i]}" + spin_i=$(( (spin_i + 1) % ${#frames[@]} )) + sleep "$interval" done } # This function displays an informational message with a yellow color. function msg_info() { local msg="$1" - echo -ne " ${HOLD} ${YW}${msg} " - spinner & - SPINNER_PID=$! + echo -ne " ${TAB}${YW}${msg} " + spinner & + SPINNER_PID=$! } # This function displays a success message with a green color. @@ -58,7 +76,7 @@ function msg_ok() { if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi printf "\e[?25h" local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" + echo -e "${BFR}${CM}${GN}${msg}${CL}" } # This function displays a error message with a red color. @@ -66,7 +84,7 @@ function msg_error() { if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi printf "\e[?25h" local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" + echo -e "${BFR}${CROSS}${RD}${msg}${CL}" } # This checks for the presence of valid Container Storage and Template Storage locations @@ -119,7 +137,7 @@ function select_storage() { else local STORAGE while [ -z "${STORAGE:+x}" ]; do - STORAGE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Storage Pools" --radiolist \ + STORAGE=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "Storage Pools" --radiolist \ "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\nTo make a selection, use the Spacebar.\n" \ 16 $(($MSG_MAX_LENGTH + 23)) 6 \ "${MENU[@]}" 3>&1 1>&2 2>&3) || exit "Menu aborted." diff --git a/misc/build.func b/misc/build.func index aee3366a..15fd713e 100644 --- a/misc/build.func +++ b/misc/build.func @@ -1,3 +1,9 @@ +# Copyright (c) 2021-2024 tteck +# Author: tteck (tteckster) +# Revision 1.0 (MickLesk 12/2024) +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + variables() { NSAPP=$(echo ${APP,,} | tr -d ' ') # This function sets the NSAPP variable by converting the value of the APP variable to lowercase and removing any spaces. var_install="${NSAPP}-install" # sets the var_install variable by appending "-install" to the value of NSAPP. @@ -6,6 +12,7 @@ variables() { # This function sets various color variables using ANSI escape codes for formatting text in the terminal. color() { + # Colors YW=$(echo "\033[33m") YWB=$(echo "\033[93m") BL=$(echo "\033[36m") @@ -13,11 +20,39 @@ color() { BGN=$(echo "\033[4;92m") GN=$(echo "\033[1;92m") DGN=$(echo "\033[32m") + + # Formatting CL=$(echo "\033[m") - CM="${GN}✓${CL}" - CROSS="${RD}✗${CL}" + UL=$(echo "\033[4m") + BOLD=$(echo "\033[1m") BFR="\\r\\033[K" HOLD=" " + TAB=" " + + # Icons + CM="${TAB}✔️${TAB}${CL}" + CROSS="${TAB}✖️${TAB}${CL}" + INFO="${TAB}💡${TAB}${CL}" + OS="${TAB}🖥️${TAB}${CL}" + OSVERSION="${TAB}🌟${TAB}${CL}" + CONTAINERTYPE="${TAB}📦${TAB}${CL}" + DISKSIZE="${TAB}💾${TAB}${CL}" + CPUCORE="${TAB}🧠${TAB}${CL}" + RAMSIZE="${TAB}🛠️${TAB}${CL}" + SEARCH="${TAB}🔍${TAB}${CL}" + VERIFYPW="${TAB}🔐${TAB}${CL}" + CONTAINERID="${TAB}🆔${TAB}${CL}" + HOSTNAME="${TAB}🏠${TAB}${CL}" + BRIDGE="${TAB}🌉${TAB}${CL}" + NETWORK="${TAB}📡${TAB}${CL}" + GATEWAY="${TAB}🌐${TAB}${CL}" + DISABLEIPV6="${TAB}🚫${TAB}${CL}" + DEFAULT="${TAB}⚙️${TAB}${CL}" + MACADDRESS="${TAB}🔗${TAB}${CL}" + VLANTAG="${TAB}🏷️${TAB}${CL}" + ROOTSSH="${TAB}🔑${TAB}${CL}" + CREATING="${TAB}🚀${TAB}${CL}" + ADVANCED="${TAB}🧩${TAB}${CL}" } # This function enables error handling in the script by setting options and defining a trap for the ERR signal. @@ -39,21 +74,26 @@ error_handler() { # This function displays a spinner. spinner() { - local chars="/-\|" + local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') local spin_i=0 - printf "\e[?25l" + local interval=0.1 + printf "\e[?25l" + + local color="${YWB}" + while true; do - printf "\r \e[36m%s\e[0m" "${chars:spin_i++%${#chars}:1}" - sleep 0.1 + printf "\r ${color}%s${CL}" "${frames[spin_i]}" + spin_i=$(( (spin_i + 1) % ${#frames[@]} )) + sleep "$interval" done } # This function displays an informational message with a yellow color. msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg} " - spinner & - SPINNER_PID=$! + local msg="$1" + echo -ne " ${TAB}${YW}${msg} " + spinner & + SPINNER_PID=$! } # This function displays a success message with a green color. @@ -61,7 +101,7 @@ msg_ok() { if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi printf "\e[?25h" local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" + echo -e "${BFR}${CM}${GN}${msg}${CL}" } # This function displays a error message with a red color. @@ -69,7 +109,7 @@ msg_error() { if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi printf "\e[?25h" local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" + echo -e "${BFR}${CROSS}${RD}${msg}${CL}" } # Check if the shell is using bash @@ -97,7 +137,7 @@ root_check() { # This function checks the version of Proxmox Virtual Environment (PVE) and exits if the version is not supported. pve_check() { if ! pveversion | grep -Eq "pve-manager/8.[1-3]"; then - msg_error "This version of Proxmox Virtual Environment is not supported" + msg_error "${CROSS}${RD}This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." sleep 2 @@ -108,19 +148,31 @@ fi # This function checks the system architecture and exits if it's not "amd64". arch_check() { if [ "$(dpkg --print-architecture)" != "amd64" ]; then - echo -e "\n ${CROSS} This script will not work with PiMox! \n" - echo -e "\n Visit https://github.com/asylumexp/Proxmox for ARM64 support. \n" + echo -e "\n ${INFO}${YWB}This script will not work with PiMox! \n" + echo -e "\n ${YWB}Visit https://github.com/asylumexp/Proxmox for ARM64 support. \n" echo -e "Exiting..." sleep 2 exit fi } +# This function sets the APP-Name into an ASCII Header in Slant, figlet needed on proxmox main node. +header_info() { + if ! command -v figlet &> /dev/null; then + apt-get install -y figlet &> /dev/null + fi + ascii_art=$(figlet -f slant "$APP") + clear + cat </dev/null 2>&1 && [ -n "${SSH_CLIENT:+x}" ]; then - if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH DETECTED" --yesno "It's advisable to utilize the Proxmox shell rather than SSH, as there may be potential complications with variable retrieval. Proceed using SSH?" 10 72; then - whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Proceed using SSH" "You've chosen to proceed using SSH. If any issues arise, please run the script in the Proxmox shell before creating a repository issue." 10 72 + if whiptail --backtitle "ProxmoxVE Community-Scripts" --defaultno --title "SSH DETECTED" --yesno "It's advisable to utilize the Proxmox shell rather than SSH, as there may be potential complications with variable retrieval. Proceed using SSH?" 10 72; then + whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox --title "Proceed using SSH" "You've chosen to proceed using SSH. If any issues arise, please run the script in the Proxmox shell before creating a repository issue." 10 72 else clear echo "Exiting due to SSH usage. Please consider using the Proxmox shell." @@ -129,52 +181,90 @@ ssh_check() { fi } +base_settings() { + # Default Settings + CT_TYPE="1" + DISK_SIZE="4" + CORE_COUNT="1" + RAM_SIZE="1024" + VERBOSE="no" + PW="" + CT_ID=$NEXTID + HN=$NSAPP + BRG="vmbr0" + NET="dhcp" + GATE="" + APT_CACHER="" + APT_CACHER_IP="" + DISABLEIP6="no" + MTU="" + SD="" + NS="" + MAC="" + VLAN="" + SSH="no" + TAGS="community-script;" + + # Changed From CT.sh + CT_TYPE=${var_unprivileged:-$CT_TYPE} + DISK_SIZE=${var_disk:-$DISK_SIZE} + CORE_COUNT=${var_cpu:-$CORE_COUNT} + RAM_SIZE=${var_ram:-$RAM_SIZE} + VERB=${var_verbose:-$VERBOSE} + TAGS="${TAGS}${var_tags:-}" + + # Since these 2 are only defined outside of default_settings function, we add a temporary fallback. TODO: To align everything, we should add these as constant variables (e.g. OSTYPE and OSVERSION), but that would currently require updating the default_settings function for all existing scripts + if [ -z "$var_os" ]; then + var_os="debian" + fi + if [ -z "$var_version" ]; then + var_version="12" + fi +} + # This function displays the default values for various settings. echo_default() { - echo -e "${DGN}Using Distribution: ${BGN}$var_os${CL}" - echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}" - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - echo -e "${DGN}Using Gateway IP Address: ${BGN}Default${CL}" - echo -e "${DGN}Using Apt-Cacher IP Address: ${BGN}Default${CL}" - echo -e "${DGN}Disable IPv6: ${BGN}No${CL}" - echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" + # Convert CT_TYPE to description + CT_TYPE_DESC="Privileged" + if [ "$CT_TYPE" -eq 1 ]; then + CT_TYPE_DESC="Unprivileged" + fi + + # Output the selected values with icons + echo -e "${OS}${BOLD}${DGN}Operating System: ${BGN}$var_os${CL}" + echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}" + echo -e "${CONTAINERTYPE}${BOLD}${DGN}Container Type: ${BGN}$CT_TYPE_DESC${CL}" + echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE}GB${CL}" + echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}${CORE_COUNT}${CL}" + echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE}MB${CL}" + # Include VERBOSE if enabled + if [ "$VERB" == "yes" ]; then + echo -e "${SEARCH}${BOLD}${DGN}Verbose Mode: ${BGN}Enabled${CL}" + fi + echo -e "${CREATING}${BOLD}${BL}Creating a ${APP} LXC using the above default settings${CL}" + echo -e " " } # This function is called when the user decides to exit the script. It clears the screen and displays an exit message. exit-script() { clear - echo -e "⚠ User exited script \n" + echo -e "${CROSS}${RD}User exited script${CL}\n" exit } # This function allows the user to configure advanced settings for the script. advanced_settings() { - whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Here is an instructional tip:" "To make a selection, use the Spacebar." 8 58 - whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Default distribution for $APP" "${var_os} ${var_version} \n \nIf the default Linux distribution is not adhered to, script support will be discontinued. \n" 10 58 + whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox --title "Here is an instructional tip:" "To make a selection, use the Spacebar." 8 58 + whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox --title "Default distribution for $APP" "${var_os} ${var_version} \n \nIf the default Linux distribution is not adhered to, script support will be discontinued. \n" 10 58 if [ "$var_os" != "alpine" ]; then var_os="" while [ -z "$var_os" ]; do - if var_os=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution:" 10 58 2 \ + if var_os=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution:" 10 58 2 \ "debian" "" OFF \ "ubuntu" "" OFF \ 3>&1 1>&2 2>&3); then if [ -n "$var_os" ]; then - echo -e "${DGN}Using Distribution: ${BGN}$var_os${CL}" + echo -e "${OS}${DGN}Using Distribution: ${BGN}$var_os${CL}" fi else exit-script @@ -185,12 +275,12 @@ advanced_settings() { if [ "$var_os" == "debian" ]; then var_version="" while [ -z "$var_version" ]; do - if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DEBIAN VERSION" --radiolist "Choose Version" 10 58 2 \ + if var_version=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "DEBIAN VERSION" --radiolist "Choose Version" 10 58 2 \ "11" "Bullseye" OFF \ "12" "Bookworm" OFF \ 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then - echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}" + echo -e "${OSVERSION}${DGN}Using $var_os Version: ${BGN}$var_version${CL}" fi else exit-script @@ -201,13 +291,14 @@ advanced_settings() { if [ "$var_os" == "ubuntu" ]; then var_version="" while [ -z "$var_version" ]; do - if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 3 \ + if var_version=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 3 \ "20.04" "Focal" OFF \ - "22.04" "Jammy" OFF \ - "24.04" "Noble" OFF \ - 3>&1 1>&2 2>&3); then + "22.04" "Jammy" OFF \ + "24.04" "Noble" OFF \ + "24.10" "Oracular" OFF \ + 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then - echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}" + echo -e "${OSVERSION}${DGN}Using $var_os Version: ${BGN}$var_version${CL}" fi else exit-script @@ -217,12 +308,12 @@ advanced_settings() { CT_TYPE="" while [ -z "$CT_TYPE" ]; do - if CT_TYPE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CONTAINER TYPE" --radiolist "Choose Type" 10 58 2 \ + if CT_TYPE=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "CONTAINER TYPE" --radiolist "Choose Type" 10 58 2 \ "1" "Unprivileged" OFF \ "0" "Privileged" OFF \ 3>&1 1>&2 2>&3); then if [ -n "$CT_TYPE" ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" + echo -e "${CONTAINERTYPE}${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" fi else exit-script @@ -230,17 +321,17 @@ advanced_settings() { done while true; do - if PW1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --passwordbox "\nSet Root Password (needed for root ssh access)" 9 58 --title "PASSWORD (leave blank for automatic login)" 3>&1 1>&2 2>&3); then + if PW1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --passwordbox "\nSet Root Password (needed for root ssh access)" 9 58 --title "PASSWORD (leave blank for automatic login)" 3>&1 1>&2 2>&3); then if [[ ! -z "$PW1" ]]; then if [[ "$PW1" == *" "* ]]; then whiptail --msgbox "Password cannot contain spaces. Please try again." 8 58 elif [ ${#PW1} -lt 5 ]; then whiptail --msgbox "Password must be at least 5 characters long. Please try again." 8 58 else - if PW2=$(whiptail --backtitle "Proxmox VE Helper Scripts" --passwordbox "\nVerify Root Password" 9 58 --title "PASSWORD VERIFICATION" 3>&1 1>&2 2>&3); then + if PW2=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --passwordbox "\nVerify Root Password" 9 58 --title "PASSWORD VERIFICATION" 3>&1 1>&2 2>&3); then if [[ "$PW1" == "$PW2" ]]; then PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}********${CL}" + echo -e "${VERIFYPW}${DGN}Using Root Password: ${BGN}********${CL}" break else whiptail --msgbox "Passwords do not match. Please try again." 8 58 @@ -252,7 +343,7 @@ advanced_settings() { else PW1="Automatic Login" PW="" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" + echo -e "${VERIFYPW}${DGN}Using Root Password: ${BGN}$PW1${CL}" break fi else @@ -261,89 +352,89 @@ advanced_settings() { done - if CT_ID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" 3>&1 1>&2 2>&3); then + if CT_ID=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" 3>&1 1>&2 2>&3); then if [ -z "$CT_ID" ]; then CT_ID="$NEXTID" - echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}" + echo -e "${CONTAINERID}${DGN}Using Container ID: ${BGN}$CT_ID${CL}" else - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" + echo -e "${CONTAINERID}${DGN}Container ID: ${BGN}$CT_ID${CL}" fi else exit fi - if CT_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" 3>&1 1>&2 2>&3); then + if CT_NAME=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" 3>&1 1>&2 2>&3); then if [ -z "$CT_NAME" ]; then HN="$NSAPP" else HN=$(echo ${CT_NAME,,} | tr -d ' ') fi - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" + echo -e "${HOSTNAME}${DGN}Using Hostname: ${BGN}$HN${CL}" else exit-script fi - if DISK_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" 3>&1 1>&2 2>&3); then + if DISK_SIZE=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" 3>&1 1>&2 2>&3); then if [ -z "$DISK_SIZE" ]; then DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" + echo -e "${DISKSIZE}${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" else if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE AN INTEGER NUMBER!${CL}" + echo -e "{INFO}${HOLD}${RD} DISK SIZE MUST BE AN INTEGER NUMBER!${CL}" advanced_settings fi - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" + echo -e "${DISKSIZE}${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" fi else exit-script fi - if CORE_COUNT=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" 3>&1 1>&2 2>&3); then + if CORE_COUNT=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" 3>&1 1>&2 2>&3); then if [ -z "$CORE_COUNT" ]; then CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" + echo -e "${CPUCORE}${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" else - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" + echo -e "${CPUCORE}${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" fi else exit-script fi - if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" 3>&1 1>&2 2>&3); then + if RAM_SIZE=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" 3>&1 1>&2 2>&3); then if [ -z "$RAM_SIZE" ]; then RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" + echo -e "${RAMSIZE}${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" else - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" + echo -e "${RAMSIZE}${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" fi else exit-script fi - if BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" 3>&1 1>&2 2>&3); then + if BRG=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" 3>&1 1>&2 2>&3); then if [ -z "$BRG" ]; then BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" + echo -e "${BRIDGE}${DGN}Using Bridge: ${BGN}$BRG${CL}" else - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" + echo -e "${BRIDGE}${DGN}Using Bridge: ${BGN}$BRG${CL}" fi else exit-script fi while true; do - NET=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Static IPv4 CIDR Address (/24)" 8 58 dhcp --title "IP ADDRESS" 3>&1 1>&2 2>&3) + NET=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a Static IPv4 CIDR Address (/24)" 8 58 dhcp --title "IP ADDRESS" 3>&1 1>&2 2>&3) exit_status=$? if [ $exit_status -eq 0 ]; then if [ "$NET" = "dhcp" ]; then - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" + echo -e "${NETWORK}${DGN}Using IP Address: ${BGN}$NET${CL}" break else if [[ "$NET" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}/([0-9]|[1-2][0-9]|3[0-2])$ ]]; then - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" + echo -e "${NETWORK}${DGN}Using IP Address: ${BGN}$NET${CL}" break else - whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "$NET is an invalid IPv4 CIDR address. Please enter a valid IPv4 CIDR address or 'dhcp'" 8 58 + whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox "$NET is an invalid IPv4 CIDR address. Please enter a valid IPv4 CIDR address or 'dhcp'" 8 58 fi fi else @@ -353,54 +444,54 @@ advanced_settings() { if [ "$NET" != "dhcp" ]; then while true; do - GATE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Enter gateway IP address" 8 58 --title "Gateway IP" 3>&1 1>&2 2>&3) + GATE1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Enter gateway IP address" 8 58 --title "Gateway IP" 3>&1 1>&2 2>&3) if [ -z "$GATE1" ]; then - whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Gateway IP address cannot be empty" 8 58 + whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox "Gateway IP address cannot be empty" 8 58 elif [[ ! "$GATE1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then - whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Invalid IP address format" 8 58 + whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox "Invalid IP address format" 8 58 else GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" + echo -e "${GATEWAY}${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" break fi done else GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}Default${CL}" + echo -e "${GATEWAY}${DGN}Using Gateway IP Address: ${BGN}Default${CL}" fi if [ "$var_os" == "alpine" ]; then APT_CACHER="" APT_CACHER_IP="" else - if APT_CACHER_IP=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set APT-Cacher IP (leave blank for default)" 8 58 --title "APT-Cacher IP" 3>&1 1>&2 2>&3); then + if APT_CACHER_IP=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set APT-Cacher IP (leave blank for default)" 8 58 --title "APT-Cacher IP" 3>&1 1>&2 2>&3); then APT_CACHER="${APT_CACHER_IP:+yes}" - echo -e "${DGN}Using APT-Cacher IP Address: ${BGN}${APT_CACHER_IP:-Default}${CL}" + echo -e "${NETWORK}${DGN}Using APT-Cacher IP Address: ${BGN}${APT_CACHER_IP:-Default}${CL}" else exit-script fi fi - if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then + if (whiptail --backtitle "ProxmoxVE Community-Scripts" --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then DISABLEIP6="yes" else DISABLEIP6="no" fi - echo -e "${DGN}Disable IPv6: ${BGN}$DISABLEIP6${CL}" + echo -e "${DISABLEIPV6}${DGN}Disable IPv6: ${BGN}$DISABLEIP6${CL}" - if MTU1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" 3>&1 1>&2 2>&3); then + if MTU1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" 3>&1 1>&2 2>&3); then if [ -z $MTU1 ]; then MTU1="Default" MTU="" else MTU=",mtu=$MTU1" fi - echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" + echo -e "${DEFAULT}${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" else exit-script fi - if SD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" 3>&1 1>&2 2>&3); then + if SD=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" 3>&1 1>&2 2>&3); then if [ -z $SD ]; then SX=Host SD="" @@ -408,72 +499,72 @@ advanced_settings() { SX=$SD SD="-searchdomain=$SD" fi - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" + echo -e "${SEARCH}${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" else exit-script fi - if NX=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" 3>&1 1>&2 2>&3); then + if NX=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" 3>&1 1>&2 2>&3); then if [ -z $NX ]; then NX=Host NS="" else NS="-nameserver=$NX" fi - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" + echo -e "${NETWORK}${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" else exit-script fi - if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" 3>&1 1>&2 2>&3); then + if MAC1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" 3>&1 1>&2 2>&3); then if [ -z $MAC1 ]; then MAC1="Default" MAC="" else MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" + echo -e "${MACADDRESS}${DGN}Using MAC Address: ${BGN}$MAC1${CL}" fi else exit-script fi - if VLAN1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" 3>&1 1>&2 2>&3); then + if VLAN1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" 3>&1 1>&2 2>&3); then if [ -z $VLAN1 ]; then VLAN1="Default" VLAN="" else VLAN=",tag=$VLAN1" fi - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" + echo -e "${VLANTAG}${DGN}Using Vlan: ${BGN}$VLAN1${CL}" else exit-script fi if [[ "$PW" == -password* ]]; then - if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then + if (whiptail --backtitle "ProxmoxVE Community-Scripts" --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then SSH="yes" else SSH="no" fi - echo -e "${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}" + echo -e "${ROOTSSH}${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}" else SSH="no" - echo -e "${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}" + echo -e "${ROOTSSH}${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}" fi - if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then + if (whiptail --backtitle "ProxmoxVE Community-Scripts" --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then VERB="yes" else VERB="no" fi - echo -e "${DGN}Enable Verbose Mode: ${BGN}$VERB${CL}" + echo -e "${SEARCH}${DGN}Enable Verbose Mode: ${BGN}$VERB${CL}" - if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" + if (whiptail --backtitle "ProxmoxVE Community-Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" 10 58); then + echo -e "${CREATING}${RD}Creating a ${APP} LXC using the above advanced settings${CL}" else clear header_info - echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${ADVANCED}${RD}Using Advanced Settings${CL}" advanced_settings fi } @@ -491,13 +582,14 @@ install_script() { NEXTID=$(pvesh get /cluster/nextid) timezone=$(cat /etc/timezone) header_info - if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then + if (whiptail --backtitle "ProxmoxVE Community-Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings + echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings${CL}" + base_settings + echo_default else header_info - echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings${CL}" advanced_settings fi } @@ -509,9 +601,14 @@ check_container_resources() { # Check whether the current RAM is less than the required RAM or the CPU cores are less than required if [[ "$current_ram" -lt "$var_ram" ]] || [[ "$current_cpu" -lt "$var_cpu" ]]; then - echo -e "\n⚠️${HOLD} ${GN}Required: ${var_cpu} CPU, ${var_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}" + echo -e "\n${INFO}${HOLD} ${GN}Required: ${var_cpu} CPU, ${var_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}" echo -e "${YWB}Please ensure that the ${APP} LXC is configured with at least ${var_cpu} vCPU and ${var_ram} MB RAM for the build process.${CL}\n" - exit 1 + read -r -p "${INFO}${HOLD} May cause data loss! ${INFO} Continue update with under-provisioned LXC? " prompt + # Check if the input is 'yes', otherwise exit with status 1 + if [[ ! ${prompt,,} =~ ^(yes)$ ]]; then + echo -e "${CROSS}${HOLD} ${YWB}Exiting based on user input.${CL}" + exit 1 + fi else echo -e "" fi @@ -524,11 +621,11 @@ check_container_storage() { usage=$(( 100 * used_size / total_size )) if (( usage > 80 )); then # Prompt the user for confirmation to continue - echo -e "⚠️${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}" + echo -e "${INFO}${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}" read -r -p "Continue anyway? " prompt # Check if the input is 'y' or 'yes', otherwise exit with status 1 if [[ ! ${prompt,,} =~ ^(y|yes)$ ]]; then - echo -e "❌${HOLD} ${YWB}Exiting based on user input.${CL}" + echo -e "${CROSS}${HOLD}${YWB}Exiting based on user input.${CL}" exit 1 fi fi @@ -536,9 +633,9 @@ check_container_storage() { start() { if command -v pveversion >/dev/null 2>&1; then - if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then + if ! (whiptail --backtitle "ProxmoxVE Community-Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then clear - echo -e "⚠ User exited script \n" + exit_script exit fi SPINNER_PID="" @@ -546,9 +643,9 @@ start() { fi if ! command -v pveversion >/dev/null 2>&1; then - if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC UPDATE" --yesno "Support/Update functions for ${APP} LXC. Proceed?" 10 58); then + if ! (whiptail --backtitle "ProxmoxVE Community-Scripts" --title "${APP} LXC UPDATE" --yesno "Support/Update functions for ${APP} LXC. Proceed?" 10 58); then clear - echo -e "⚠ User exited script \n" + exit_script exit fi SPINNER_PID="" @@ -591,7 +688,7 @@ build_container() { export PCT_OPTIONS=" -features $FEATURES -hostname $HN - -tags proxmox-helper-scripts + -tags $TAGS $SD $NS -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN$MTU @@ -661,8 +758,6 @@ EOF pct exec "$CTID" -- /bin/sh -c 'cat </etc/apk/repositories http://dl-cdn.alpinelinux.org/alpine/latest-stable/main http://dl-cdn.alpinelinux.org/alpine/latest-stable/community -#http://dl-cdn.alpinelinux.org/alpine/v3.19/main -#http://dl-cdn.alpinelinux.org/alpine/v3.19/community EOF' pct exec "$CTID" -- ash -c "apk add bash >/dev/null" fi @@ -711,4 +806,4 @@ EOF if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi -} +} \ No newline at end of file diff --git a/misc/install.func b/misc/install.func index 2a22e2ff..a7723e7c 100644 --- a/misc/install.func +++ b/misc/install.func @@ -1,18 +1,38 @@ +# Copyright (c) 2021-2024 tteck +# Author: tteck (tteckster) +# Revision 1.0 (MickLesk 12/2024) +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + # This function sets color variables for formatting output in the terminal color() { + # Colors YW=$(echo "\033[33m") + YWB=$(echo "\033[93m") BL=$(echo "\033[36m") RD=$(echo "\033[01;31m") - BGN=$(echo "\033[4;92m") GN=$(echo "\033[1;92m") - DGN=$(echo "\033[32m") + + # Formatting CL=$(echo "\033[m") + BFR="\\r\\033[K" + BOLD=$(echo "\033[1m") + TAB=" " + + # System RETRY_NUM=10 RETRY_EVERY=3 - CM="${GN}✓${CL}" - CROSS="${RD}✗${CL}" - BFR="\\r\\033[K" - HOLD=" " + + # Icons + CM="${TAB}✔️${TAB}${CL}" + CROSS="${TAB}✖️${TAB}${CL}" + INFO="${TAB}💡${TAB}${CL}" + NETWORK="${TAB}📡${TAB}${CL}" + OS="${TAB}🖥️${TAB}${CL}" + OSVERSION="${TAB}🌟${TAB}${CL}" + HOSTNAME="${TAB}🏠${TAB}${CL}" + GATEWAY="${TAB}🌐${TAB}${CL}" + DEFAULT="${TAB}⚙️${TAB}${CL}" } # This function enables IPv6 if it's not disabled and sets verbose mode if the global variable is set to "yes" @@ -49,30 +69,34 @@ error_handler() { # This function displays a spinner. spinner() { - local chars="/-\|" + local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') local spin_i=0 - printf "\e[?25l" + local interval=0.1 + printf "\e[?25l" + + local color="${YWB}" + while true; do - printf "\r \e[36m%s\e[0m" "${chars:spin_i++%${#chars}:1}" - sleep 0.1 + printf "\r ${color}%s${CL}" "${frames[spin_i]}" + spin_i=$(( (spin_i + 1) % ${#frames[@]} )) + sleep "$interval" done } # This function displays an informational message with a yellow color. msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg} " - spinner & - SPINNER_PID=$! + local msg="$1" + echo -ne " ${TAB}${YW}${msg} " + spinner & + SPINNER_PID=$! } - # This function displays a success message with a green color. msg_ok() { if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi printf "\e[?25h" local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" + echo -e "${BFR}${CM}${GN}${msg}${CL}" } # This function displays a error message with a red color. @@ -80,7 +104,7 @@ msg_error() { if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi printf "\e[?25h" local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" + echo -e "${BFR}${CROSS}${RD}${msg}${CL}" } # This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection @@ -102,7 +126,7 @@ setting_up_container() { done if [ "$(hostname -I)" = "" ]; then echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - echo -e " 🖧 Check Network Settings" + echo -e "${NETWORK}Check Network Settings" exit 1 fi rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED @@ -118,8 +142,10 @@ network_check() { ipv4_connected=false ipv6_connected=false sleep 1 + sysctl -w net.ipv6.conf.all.disable_ipv6=0 &>/dev/nul + sysctl -w net.ipv6.conf.default.disable_ipv6=0 &>/dev/nul # Check IPv4 connectivity - if ping -c 1 -W 1 1.1.1.1 &>/dev/null; then + if ping -c 1 -W 1 1.1.1.1 &>/dev/null || ping -c 1 -W 1 8.8.8.8 &>/dev/null || ping -c 1 -W 1 9.9.9.9 &>/dev/null; then msg_ok "IPv4 Internet Connected"; ipv4_connected=true else @@ -127,7 +153,7 @@ network_check() { fi # Check IPv6 connectivity - if ping6 -c 1 -W 1 2606:4700:4700::1111 &>/dev/null; then + if ping6 -c 1 -W 1 2606:4700:4700::1111 &>/dev/null || ping6 -c 1 -W 1 2001:4860:4860::8888 &>/dev/null || ping6 -c 1 -W 1 2620:fe::fe &>/dev/null; then msg_ok "IPv6 Internet Connected"; ipv6_connected=true else @@ -138,9 +164,9 @@ network_check() { if [[ $ipv4_connected == false && $ipv6_connected == false ]]; then read -r -p "No Internet detected,would you like to continue anyway? " prompt if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" + echo -e "${INFO}${RD}Expect Issues Without Internet${CL}" else - echo -e " 🖧 Check Network Settings" + echo -e "${NETWORK}Check Network Settings" exit 1 fi fi @@ -166,21 +192,57 @@ fi EOF chmod +x /usr/local/bin/apt-proxy-detect.sh fi - $STD apt-get update - $STD apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade - rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED + if grep -qEi "debian|ubuntu" /etc/os-release; then + $STD apt-get update + $STD apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade + # RPM-based systems + elif grep -qEi "fedora|centos|rocky|almalinux" /etc/os-release; then + $STD dnf -y upgrade + # openSUSE + elif grep -qEi "opensuse" /etc/os-release; then + $STD zypper -n update + else + msg_error "Unsupported OS detected!" + exit 1 + fi msg_ok "Updated Container OS" } # This function modifies the message of the day (motd) and SSH settings motd_ssh() { - echo "export TERM='xterm-256color'" >>/root/.bashrc - echo -e "$APPLICATION LXC provided by https://helper-scripts.com/\n" >/etc/motd - chmod -x /etc/update-motd.d/* - if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd + # Set terminal to 256-color mode if not already set + grep -qxF "export TERM='xterm-256color'" /root/.bashrc || echo "export TERM='xterm-256color'" >> /root/.bashrc + + # Get the current private IP address + IP=$(hostname -I | awk '{print $1}') # Private IP + + # Get OS information (Debian / Ubuntu) + if [ -f "/etc/os-release" ]; then + OS_NAME=$(grep ^NAME /etc/os-release | cut -d= -f2 | tr -d '"') + OS_VERSION=$(grep ^VERSION_ID /etc/os-release | cut -d= -f2 | tr -d '"') + elif [ -f "/etc/debian_version" ]; then + OS_NAME="Debian" + OS_VERSION=$(cat /etc/debian_version) fi + + # Set MOTD with application info, system details + MOTD_FILE="/etc/motd" + if [ -f "$MOTD_FILE" ]; then + # Start MOTD with application info and link + echo -e "\n${BOLD}${APPLICATION} LXC Container${CL}" > "$MOTD_FILE" + echo -e "${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| Project: ${GN}ProxmoxVE ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\n" >> "$MOTD_FILE" + + # Add system information with icons + echo -e "${TAB}${OS}${YW} OS: ${GN}${OS_NAME} ${OS_VERSION}${CL}" >> "$MOTD_FILE" + echo -e "${TAB}${OSVERSION}${YW} Version: ${GN}${OS_VERSION}${CL}" >> "$MOTD_FILE" + echo -e "${TAB}${HOSTNAME}${YW} Hostname: ${GN}$(hostname)${CL}" >> "$MOTD_FILE" + echo -e "${TAB}${INFO}${YW} IP Address: ${GN}${IP}${CL}" >> "$MOTD_FILE" + else + echo "MotD file does not exist!" >&2 + fi + + # Disable default MOTD scripts + chmod -x /etc/update-motd.d/* } # This function customizes the container by modifying the getty service and enabling auto-login for the root user From 4f521d4b287ab921b64ec22a0c80d301d88ff1ae Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:38:47 +0100 Subject: [PATCH 02/11] Change Author MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> --- ct/create_lxc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ct/create_lxc.sh b/ct/create_lxc.sh index 8457e4f7..a4cf0f33 100644 --- a/ct/create_lxc.sh +++ b/ct/create_lxc.sh @@ -2,7 +2,7 @@ # Copyright (c) 2021-2024 tteck # Author: tteck (tteckster) -# Revision 1.0 (MickLesk 12/2024) +# Co-Author: MickLesk # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE From d07274ce7b786c7c99eb4adffaf31154e832d1a4 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:42:15 +0100 Subject: [PATCH 03/11] Fix indentation / naming / echos --- ct/create_lxc.sh | 30 +++--- misc/build.func | 231 +++++++++++++++++++++++----------------------- misc/install.func | 58 +++++------- 3 files changed, 156 insertions(+), 163 deletions(-) diff --git a/ct/create_lxc.sh b/ct/create_lxc.sh index 8457e4f7..bc684e90 100644 --- a/ct/create_lxc.sh +++ b/ct/create_lxc.sh @@ -2,7 +2,7 @@ # Copyright (c) 2021-2024 tteck # Author: tteck (tteckster) -# Revision 1.0 (MickLesk 12/2024) +# Co-Author: MickLesk # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE @@ -49,26 +49,26 @@ function error_handler() { # This function displays a spinner. function spinner() { - local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') - local spin_i=0 - local interval=0.1 - printf "\e[?25l" + local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') + local spin_i=0 + local interval=0.1 + printf "\e[?25l" - local color="${YWB}" + local color="${YWB}" - while true; do - printf "\r ${color}%s${CL}" "${frames[spin_i]}" - spin_i=$(( (spin_i + 1) % ${#frames[@]} )) - sleep "$interval" - done + while true; do + printf "\r ${color}%s${CL}" "${frames[spin_i]}" + spin_i=$(( (spin_i + 1) % ${#frames[@]} )) + sleep "$interval" + done } # This function displays an informational message with a yellow color. function msg_info() { local msg="$1" - echo -ne " ${TAB}${YW}${msg} " - spinner & - SPINNER_PID=$! + echo -ne " ${TAB}${YW}${msg}" + spinner & + SPINNER_PID=$! } # This function displays a success message with a green color. @@ -137,7 +137,7 @@ function select_storage() { else local STORAGE while [ -z "${STORAGE:+x}" ]; do - STORAGE=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "Storage Pools" --radiolist \ + STORAGE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Storage Pools" --radiolist \ "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\nTo make a selection, use the Spacebar.\n" \ 16 $(($MSG_MAX_LENGTH + 23)) 6 \ "${MENU[@]}" 3>&1 1>&2 2>&3) || exit "Menu aborted." diff --git a/misc/build.func b/misc/build.func index 15fd713e..346cd65b 100644 --- a/misc/build.func +++ b/misc/build.func @@ -1,6 +1,6 @@ # Copyright (c) 2021-2024 tteck # Author: tteck (tteckster) -# Revision 1.0 (MickLesk 12/2024) +# Co-Author: MickLesk # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE @@ -74,26 +74,26 @@ error_handler() { # This function displays a spinner. spinner() { - local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') - local spin_i=0 - local interval=0.1 - printf "\e[?25l" + local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') + local spin_i=0 + local interval=0.1 + printf "\e[?25l" - local color="${YWB}" + local color="${YWB}" - while true; do - printf "\r ${color}%s${CL}" "${frames[spin_i]}" - spin_i=$(( (spin_i + 1) % ${#frames[@]} )) - sleep "$interval" - done + while true; do + printf "\r ${color}%s${CL}" "${frames[spin_i]}" + spin_i=$(( (spin_i + 1) % ${#frames[@]} )) + sleep "$interval" + done } # This function displays an informational message with a yellow color. msg_info() { - local msg="$1" - echo -ne " ${TAB}${YW}${msg} " - spinner & - SPINNER_PID=$! + local msg="$1" + echo -ne " ${TAB}${YW}${msg}" + spinner & + SPINNER_PID=$! } # This function displays a success message with a green color. @@ -158,21 +158,19 @@ arch_check() { # This function sets the APP-Name into an ASCII Header in Slant, figlet needed on proxmox main node. header_info() { - if ! command -v figlet &> /dev/null; then - apt-get install -y figlet &> /dev/null - fi - ascii_art=$(figlet -f slant "$APP") - clear - cat < /dev/null + ascii_art=$(figlet -f slant "$APP") + clear + cat </dev/null 2>&1 && [ -n "${SSH_CLIENT:+x}" ]; then - if whiptail --backtitle "ProxmoxVE Community-Scripts" --defaultno --title "SSH DETECTED" --yesno "It's advisable to utilize the Proxmox shell rather than SSH, as there may be potential complications with variable retrieval. Proceed using SSH?" 10 72; then - whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox --title "Proceed using SSH" "You've chosen to proceed using SSH. If any issues arise, please run the script in the Proxmox shell before creating a repository issue." 10 72 + if [ -n "${SSH_CLIENT:+x}" ]; then + if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH DETECTED" --yesno "It's advisable to utilize the Proxmox shell rather than SSH, as there may be potential complications with variable retrieval. Proceed using SSH?" 10 72; then + whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Proceed using SSH" "You've chosen to proceed using SSH. If any issues arise, please run the script in the Proxmox shell before creating a repository issue." 10 72 else clear echo "Exiting due to SSH usage. Please consider using the Proxmox shell." @@ -242,32 +240,39 @@ echo_default() { echo -e "${SEARCH}${BOLD}${DGN}Verbose Mode: ${BGN}Enabled${CL}" fi echo -e "${CREATING}${BOLD}${BL}Creating a ${APP} LXC using the above default settings${CL}" - echo -e " " + echo -e " " } # This function is called when the user decides to exit the script. It clears the screen and displays an exit message. -exit-script() { +exit_script() { clear echo -e "${CROSS}${RD}User exited script${CL}\n" + + # Stop any running spinner + if [ -n "$SPINNER_PID" ] && kill -0 "$SPINNER_PID" 2>/dev/null; then + kill "$SPINNER_PID" + wait "$SPINNER_PID" 2>/dev/null + fi + exit } # This function allows the user to configure advanced settings for the script. advanced_settings() { - whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox --title "Here is an instructional tip:" "To make a selection, use the Spacebar." 8 58 - whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox --title "Default distribution for $APP" "${var_os} ${var_version} \n \nIf the default Linux distribution is not adhered to, script support will be discontinued. \n" 10 58 + whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Here is an instructional tip:" "To make a selection, use the Spacebar." 8 58 + whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Default distribution for $APP" "${var_os} ${var_version} \n \nIf the default Linux distribution is not adhered to, script support will be discontinued. \n" 10 58 if [ "$var_os" != "alpine" ]; then var_os="" while [ -z "$var_os" ]; do - if var_os=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution:" 10 58 2 \ + if var_os=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution:" 10 58 2 \ "debian" "" OFF \ "ubuntu" "" OFF \ 3>&1 1>&2 2>&3); then if [ -n "$var_os" ]; then - echo -e "${OS}${DGN}Using Distribution: ${BGN}$var_os${CL}" + echo -e "${OS}${BOLD}${DGN}Operating System: ${BGN}$var_os${CL}" fi else - exit-script + exit_script fi done fi @@ -275,15 +280,15 @@ advanced_settings() { if [ "$var_os" == "debian" ]; then var_version="" while [ -z "$var_version" ]; do - if var_version=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "DEBIAN VERSION" --radiolist "Choose Version" 10 58 2 \ + if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DEBIAN VERSION" --radiolist "Choose Version" 10 58 2 \ "11" "Bullseye" OFF \ "12" "Bookworm" OFF \ 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then - echo -e "${OSVERSION}${DGN}Using $var_os Version: ${BGN}$var_version${CL}" + echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}" fi else - exit-script + exit_script fi done fi @@ -291,207 +296,207 @@ advanced_settings() { if [ "$var_os" == "ubuntu" ]; then var_version="" while [ -z "$var_version" ]; do - if var_version=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 3 \ + if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ "20.04" "Focal" OFF \ - "22.04" "Jammy" OFF \ - "24.04" "Noble" OFF \ - "24.10" "Oracular" OFF \ - 3>&1 1>&2 2>&3); then + "22.04" "Jammy" OFF \ + "24.04" "Noble" OFF \ + "24.10" "Oracular" OFF \ + 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then - echo -e "${OSVERSION}${DGN}Using $var_os Version: ${BGN}$var_version${CL}" + echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}" fi else - exit-script + exit_script fi done fi CT_TYPE="" while [ -z "$CT_TYPE" ]; do - if CT_TYPE=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --title "CONTAINER TYPE" --radiolist "Choose Type" 10 58 2 \ + if CT_TYPE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CONTAINER TYPE" --radiolist "Choose Type" 10 58 2 \ "1" "Unprivileged" OFF \ "0" "Privileged" OFF \ 3>&1 1>&2 2>&3); then if [ -n "$CT_TYPE" ]; then - echo -e "${CONTAINERTYPE}${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" + echo -e "${CONTAINERTYPE}${BOLD}${DGN}Container Type: ${BGN}$CT_TYPE_DESC${CL}" fi else - exit-script + exit_script fi done while true; do - if PW1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --passwordbox "\nSet Root Password (needed for root ssh access)" 9 58 --title "PASSWORD (leave blank for automatic login)" 3>&1 1>&2 2>&3); then + if PW1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --passwordbox "\nSet Root Password (needed for root ssh access)" 9 58 --title "PASSWORD (leave blank for automatic login)" 3>&1 1>&2 2>&3); then if [[ ! -z "$PW1" ]]; then if [[ "$PW1" == *" "* ]]; then whiptail --msgbox "Password cannot contain spaces. Please try again." 8 58 elif [ ${#PW1} -lt 5 ]; then whiptail --msgbox "Password must be at least 5 characters long. Please try again." 8 58 else - if PW2=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --passwordbox "\nVerify Root Password" 9 58 --title "PASSWORD VERIFICATION" 3>&1 1>&2 2>&3); then + if PW2=$(whiptail --backtitle "Proxmox VE Helper Scripts" --passwordbox "\nVerify Root Password" 9 58 --title "PASSWORD VERIFICATION" 3>&1 1>&2 2>&3); then if [[ "$PW1" == "$PW2" ]]; then PW="-password $PW1" - echo -e "${VERIFYPW}${DGN}Using Root Password: ${BGN}********${CL}" + echo -e "${VERIFYPW}${BOLD}${DGN}Root Password: ${BGN}********${CL}" break else whiptail --msgbox "Passwords do not match. Please try again." 8 58 fi else - exit-script + exit_script fi fi else PW1="Automatic Login" PW="" - echo -e "${VERIFYPW}${DGN}Using Root Password: ${BGN}$PW1${CL}" + echo -e "${VERIFYPW}${BOLD}${DGN}Root Password: ${BGN}$PW1${CL}" break fi else - exit-script + exit_script fi done - if CT_ID=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" 3>&1 1>&2 2>&3); then + if CT_ID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" 3>&1 1>&2 2>&3); then if [ -z "$CT_ID" ]; then CT_ID="$NEXTID" - echo -e "${CONTAINERID}${DGN}Using Container ID: ${BGN}$CT_ID${CL}" + echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}" else - echo -e "${CONTAINERID}${DGN}Container ID: ${BGN}$CT_ID${CL}" + echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}" fi else exit fi - if CT_NAME=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" 3>&1 1>&2 2>&3); then + if CT_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" 3>&1 1>&2 2>&3); then if [ -z "$CT_NAME" ]; then HN="$NSAPP" else HN=$(echo ${CT_NAME,,} | tr -d ' ') fi - echo -e "${HOSTNAME}${DGN}Using Hostname: ${BGN}$HN${CL}" + echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}" else - exit-script + exit_script fi - if DISK_SIZE=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" 3>&1 1>&2 2>&3); then + if DISK_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" 3>&1 1>&2 2>&3); then if [ -z "$DISK_SIZE" ]; then DISK_SIZE="$var_disk" - echo -e "${DISKSIZE}${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" + echo -e "${DISKSIZE}${DGN}Disk Size: ${BGN}$DISK_SIZE${CL}" else if ! [[ $DISK_SIZE =~ $INTEGER ]]; then echo -e "{INFO}${HOLD}${RD} DISK SIZE MUST BE AN INTEGER NUMBER!${CL}" advanced_settings fi - echo -e "${DISKSIZE}${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" + echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}$DISK_SIZE${CL}" fi else - exit-script + exit_script fi - if CORE_COUNT=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" 3>&1 1>&2 2>&3); then + if CORE_COUNT=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" 3>&1 1>&2 2>&3); then if [ -z "$CORE_COUNT" ]; then CORE_COUNT="$var_cpu" - echo -e "${CPUCORE}${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" + echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}$CORE_COUNT${CL}" else - echo -e "${CPUCORE}${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" + echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}$CORE_COUNT${CL}" fi else - exit-script + exit_script fi - if RAM_SIZE=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" 3>&1 1>&2 2>&3); then + if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" 3>&1 1>&2 2>&3); then if [ -z "$RAM_SIZE" ]; then RAM_SIZE="$var_ram" - echo -e "${RAMSIZE}${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" + echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}$RAM_SIZE${CL}" else - echo -e "${RAMSIZE}${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" + echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}$RAM_SIZE${CL}" fi else - exit-script + exit_script fi - if BRG=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" 3>&1 1>&2 2>&3); then + if BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" 3>&1 1>&2 2>&3); then if [ -z "$BRG" ]; then BRG="vmbr0" - echo -e "${BRIDGE}${DGN}Using Bridge: ${BGN}$BRG${CL}" + echo -e "${BRIDGE}${BOLD}${DGN}Bridge: ${BGN}$BRG${CL}" else - echo -e "${BRIDGE}${DGN}Using Bridge: ${BGN}$BRG${CL}" + echo -e "${BRIDGE}${BOLD}${DGN}Bridge: ${BGN}$BRG${CL}" fi else - exit-script + exit_script fi while true; do - NET=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a Static IPv4 CIDR Address (/24)" 8 58 dhcp --title "IP ADDRESS" 3>&1 1>&2 2>&3) + NET=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Static IPv4 CIDR Address (/24)" 8 58 dhcp --title "IP ADDRESS" 3>&1 1>&2 2>&3) exit_status=$? if [ $exit_status -eq 0 ]; then if [ "$NET" = "dhcp" ]; then - echo -e "${NETWORK}${DGN}Using IP Address: ${BGN}$NET${CL}" + echo -e "${NETWORK}${BOLD}${DGN}IP Address: ${BGN}$NET${CL}" break else if [[ "$NET" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}/([0-9]|[1-2][0-9]|3[0-2])$ ]]; then - echo -e "${NETWORK}${DGN}Using IP Address: ${BGN}$NET${CL}" + echo -e "${NETWORK}${BOLD}${DGN}IP Address: ${BGN}$NET${CL}" break else - whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox "$NET is an invalid IPv4 CIDR address. Please enter a valid IPv4 CIDR address or 'dhcp'" 8 58 + whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "$NET is an invalid IPv4 CIDR address. Please enter a valid IPv4 CIDR address or 'dhcp'" 8 58 fi fi else - exit-script + exit_script fi done if [ "$NET" != "dhcp" ]; then while true; do - GATE1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Enter gateway IP address" 8 58 --title "Gateway IP" 3>&1 1>&2 2>&3) + GATE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Enter gateway IP address" 8 58 --title "Gateway IP" 3>&1 1>&2 2>&3) if [ -z "$GATE1" ]; then - whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox "Gateway IP address cannot be empty" 8 58 + whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Gateway IP address cannot be empty" 8 58 elif [[ ! "$GATE1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then - whiptail --backtitle "ProxmoxVE Community-Scripts" --msgbox "Invalid IP address format" 8 58 + whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Invalid IP address format" 8 58 else GATE=",gw=$GATE1" - echo -e "${GATEWAY}${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" + echo -e "${GATEWAY}${BOLD}${DGN}Gateway IP Address: ${BGN}$GATE1${CL}" break fi done else GATE="" - echo -e "${GATEWAY}${DGN}Using Gateway IP Address: ${BGN}Default${CL}" + echo -e "${GATEWAY}${BOLD}${DGN}Gateway IP Address: ${BGN}Default${CL}" fi if [ "$var_os" == "alpine" ]; then APT_CACHER="" APT_CACHER_IP="" else - if APT_CACHER_IP=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set APT-Cacher IP (leave blank for default)" 8 58 --title "APT-Cacher IP" 3>&1 1>&2 2>&3); then + if APT_CACHER_IP=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set APT-Cacher IP (leave blank for default)" 8 58 --title "APT-Cacher IP" 3>&1 1>&2 2>&3); then APT_CACHER="${APT_CACHER_IP:+yes}" - echo -e "${NETWORK}${DGN}Using APT-Cacher IP Address: ${BGN}${APT_CACHER_IP:-Default}${CL}" + echo -e "${NETWORK}${BOLD}${DGN}APT-Cacher IP Address: ${BGN}${APT_CACHER_IP:-Default}${CL}" else - exit-script + exit_script fi fi - if (whiptail --backtitle "ProxmoxVE Community-Scripts" --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then + if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then DISABLEIP6="yes" else DISABLEIP6="no" fi - echo -e "${DISABLEIPV6}${DGN}Disable IPv6: ${BGN}$DISABLEIP6${CL}" + echo -e "${DISABLEIPV6}${BOLD}${DGN}Disable IPv6: ${BGN}$DISABLEIP6${CL}" - if MTU1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" 3>&1 1>&2 2>&3); then + if MTU1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" 3>&1 1>&2 2>&3); then if [ -z $MTU1 ]; then MTU1="Default" MTU="" else MTU=",mtu=$MTU1" fi - echo -e "${DEFAULT}${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" + echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU Size: ${BGN}$MTU1${CL}" else - exit-script + exit_script fi - if SD=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" 3>&1 1>&2 2>&3); then + if SD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" 3>&1 1>&2 2>&3); then if [ -z $SD ]; then SX=Host SD="" @@ -499,72 +504,72 @@ advanced_settings() { SX=$SD SD="-searchdomain=$SD" fi - echo -e "${SEARCH}${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" + echo -e "${SEARCH}${BOLD}${DGN}DNS Search Domain: ${BGN}$SX${CL}" else - exit-script + exit_script fi - if NX=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" 3>&1 1>&2 2>&3); then + if NX=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" 3>&1 1>&2 2>&3); then if [ -z $NX ]; then NX=Host NS="" else NS="-nameserver=$NX" fi - echo -e "${NETWORK}${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" + echo -e "${NETWORK}${BOLD}${DGN}DNS Server IP Address: ${BGN}$NX${CL}" else - exit-script + exit_script fi - if MAC1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" 3>&1 1>&2 2>&3); then + if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" 3>&1 1>&2 2>&3); then if [ -z $MAC1 ]; then MAC1="Default" MAC="" else MAC=",hwaddr=$MAC1" - echo -e "${MACADDRESS}${DGN}Using MAC Address: ${BGN}$MAC1${CL}" + echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}$MAC1${CL}" fi else - exit-script + exit_script fi - if VLAN1=$(whiptail --backtitle "ProxmoxVE Community-Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" 3>&1 1>&2 2>&3); then + if VLAN1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" 3>&1 1>&2 2>&3); then if [ -z $VLAN1 ]; then VLAN1="Default" VLAN="" else VLAN=",tag=$VLAN1" fi - echo -e "${VLANTAG}${DGN}Using Vlan: ${BGN}$VLAN1${CL}" + echo -e "${VLANTAG}${BOLD}${DGN}Vlan: ${BGN}$VLAN1${CL}" else - exit-script + exit_script fi if [[ "$PW" == -password* ]]; then - if (whiptail --backtitle "ProxmoxVE Community-Scripts" --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then + if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then SSH="yes" else SSH="no" fi - echo -e "${ROOTSSH}${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}" + echo -e "${ROOTSSH}${BOLD}${DGN}Root SSH Access: ${BGN}$SSH${CL}" else SSH="no" - echo -e "${ROOTSSH}${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}" + echo -e "${ROOTSSH}${BOLD}${DGN}Root SSH Access: ${BGN}$SSH${CL}" fi - if (whiptail --backtitle "ProxmoxVE Community-Scripts" --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then + if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then VERB="yes" else VERB="no" fi echo -e "${SEARCH}${DGN}Enable Verbose Mode: ${BGN}$VERB${CL}" - if (whiptail --backtitle "ProxmoxVE Community-Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" 10 58); then - echo -e "${CREATING}${RD}Creating a ${APP} LXC using the above advanced settings${CL}" + if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" 10 58); then + echo -e "${CREATING}${BOLD}${RD}Creating a ${APP} LXC using the above advanced settings${CL}" else clear header_info - echo -e "${ADVANCED}${RD}Using Advanced Settings${CL}" + echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings${CL}" advanced_settings fi } @@ -582,10 +587,10 @@ install_script() { NEXTID=$(pvesh get /cluster/nextid) timezone=$(cat /etc/timezone) header_info - if (whiptail --backtitle "ProxmoxVE Community-Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then + if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then header_info echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings${CL}" - base_settings + base_settings echo_default else header_info @@ -633,7 +638,7 @@ check_container_storage() { start() { if command -v pveversion >/dev/null 2>&1; then - if ! (whiptail --backtitle "ProxmoxVE Community-Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then + if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then clear exit_script exit @@ -643,7 +648,7 @@ start() { fi if ! command -v pveversion >/dev/null 2>&1; then - if ! (whiptail --backtitle "ProxmoxVE Community-Scripts" --title "${APP} LXC UPDATE" --yesno "Support/Update functions for ${APP} LXC. Proceed?" 10 58); then + if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC UPDATE" --yesno "Support/Update functions for ${APP} LXC. Proceed?" 10 58); then clear exit_script exit diff --git a/misc/install.func b/misc/install.func index a7723e7c..da86c75e 100644 --- a/misc/install.func +++ b/misc/install.func @@ -1,6 +1,6 @@ # Copyright (c) 2021-2024 tteck # Author: tteck (tteckster) -# Revision 1.0 (MickLesk 12/2024) +# Co-Author: MickLesk # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE @@ -16,7 +16,7 @@ color() { # Formatting CL=$(echo "\033[m") BFR="\\r\\033[K" - BOLD=$(echo "\033[1m") + BOLD=$(echo "\033[1m") TAB=" " # System @@ -27,12 +27,12 @@ color() { CM="${TAB}✔️${TAB}${CL}" CROSS="${TAB}✖️${TAB}${CL}" INFO="${TAB}💡${TAB}${CL}" - NETWORK="${TAB}📡${TAB}${CL}" + NETWORK="${TAB}📡${TAB}${CL}" OS="${TAB}🖥️${TAB}${CL}" OSVERSION="${TAB}🌟${TAB}${CL}" HOSTNAME="${TAB}🏠${TAB}${CL}" GATEWAY="${TAB}🌐${TAB}${CL}" - DEFAULT="${TAB}⚙️${TAB}${CL}" + DEFAULT="${TAB}⚙️${TAB}${CL}" } # This function enables IPv6 if it's not disabled and sets verbose mode if the global variable is set to "yes" @@ -69,26 +69,26 @@ error_handler() { # This function displays a spinner. spinner() { - local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') - local spin_i=0 - local interval=0.1 - printf "\e[?25l" + local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') + local spin_i=0 + local interval=0.1 + printf "\e[?25l" - local color="${YWB}" + local color="${YWB}" - while true; do - printf "\r ${color}%s${CL}" "${frames[spin_i]}" - spin_i=$(( (spin_i + 1) % ${#frames[@]} )) - sleep "$interval" - done + while true; do + printf "\r ${color}%s${CL}" "${frames[spin_i]}" + spin_i=$(( (spin_i + 1) % ${#frames[@]} )) + sleep "$interval" + done } # This function displays an informational message with a yellow color. msg_info() { - local msg="$1" - echo -ne " ${TAB}${YW}${msg} " - spinner & - SPINNER_PID=$! + local msg="$1" + echo -ne " ${TAB}${YW}${msg}" + spinner & + SPINNER_PID=$! } # This function displays a success message with a green color. @@ -142,8 +142,6 @@ network_check() { ipv4_connected=false ipv6_connected=false sleep 1 - sysctl -w net.ipv6.conf.all.disable_ipv6=0 &>/dev/nul - sysctl -w net.ipv6.conf.default.disable_ipv6=0 &>/dev/nul # Check IPv4 connectivity if ping -c 1 -W 1 1.1.1.1 &>/dev/null || ping -c 1 -W 1 8.8.8.8 &>/dev/null || ping -c 1 -W 1 9.9.9.9 &>/dev/null; then msg_ok "IPv4 Internet Connected"; @@ -192,26 +190,16 @@ fi EOF chmod +x /usr/local/bin/apt-proxy-detect.sh fi - if grep -qEi "debian|ubuntu" /etc/os-release; then - $STD apt-get update - $STD apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade - # RPM-based systems - elif grep -qEi "fedora|centos|rocky|almalinux" /etc/os-release; then - $STD dnf -y upgrade - # openSUSE - elif grep -qEi "opensuse" /etc/os-release; then - $STD zypper -n update - else - msg_error "Unsupported OS detected!" - exit 1 - fi + $STD apt-get update + $STD apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade + rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED msg_ok "Updated Container OS" } # This function modifies the message of the day (motd) and SSH settings motd_ssh() { - # Set terminal to 256-color mode if not already set - grep -qxF "export TERM='xterm-256color'" /root/.bashrc || echo "export TERM='xterm-256color'" >> /root/.bashrc + # Set terminal to 256-color mode + echo "export TERM='xterm-256color'" >>/root/.bashrc # Get the current private IP address IP=$(hostname -I | awk '{print $1}') # Private IP From addb48bd52f43f04201df7071c7c3dd829712b57 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:20:23 +0100 Subject: [PATCH 04/11] Fix some Parts --- misc/build.func | 18 ++++++++++-------- misc/install.func | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/misc/build.func b/misc/build.func index 346cd65b..ba177f93 100644 --- a/misc/build.func +++ b/misc/build.func @@ -235,6 +235,7 @@ echo_default() { echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE}GB${CL}" echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}${CORE_COUNT}${CL}" echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE}MB${CL}" + echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}${CT_ID}${CL}" # Include VERBOSE if enabled if [ "$VERB" == "yes" ]; then echo -e "${SEARCH}${BOLD}${DGN}Verbose Mode: ${BGN}Enabled${CL}" @@ -246,14 +247,8 @@ echo_default() { # This function is called when the user decides to exit the script. It clears the screen and displays an exit message. exit_script() { clear + echo -e "\n" echo -e "${CROSS}${RD}User exited script${CL}\n" - - # Stop any running spinner - if [ -n "$SPINNER_PID" ] && kill -0 "$SPINNER_PID" 2>/dev/null; then - kill "$SPINNER_PID" - wait "$SPINNER_PID" 2>/dev/null - fi - exit } @@ -311,6 +306,9 @@ advanced_settings() { done fi + # Setting Default Tag for Advanced Settings + TAGS="community-script;" + CT_TYPE="" while [ -z "$CT_TYPE" ]; do if CT_TYPE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CONTAINER TYPE" --radiolist "Choose Type" 10 58 2 \ @@ -318,6 +316,10 @@ advanced_settings() { "0" "Privileged" OFF \ 3>&1 1>&2 2>&3); then if [ -n "$CT_TYPE" ]; then + CT_TYPE_DESC="Privileged" + if [ "$CT_TYPE" -eq 1 ]; then + CT_TYPE_DESC="Unprivileged" + fi echo -e "${CONTAINERTYPE}${BOLD}${DGN}Container Type: ${BGN}$CT_TYPE_DESC${CL}" fi else @@ -562,7 +564,7 @@ advanced_settings() { else VERB="no" fi - echo -e "${SEARCH}${DGN}Enable Verbose Mode: ${BGN}$VERB${CL}" + echo -e "${SEARCH}${BOLD}${DGN}Verbose Mode: ${BGN}$VERB${CL}" if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" 10 58); then echo -e "${CREATING}${BOLD}${RD}Creating a ${APP} LXC using the above advanced settings${CL}" diff --git a/misc/install.func b/misc/install.func index da86c75e..01c31c81 100644 --- a/misc/install.func +++ b/misc/install.func @@ -199,7 +199,7 @@ EOF # This function modifies the message of the day (motd) and SSH settings motd_ssh() { # Set terminal to 256-color mode - echo "export TERM='xterm-256color'" >>/root/.bashrc + grep -qxF "export TERM='xterm-256color'" /root/.bashrc || echo "export TERM='xterm-256color'" >> /root/.bashrc # Get the current private IP address IP=$(hostname -I | awk '{print $1}') # Private IP From 852ab6065f5117d228a5a5b6cba63dff562735a8 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:03:41 +0100 Subject: [PATCH 05/11] Add alpine-install.func --- misc/alpine-install.func | 88 +++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 175b8ca7..56743adf 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -1,20 +1,42 @@ +# Copyright (c) 2021-2024 tteck +# Author: tteck (tteckster) +# Co-Author: MickLesk +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + +# This function sets color variables for formatting output in the terminal color() { + # Colors YW=$(echo "\033[33m") + YWB=$(echo "\033[93m") BL=$(echo "\033[36m") RD=$(echo "\033[01;31m") - BGN=$(echo "\033[4;92m") GN=$(echo "\033[1;92m") - DGN=$(echo "\033[32m") + + # Formatting CL=$(echo "\033[m") + BFR="\\r\\033[K" + BOLD=$(echo "\033[1m") + TAB=" " + + # System RETRY_NUM=10 RETRY_EVERY=3 i=$RETRY_NUM - CM="${GN}✓${CL}" - CROSS="${RD}✗${CL}" - BFR="\\r\\033[K" - HOLD="-" + + # Icons + CM="${TAB}✔️${TAB}${CL}" + CROSS="${TAB}✖️${TAB}${CL}" + INFO="${TAB}💡${TAB}${CL}" + NETWORK="${TAB}📡${TAB}${CL}" + OS="${TAB}🖥️${TAB}${CL}" + OSVERSION="${TAB}🌟${TAB}${CL}" + HOSTNAME="${TAB}🏠${TAB}${CL}" + GATEWAY="${TAB}🌐${TAB}${CL}" + DEFAULT="${TAB}⚙️${TAB}${CL}" } +# This function enables IPv6 if it's not disabled and sets verbose mode if the global variable is set to "yes" verb_ip6() { if [ "$VERBOSE" = "yes" ]; then STD="" @@ -27,11 +49,13 @@ verb_ip6() { fi } +# This function sets error handling options and defines the error_handler function to handle errors catch_errors() { set -Eeuo pipefail trap 'error_handler $LINENO "$BASH_COMMAND"' ERR } +# This function handles errors error_handler() { local exit_code="$?" local line_number="$1" @@ -40,21 +64,25 @@ error_handler() { echo -e "\n$error_message\n" } +# This function displays an informational message with a yellow color. msg_info() { local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." + echo -ne " ${TAB}${YW}${msg}" } +# This function displays a success message with a green color. msg_ok() { local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" + echo -e "${BFR}${CM}${GN}${msg}${CL}" } +# This function displays a error message with a red color. msg_error() { local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" + echo -e "${BFR}${CROSS}${RD}${msg}${CL}" } +# This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection setting_up_container() { msg_info "Setting up Container OS" while [ $i -gt 0 ]; do @@ -68,23 +96,26 @@ setting_up_container() { if [ "$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d'/' -f1)" = "" ]; then echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - echo -e " 🖧 Check Network Settings" + echo -e "${NETWORK}Check Network Settings" exit 1 fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(ip addr show | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1 | tail -n1)${CL}" } +# This function checks the network connection by pinging a known IP address and prompts the user to continue if the internet is not connected network_check() { set +e trap - ERR - if ping -c 1 -W 1 1.1.1.1 &>/dev/null; then msg_ok "Internet Connected"; else + if ping -c 1 -W 1 1.1.1.1 &>/dev/null || ping -c 1 -W 1 8.8.8.8 &>/dev/null || ping -c 1 -W 1 9.9.9.9 &>/dev/null; then + msg_ok "Internet Connected"; + else msg_error "Internet NOT Connected" read -r -p "Would you like to continue anyway? " prompt if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" + echo -e "${INFO}${RD}Expect Issues Without Internet${CL}" else - echo -e " 🖧 Check Network Settings" + echo -e "${NETWORK}Check Network Settings" exit 1 fi fi @@ -94,6 +125,7 @@ network_check() { trap 'error_handler $LINENO "$BASH_COMMAND"' ERR } +# This function updates the Container OS by running apt-get update and upgrade update_os() { msg_info "Updating Container OS" $STD apk update @@ -101,20 +133,46 @@ update_os() { msg_ok "Updated Container OS" } +# This function modifies the message of the day (motd) and SSH settings motd_ssh() { + # Set terminal to 256-color mode echo "export TERM='xterm-256color'" >>/root/.bashrc - echo -e "$APPLICATION LXC provided by https://Helper-Scripts.com/\n" >/etc/motd + IP=$(ip -4 addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 | head -n 1) + # Get OS information + if [ -f "/etc/os-release" ]; then + OS_NAME=$(grep ^NAME /etc/os-release | cut -d= -f2 | tr -d '"') + OS_VERSION=$(grep ^VERSION_ID /etc/os-release | cut -d= -f2 | tr -d '"') + else + OS_NAME="Alpine Linux" + OS_VERSION="Unknown" + fi + # Set MOTD with application info and system details + MOTD_FILE="/etc/motd" + if [ -f "$MOTD_FILE" ]; then + echo -e "\n${BOLD}${APPLICATION} LXC Container${CL}" > "$MOTD_FILE" + echo -e "${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| Project: ${GN}ProxmoxVE ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\n" >> "$MOTD_FILE" + echo -e "${TAB}${OS}${YW} OS: ${GN}${OS_NAME} ${OS_VERSION}${CL}" >> "$MOTD_FILE" + echo -e "${TAB}${HOSTNAME}${YW} Hostname: ${GN}$(hostname)${CL}" >> "$MOTD_FILE" + echo -e "${TAB}${INFO}${YW} IP Address: ${GN}${IP}${CL}" >> "$MOTD_FILE" + else + echo -e "${RD}[WARNING] MOTD file does not exist!${CL}" >&2 + fi + # Configure SSH if enabled if [[ "${SSH_ROOT}" == "yes" ]]; then + # Enable sshd service $STD rc-update add sshd + # Allow root login via SSH sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config + # Start the sshd service $STD /etc/init.d/sshd start fi } +# This function customizes the container and enabling the passwordless login for the root user customize() { if [[ "$PASSWORD" == "" ]]; then msg_info "Customizing Container" bash -c "passwd -d root" >/dev/null 2>&1 msg_ok "Customized Container" fi -} +} \ No newline at end of file From 11e1768e78e5b019640dd1babc80a70caaaa4d18 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:05:49 +0100 Subject: [PATCH 06/11] update alpine to 3.20 --- ct/alpine.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ct/alpine.sh b/ct/alpine.sh index d6944dc0..5d8fab53 100644 --- a/ct/alpine.sh +++ b/ct/alpine.sh @@ -24,7 +24,7 @@ var_disk="0.1" var_cpu="1" var_ram="512" var_os="alpine" -var_version="3.19" +var_version="3.20" variables color catch_errors From 30bf69c5e569600192c20eeb02dbc6394edb3be1 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 5 Dec 2024 09:29:44 +0100 Subject: [PATCH 07/11] fix spaces --- ct/create_lxc.sh | 4 ++-- misc/alpine-install.func | 4 ++-- misc/install.func | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ct/create_lxc.sh b/ct/create_lxc.sh index bc684e90..a479a365 100644 --- a/ct/create_lxc.sh +++ b/ct/create_lxc.sh @@ -66,7 +66,7 @@ function spinner() { # This function displays an informational message with a yellow color. function msg_info() { local msg="$1" - echo -ne " ${TAB}${YW}${msg}" + echo -ne "${TAB}${YW}${msg}" spinner & SPINNER_PID=$! } @@ -123,7 +123,7 @@ function select_storage() { local TAG=$(echo $line | awk '{print $1}') local TYPE=$(echo $line | awk '{printf "%-10s", $2}') local FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}') - local ITEM=" Type: $TYPE Free: $FREE " + local ITEM="Type: $TYPE Free: $FREE " local OFFSET=2 if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 56743adf..e8244baa 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -49,7 +49,7 @@ verb_ip6() { fi } -# This function sets error handling options and defines the error_handler function to handle errors +# This function catches errors and handles them with the error handler function catch_errors() { set -Eeuo pipefail trap 'error_handler $LINENO "$BASH_COMMAND"' ERR @@ -168,7 +168,7 @@ motd_ssh() { fi } -# This function customizes the container and enabling the passwordless login for the root user +# This function customizes the container and enables passwordless login for the root user customize() { if [[ "$PASSWORD" == "" ]]; then msg_info "Customizing Container" diff --git a/misc/install.func b/misc/install.func index 01c31c81..e157d1cb 100644 --- a/misc/install.func +++ b/misc/install.func @@ -86,8 +86,8 @@ spinner() { # This function displays an informational message with a yellow color. msg_info() { local msg="$1" - echo -ne " ${TAB}${YW}${msg}" - spinner & + echo -ne "${TAB}${YW}${msg}" + spinner & SPINNER_PID=$! } @@ -142,7 +142,7 @@ network_check() { ipv4_connected=false ipv6_connected=false sleep 1 -# Check IPv4 connectivity +# Check IPv4 connectivity to Google, Cloudflare & Quad9 DNS servers. if ping -c 1 -W 1 1.1.1.1 &>/dev/null || ping -c 1 -W 1 8.8.8.8 &>/dev/null || ping -c 1 -W 1 9.9.9.9 &>/dev/null; then msg_ok "IPv4 Internet Connected"; ipv4_connected=true @@ -150,7 +150,7 @@ network_check() { msg_error "IPv4 Internet Not Connected"; fi -# Check IPv6 connectivity +# Check IPv6 connectivity to Google, Cloudflare & Quad9 DNS servers. if ping6 -c 1 -W 1 2606:4700:4700::1111 &>/dev/null || ping6 -c 1 -W 1 2001:4860:4860::8888 &>/dev/null || ping6 -c 1 -W 1 2620:fe::fe &>/dev/null; then msg_ok "IPv6 Internet Connected"; ipv6_connected=true From 945d55f4234b8d669a6f7170ceab6ef87d2a726b Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:21:47 +0100 Subject: [PATCH 08/11] Update build.func --- misc/build.func | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/misc/build.func b/misc/build.func index ba177f93..28551a1b 100644 --- a/misc/build.func +++ b/misc/build.func @@ -91,7 +91,7 @@ spinner() { # This function displays an informational message with a yellow color. msg_info() { local msg="$1" - echo -ne " ${TAB}${YW}${msg}" + echo -ne "${TAB}${YW}${msg}" spinner & SPINNER_PID=$! } @@ -203,8 +203,8 @@ base_settings() { SSH="no" TAGS="community-script;" - # Changed From CT.sh - CT_TYPE=${var_unprivileged:-$CT_TYPE} + # Override default settings with variables from ct script + CT_TYPE=${var_privileged:-$CT_TYPE} DISK_SIZE=${var_disk:-$DISK_SIZE} CORE_COUNT=${var_cpu:-$CORE_COUNT} RAM_SIZE=${var_ram:-$RAM_SIZE} @@ -223,9 +223,9 @@ base_settings() { # This function displays the default values for various settings. echo_default() { # Convert CT_TYPE to description - CT_TYPE_DESC="Privileged" - if [ "$CT_TYPE" -eq 1 ]; then - CT_TYPE_DESC="Unprivileged" + CT_TYPE_DESC="Unprivileged" + if [ "$CT_TYPE" -eq 0 ]; then + CT_TYPE_DESC="Privileged" fi # Output the selected values with icons @@ -236,7 +236,6 @@ echo_default() { echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}${CORE_COUNT}${CL}" echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE}MB${CL}" echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}${CT_ID}${CL}" - # Include VERBOSE if enabled if [ "$VERB" == "yes" ]; then echo -e "${SEARCH}${BOLD}${DGN}Verbose Mode: ${BGN}Enabled${CL}" fi @@ -247,8 +246,7 @@ echo_default() { # This function is called when the user decides to exit the script. It clears the screen and displays an exit message. exit_script() { clear - echo -e "\n" - echo -e "${CROSS}${RD}User exited script${CL}\n" + echo -e "\n${CROSS}${RD}User exited script${CL}\n" exit } @@ -293,10 +291,10 @@ advanced_settings() { while [ -z "$var_version" ]; do if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ "20.04" "Focal" OFF \ - "22.04" "Jammy" OFF \ - "24.04" "Noble" OFF \ - "24.10" "Oracular" OFF \ - 3>&1 1>&2 2>&3); then + "22.04" "Jammy" OFF \ + "24.04" "Noble" OFF \ + "24.10" "Oracular" OFF \ + 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}" fi @@ -316,10 +314,10 @@ advanced_settings() { "0" "Privileged" OFF \ 3>&1 1>&2 2>&3); then if [ -n "$CT_TYPE" ]; then - CT_TYPE_DESC="Privileged" - if [ "$CT_TYPE" -eq 1 ]; then CT_TYPE_DESC="Unprivileged" - fi + if [ "$CT_TYPE" -eq 0 ]; then + CT_TYPE_DESC="Privileged" + fi echo -e "${CONTAINERTYPE}${BOLD}${DGN}Container Type: ${BGN}$CT_TYPE_DESC${CL}" fi else @@ -592,7 +590,7 @@ install_script() { if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then header_info echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings${CL}" - base_settings + base_settings echo_default else header_info From 7779b1e0040e1b2de8559b05e9cb890b36df7d9e Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:44:28 +0100 Subject: [PATCH 09/11] Merge Create_LXC from DEV --- ct/create_lxc.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ct/create_lxc.sh b/ct/create_lxc.sh index a479a365..46f52902 100644 --- a/ct/create_lxc.sh +++ b/ct/create_lxc.sh @@ -15,9 +15,7 @@ YW=$(echo "\033[33m") YWB=$(echo "\033[93m") BL=$(echo "\033[36m") RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") # Formatting CL=$(echo "\033[m") @@ -66,7 +64,7 @@ function spinner() { # This function displays an informational message with a yellow color. function msg_info() { local msg="$1" - echo -ne "${TAB}${YW}${msg}" + echo -ne "${TAB}${YW}${HOLD}${msg}${HOLD}" spinner & SPINNER_PID=$! } @@ -141,11 +139,14 @@ function select_storage() { "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\nTo make a selection, use the Spacebar.\n" \ 16 $(($MSG_MAX_LENGTH + 23)) 6 \ "${MENU[@]}" 3>&1 1>&2 2>&3) || exit "Menu aborted." + if [ $? -ne 0 ]; then + echo -e "${CROSS}${RD} Menu aborted by user.${CL}" + exit 0 + fi done - printf $STORAGE + printf "%s" "$STORAGE" fi } - # Test if required variables are set [[ "${CTID:-}" ]] || exit "You need to set 'CTID' variable." [[ "${PCT_OSTYPE:-}" ]] || exit "You need to set 'PCT_OSTYPE' variable." From 0e461e4839ea19d986042e3d19818fd3a441c609 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:45:54 +0100 Subject: [PATCH 10/11] Merge from DEV --- misc/build.func | 63 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/misc/build.func b/misc/build.func index 28551a1b..82dcacf9 100644 --- a/misc/build.func +++ b/misc/build.func @@ -91,7 +91,7 @@ spinner() { # This function displays an informational message with a yellow color. msg_info() { local msg="$1" - echo -ne "${TAB}${YW}${msg}" + echo -ne "${TAB}${YW}${HOLD}${msg}${HOLD}" spinner & SPINNER_PID=$! } @@ -185,7 +185,7 @@ base_settings() { DISK_SIZE="4" CORE_COUNT="1" RAM_SIZE="1024" - VERBOSE="no" + VERBOSE="${1:-no}" PW="" CT_ID=$NEXTID HN=$NSAPP @@ -587,21 +587,56 @@ install_script() { NEXTID=$(pvesh get /cluster/nextid) timezone=$(cat /etc/timezone) header_info - if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings${CL}" - base_settings - echo_default - else - header_info - echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings${CL}" - advanced_settings - fi + while true; do + CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --menu "Choose an option:" \ + 12 50 4 \ + "1" "Default Settings" \ + "2" "Default Settings (with verbose)" \ + "3" "Advanced Settings" \ + "4" "Exit" --nocancel --default-item "1" 3>&1 1>&2 2>&3) + + if [ $? -ne 0 ]; then + echo -e "${CROSS}${RD} Menu canceled. Exiting.${CL}" + exit 0 + fi + + case $CHOICE in + 1) + header_info + echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings${CL}" + VERB="no" + base_settings "$VERB" + echo_default + break + ;; + 2) + header_info + echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings (${SEARCH} Verbose)${CL}" + VERB="yes" + base_settings "$VERB" + echo_default + break + ;; + 3) + header_info + echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings${CL}" + advanced_settings + break + ;; + 4) + echo -e "${CROSS}${RD}Exiting.${CL}" + exit 0 + ;; + *) + echo -e "${CROSS}${RD}Invalid option, please try again.${CL}" + ;; + esac + done } check_container_resources() { # Check actual RAM & Cores - current_ram=$(free -m | awk '/^Mem:/{print $2}') + current_ram=$(free -m | awk 'NR==2{print $2}') current_cpu=$(nproc) # Check whether the current RAM is less than the required RAM or the CPU cores are less than required @@ -811,4 +846,4 @@ EOF if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi -} \ No newline at end of file +} From 5d97fcdecf0f22b950c9cdef077fc7c517906647 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:46:32 +0100 Subject: [PATCH 11/11] Merge from DEV --- misc/install.func | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/misc/install.func b/misc/install.func index e157d1cb..d701fdfb 100644 --- a/misc/install.func +++ b/misc/install.func @@ -17,6 +17,7 @@ color() { CL=$(echo "\033[m") BFR="\\r\\033[K" BOLD=$(echo "\033[1m") + HOLD=" " TAB=" " # System @@ -86,7 +87,7 @@ spinner() { # This function displays an informational message with a yellow color. msg_info() { local msg="$1" - echo -ne "${TAB}${YW}${msg}" + echo -ne "${TAB}${YW}${HOLD}${msg}${HOLD}" spinner & SPINNER_PID=$! } @@ -218,11 +219,10 @@ motd_ssh() { if [ -f "$MOTD_FILE" ]; then # Start MOTD with application info and link echo -e "\n${BOLD}${APPLICATION} LXC Container${CL}" > "$MOTD_FILE" - echo -e "${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| Project: ${GN}ProxmoxVE ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\n" >> "$MOTD_FILE" + echo -e "${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\n" >> "$MOTD_FILE" # Add system information with icons - echo -e "${TAB}${OS}${YW} OS: ${GN}${OS_NAME} ${OS_VERSION}${CL}" >> "$MOTD_FILE" - echo -e "${TAB}${OSVERSION}${YW} Version: ${GN}${OS_VERSION}${CL}" >> "$MOTD_FILE" + echo -e "${TAB}${OS}${YW} OS: ${GN}${OS_NAME} - Version: ${OS_VERSION}${CL}" >> "$MOTD_FILE" echo -e "${TAB}${HOSTNAME}${YW} Hostname: ${GN}$(hostname)${CL}" >> "$MOTD_FILE" echo -e "${TAB}${INFO}${YW} IP Address: ${GN}${IP}${CL}" >> "$MOTD_FILE" else