This commit is contained in:
CanbiZ 2025-05-07 13:43:15 +02:00
parent bd52bbc4ba
commit 2eb8388fc7
5 changed files with 170 additions and 155 deletions

View File

@ -10,6 +10,7 @@
# if [ "$VERBOSE" == "yes" ]; then set -x; fi # if [ "$VERBOSE" == "yes" ]; then set -x; fi
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func) source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func)
load_functions
# This function sets color variables for formatting output in the terminal # This function sets color variables for formatting output in the terminal
# Colors # Colors

View File

@ -4,37 +4,40 @@
# License: MIT # License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func)
load_functions
# This function sets color variables for formatting output in the terminal # This function sets color variables for formatting output in the terminal
color() { # color() {
# Colors # # Colors
YW=$(echo "\033[33m") # YW=$(echo "\033[33m")
YWB=$(echo "\033[93m") # YWB=$(echo "\033[93m")
BL=$(echo "\033[36m") # BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m") # RD=$(echo "\033[01;31m")
GN=$(echo "\033[1;92m") # GN=$(echo "\033[1;92m")
# Formatting # # Formatting
CL=$(echo "\033[m") # CL=$(echo "\033[m")
BFR="\\r\\033[K" # BFR="\\r\\033[K"
BOLD=$(echo "\033[1m") # BOLD=$(echo "\033[1m")
TAB=" " # TAB=" "
# System # # System
RETRY_NUM=10 # RETRY_NUM=10
RETRY_EVERY=3 # RETRY_EVERY=3
i=$RETRY_NUM # i=$RETRY_NUM
# Icons # # Icons
CM="${TAB}✔️${TAB}${CL}" # CM="${TAB}✔️${TAB}${CL}"
CROSS="${TAB}✖️${TAB}${CL}" # CROSS="${TAB}✖️${TAB}${CL}"
INFO="${TAB}💡${TAB}${CL}" # INFO="${TAB}💡${TAB}${CL}"
NETWORK="${TAB}📡${TAB}${CL}" # NETWORK="${TAB}📡${TAB}${CL}"
OS="${TAB}🖥️${TAB}${CL}" # OS="${TAB}🖥️${TAB}${CL}"
OSVERSION="${TAB}🌟${TAB}${CL}" # OSVERSION="${TAB}🌟${TAB}${CL}"
HOSTNAME="${TAB}🏠${TAB}${CL}" # HOSTNAME="${TAB}🏠${TAB}${CL}"
GATEWAY="${TAB}🌐${TAB}${CL}" # GATEWAY="${TAB}🌐${TAB}${CL}"
DEFAULT="${TAB}⚙️${TAB}${CL}" # DEFAULT="${TAB}⚙️${TAB}${CL}"
} # }
# Function to set STD mode based on verbosity # Function to set STD mode based on verbosity
set_std_mode() { set_std_mode() {
@ -78,78 +81,78 @@ error_handler() {
[[ -n "${SPINNER_PID:-}" ]] && kill "$SPINNER_PID" &>/dev/null || true [[ -n "${SPINNER_PID:-}" ]] && kill "$SPINNER_PID" &>/dev/null || true
} }
# This function displays an informational message with logging support. # # This function displays an informational message with logging support.
declare -A MSG_INFO_SHOWN # declare -A MSG_INFO_SHOWN
SPINNER_ACTIVE=0 # SPINNER_ACTIVE=0
SPINNER_PID="" # SPINNER_PID=""
SPINNER_MSG="" # SPINNER_MSG=""
trap 'stop_spinner' EXIT INT TERM HUP # trap 'stop_spinner' EXIT INT TERM HUP
start_spinner() { # start_spinner() {
local msg="$1" # local msg="$1"
local frames=(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏) # local frames=(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏)
local spin_i=0 # local spin_i=0
local interval=0.1 # local interval=0.1
SPINNER_MSG="$msg" # SPINNER_MSG="$msg"
printf "\r\e[2K" >&2 # printf "\r\e[2K" >&2
{ # {
while [[ "$SPINNER_ACTIVE" -eq 1 ]]; do # while [[ "$SPINNER_ACTIVE" -eq 1 ]]; do
printf "\r\e[2K%s %b" "${frames[spin_i]}" "${YW}${SPINNER_MSG}${CL}" >&2 # printf "\r\e[2K%s %b" "${frames[spin_i]}" "${YW}${SPINNER_MSG}${CL}" >&2
spin_i=$(((spin_i + 1) % ${#frames[@]})) # spin_i=$(((spin_i + 1) % ${#frames[@]}))
sleep "$interval" # sleep "$interval"
done # done
} & # } &
SPINNER_PID=$! # SPINNER_PID=$!
disown "$SPINNER_PID" # disown "$SPINNER_PID"
} # }
stop_spinner() { # stop_spinner() {
if [[ ${SPINNER_PID+v} && -n "$SPINNER_PID" ]] && kill -0 "$SPINNER_PID" 2>/dev/null; then # if [[ ${SPINNER_PID+v} && -n "$SPINNER_PID" ]] && kill -0 "$SPINNER_PID" 2>/dev/null; then
kill "$SPINNER_PID" 2>/dev/null # kill "$SPINNER_PID" 2>/dev/null
sleep 0.1 # sleep 0.1
kill -0 "$SPINNER_PID" 2>/dev/null && kill -9 "$SPINNER_PID" 2>/dev/null # kill -0 "$SPINNER_PID" 2>/dev/null && kill -9 "$SPINNER_PID" 2>/dev/null
wait "$SPINNER_PID" 2>/dev/null || true # wait "$SPINNER_PID" 2>/dev/null || true
fi # fi
SPINNER_ACTIVE=0 # SPINNER_ACTIVE=0
unset SPINNER_PID # unset SPINNER_PID
} # }
spinner_guard() { # spinner_guard() {
if [[ "$SPINNER_ACTIVE" -eq 1 ]] && [[ -n "$SPINNER_PID" ]]; then # if [[ "$SPINNER_ACTIVE" -eq 1 ]] && [[ -n "$SPINNER_PID" ]]; then
kill "$SPINNER_PID" 2>/dev/null # kill "$SPINNER_PID" 2>/dev/null
wait "$SPINNER_PID" 2>/dev/null || true # wait "$SPINNER_PID" 2>/dev/null || true
SPINNER_ACTIVE=0 # SPINNER_ACTIVE=0
unset SPINNER_PID # unset SPINNER_PID
fi # fi
} # }
msg_info() { # msg_info() {
local msg="$1" # local msg="$1"
[[ -n "${MSG_INFO_SHOWN["$msg"]+x}" ]] && return # [[ -n "${MSG_INFO_SHOWN["$msg"]+x}" ]] && return
MSG_INFO_SHOWN["$msg"]=1 # MSG_INFO_SHOWN["$msg"]=1
spinner_guard # spinner_guard
SPINNER_ACTIVE=1 # SPINNER_ACTIVE=1
start_spinner "$msg" # start_spinner "$msg"
} # }
msg_ok() { # msg_ok() {
local msg="$1" # local msg="$1"
stop_spinner # stop_spinner
printf "\r\e[2K%s %b\n" "${CM}" "${GN}${msg}${CL}" >&2 # printf "\r\e[2K%s %b\n" "${CM}" "${GN}${msg}${CL}" >&2
unset MSG_INFO_SHOWN["$msg"] # unset MSG_INFO_SHOWN["$msg"]
} # }
msg_error() { # msg_error() {
stop_spinner # stop_spinner
local msg="$1" # local msg="$1"
printf "\r\e[2K%s %b\n" "${CROSS}" "${RD}${msg}${CL}" >&2 # printf "\r\e[2K%s %b\n" "${CROSS}" "${RD}${msg}${CL}" >&2
#log_message "ERROR" "$msg" # #log_message "ERROR" "$msg"
} # }
# This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection # This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection
setting_up_container() { setting_up_container() {

View File

@ -15,7 +15,9 @@ variables() {
} }
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/api.func) source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/api.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func) source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func)
color
# # This function sets various color variables using ANSI escape codes for formatting text in the terminal. # # This function sets various color variables using ANSI escape codes for formatting text in the terminal.
# color() { # color() {

View File

@ -1,6 +1,14 @@
# Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/LICENSE # License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/LICENSE
load_functions() {
[[ -n "${__FUNCTIONS_LOADED:-}" ]] && return
__FUNCTIONS_LOADED=1
color
# add more
}
# This function sets various color variables using ANSI escape codes for formatting text in the terminal. # This function sets various color variables using ANSI escape codes for formatting text in the terminal.
color() { color() {
# Colors # Colors
@ -117,77 +125,77 @@ msg_error() {
printf "\r\e[2K%s %b\n" "${CROSS}" "${RD}${msg}${CL}" >&2 printf "\r\e[2K%s %b\n" "${CROSS}" "${RD}${msg}${CL}" >&2
} }
shell_check() { # shell_check() {
if [[ "$(basename "$SHELL")" != "bash" ]]; then # if [[ "$(basename "$SHELL")" != "bash" ]]; then
clear # clear
msg_error "Your default shell is currently not set to Bash. To use these scripts, please switch to the Bash shell." # msg_error "Your default shell is currently not set to Bash. To use these scripts, please switch to the Bash shell."
echo -e "\nExiting..." # echo -e "\nExiting..."
sleep 2 # sleep 2
exit # exit
fi # fi
} # }
root_check() { # root_check() {
if [[ "$(id -u)" -ne 0 || $(ps -o comm= -p $PPID) == "sudo" ]]; then # if [[ "$(id -u)" -ne 0 || $(ps -o comm= -p $PPID) == "sudo" ]]; then
clear # clear
msg_error "Please run this script as root." # msg_error "Please run this script as root."
echo -e "\nExiting..." # echo -e "\nExiting..."
sleep 2 # sleep 2
exit # exit
fi # fi
} # }
pve_check() { # pve_check() {
if ! pveversion | grep -Eq "pve-manager/8\.[1-9](\.[0-9]+)*"; then # if ! pveversion | grep -Eq "pve-manager/8\.[1-9](\.[0-9]+)*"; then
msg_error "${CROSS}${RD}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 "Requires Proxmox Virtual Environment Version 8.1 or later."
echo -e "Exiting..." # echo -e "Exiting..."
sleep 2 # sleep 2
exit # exit
fi # fi
} # }
arch_check() { # arch_check() {
if [ "$(dpkg --print-architecture)" != "amd64" ]; then # if [ "$(dpkg --print-architecture)" != "amd64" ]; then
echo -e "\n ${INFO}${YWB}This script will not work with PiMox! \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 "\n ${YWB}Visit https://github.com/asylumexp/Proxmox for ARM64 support. \n"
echo -e "Exiting..." # echo -e "Exiting..."
sleep 2 # sleep 2
exit # exit
fi # fi
} # }
ssh_check() { # ssh_check() {
if command -v pveversion >/dev/null 2>&1; then # if command -v pveversion >/dev/null 2>&1; then
if [ -n "${SSH_CLIENT:+x}" ]; then # if [ -n "${SSH_CLIENT:+x}" ]; then
if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH DETECTED" --yesno "It's suggested to use the Proxmox shell instead of SSH, since SSH can create issues while gathering variables. Would you like to proceed with using SSH?" 10 62; then # if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH DETECTED" --yesno "It's suggested to use the Proxmox shell instead of SSH, since SSH can create issues while gathering variables. Would you like to proceed with using SSH?" 10 62; then
echo "you've been warned" # echo "you've been warned"
else # else
clear # clear
exit # exit
fi # fi
fi # fi
fi # fi
} # }
exit-script() { # exit-script() {
clear # clear
echo -e "\n${CROSS}${RD}User exited script${CL}\n" # echo -e "\n${CROSS}${RD}User exited script${CL}\n"
exit # exit
} # }
set_std_mode() { # set_std_mode() {
if [ "$VERB" = "yes" ]; then # if [ "$VERB" = "yes" ]; then
STD="" # STD=""
else # else
STD="silent" # STD="silent"
fi # fi
} # }
silent() { # silent() {
if [ "$VERB" = "no" ]; then # if [ "$VERB" = "no" ]; then
"$@" >>"$LOGFILE" 2>&1 # "$@" >>"$LOGFILE" 2>&1
else # else
"$@" 2>&1 | tee -a "$LOGFILE" # "$@" 2>&1 | tee -a "$LOGFILE"
fi # fi
} # }

View File

@ -6,6 +6,7 @@
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func) source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func)
load_functions
# color() { # color() {
# # Colors # # Colors