mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-07-11 16:37:37 +00:00
Verbose_Update (#2583)
This commit is contained in:
236
misc/build.func
236
misc/build.func
@ -5,12 +5,12 @@
|
||||
# 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.
|
||||
INTEGER='^[0-9]+([.][0-9]+)?$' # it defines the INTEGER regular expression pattern.
|
||||
PVEHOST_NAME=$(hostname) # gets the Proxmox Hostname and sets it to Uppercase
|
||||
DIAGNOSTICS="yes" # sets the DIAGNOSTICS variable to "yes", used for the API call.
|
||||
METHOD="default" # sets the METHOD variable to "default", used for the API call.
|
||||
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.
|
||||
INTEGER='^[0-9]+([.][0-9]+)?$' # it defines the INTEGER regular expression pattern.
|
||||
PVEHOST_NAME=$(hostname) # gets the Proxmox Hostname and sets it to Uppercase
|
||||
DIAGNOSTICS="yes" # sets the DIAGNOSTICS variable to "yes", used for the API call.
|
||||
METHOD="default" # sets the METHOD variable to "default", used for the API call.
|
||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)" # generates a random UUID and sets it to the RANDOM_UUID variable.
|
||||
}
|
||||
|
||||
@ -69,55 +69,86 @@ catch_errors() {
|
||||
|
||||
# This function is called when an error occurs. It receives the exit code, line number, and command that caused the error, and displays an error message.
|
||||
error_handler() {
|
||||
source /dev/stdin <<< $(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func)
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
|
||||
source /dev/stdin <<<$(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func)
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID >/dev/null; then kill $SPINNER_PID >/dev/null; fi
|
||||
printf "\e[?25h"
|
||||
local exit_code="$?"
|
||||
local line_number="$1"
|
||||
local command="$2"
|
||||
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
|
||||
post_update_to_api "failed" "${command}"
|
||||
post_update_to_api "failed" "${command}"
|
||||
echo -e "\n$error_message\n"
|
||||
}
|
||||
|
||||
# This function displays a spinner.
|
||||
spinner() {
|
||||
# This function displays an informational message with logging support.
|
||||
start_spinner() {
|
||||
local msg="$1"
|
||||
local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
|
||||
local spin_i=0
|
||||
local interval=0.1
|
||||
printf "\e[?25l"
|
||||
local term_width=$(tput cols)
|
||||
|
||||
local color="${YWB}"
|
||||
{
|
||||
while [ "${SPINNER_ACTIVE:-1}" -eq 1 ]; do
|
||||
printf "\r\e[2K${frames[spin_i]} ${YW}%b${CL}" "$msg" >&2
|
||||
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}${HOLD}${msg}${HOLD}"
|
||||
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"
|
||||
msg_info() {
|
||||
local msg="$1"
|
||||
echo -e "${BFR}${CM}${GN}${msg}${CL}"
|
||||
if [ "${SPINNER_ACTIVE:-0}" -eq 1 ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
SPINNER_ACTIVE=1
|
||||
start_spinner "$msg"
|
||||
}
|
||||
|
||||
# This function displays a error message with a red color.
|
||||
msg_error() {
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
|
||||
printf "\e[?25h"
|
||||
msg_ok() {
|
||||
if [ -n "${SPINNER_PID:-}" ] && ps -p "$SPINNER_PID" >/dev/null 2>&1; then
|
||||
kill "$SPINNER_PID" >/dev/null 2>&1
|
||||
wait "$SPINNER_PID" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
local msg="$1"
|
||||
echo -e "${BFR}${CROSS}${RD}${msg}${CL}"
|
||||
printf "\r\e[2K${CM}${GN}%b${CL}\n" "$msg" >&2
|
||||
unset SPINNER_PID
|
||||
SPINNER_ACTIVE=0
|
||||
|
||||
log_message "OK" "$msg"
|
||||
}
|
||||
|
||||
msg_error() {
|
||||
if [ -n "${SPINNER_PID:-}" ] && ps -p "$SPINNER_PID" >/dev/null 2>&1; then
|
||||
kill "$SPINNER_PID" >/dev/null 2>&1
|
||||
wait "$SPINNER_PID" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
local msg="$1"
|
||||
printf "\r\e[2K${CROSS}${RD}%b${CL}\n" "$msg" >&2
|
||||
unset SPINNER_PID
|
||||
SPINNER_ACTIVE=0
|
||||
log_message "ERROR" "$msg"
|
||||
}
|
||||
|
||||
log_message() {
|
||||
local level="$1"
|
||||
local message="$2"
|
||||
local timestamp
|
||||
local logdate
|
||||
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
logdate=$(date '+%Y-%m-%d')
|
||||
|
||||
LOGDIR="/usr/local/community-scripts/logs"
|
||||
mkdir -p "$LOGDIR"
|
||||
|
||||
LOGFILE="${LOGDIR}/${logdate}_${NSAPP}.log"
|
||||
echo "$timestamp - $level: $message" >>"$LOGFILE"
|
||||
}
|
||||
|
||||
# Check if the shell is using bash
|
||||
@ -236,13 +267,13 @@ update_motd_ip() {
|
||||
|
||||
IP=$(get_current_ip)
|
||||
# Add the new IP address
|
||||
echo -e "${TAB}${NETWORK}${YW} IP Address: ${GN}${IP}${CL}" >> "$MOTD_FILE"
|
||||
echo -e "${TAB}${NETWORK}${YW} IP Address: ${GN}${IP}${CL}" >>"$MOTD_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to download & save header files
|
||||
get_header() {
|
||||
local app_name=$(echo ${APP,,} | tr -d ' ')
|
||||
local app_name=$(echo ${APP,,} | tr -d ' ')
|
||||
local header_url="https://github.com/community-scripts/ProxmoxVE/raw/main/ct/headers/${app_name}"
|
||||
local local_header_path="/usr/local/community-scripts/headers/${app_name}"
|
||||
|
||||
@ -261,7 +292,7 @@ get_header() {
|
||||
|
||||
# This function sets the APP-Name into an ASCII Header in Slant, figlet needed on proxmox main node.
|
||||
header_info() {
|
||||
local app_name=$(echo ${APP,,} | tr -d ' ')
|
||||
local app_name=$(echo ${APP,,} | tr -d ' ')
|
||||
local header_content
|
||||
|
||||
# Download & save Header-File locally
|
||||
@ -795,14 +826,14 @@ advanced_settings() {
|
||||
fi
|
||||
}
|
||||
|
||||
diagnostics_check(){
|
||||
diagnostics_check() {
|
||||
if ! [ -d "/usr/local/community-scripts" ]; then
|
||||
mkdir -p /usr/local/community-scripts
|
||||
fi
|
||||
mkdir -p /usr/local/community-scripts
|
||||
fi
|
||||
|
||||
if ! [ -f "/usr/local/community-scripts/diagnostics" ]; then
|
||||
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS" --yesno "Send Diagnostics of LXC Installation?\n\n(This only transmits data without user data, just RAM, CPU, LXC name, ...)" 10 58); then
|
||||
cat <<EOF>/usr/local/community-scripts/diagnostics
|
||||
if ! [ -f "/usr/local/community-scripts/diagnostics" ]; then
|
||||
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS" --yesno "Send Diagnostics of LXC Installation?\n\n(This only transmits data without user data, just RAM, CPU, LXC name, ...)" 10 58); then
|
||||
cat <<EOF >/usr/local/community-scripts/diagnostics
|
||||
DIAGNOSTICS=yes
|
||||
|
||||
#This file is used to store the diagnostics settings for the Community-Scripts API.
|
||||
@ -920,23 +951,24 @@ install_script() {
|
||||
advanced_settings
|
||||
break
|
||||
;;
|
||||
4)
|
||||
if [[ $DIAGNOSTICS == "yes" ]]; then
|
||||
if whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --yesno "Send Diagnostics of LXC Installation?\n\nCurrent setting: ${DIAGNOSTICS}" 10 58 \
|
||||
--yes-button "No" --no-button "Back" ; then
|
||||
DIAGNOSTICS="no"
|
||||
sed -i 's/^DIAGNOSTICS=.*/DIAGNOSTICS=no/' /usr/local/community-scripts/diagnostics
|
||||
whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --msgbox "Diagnostics settings changed to ${DIAGNOSTICS}." 8 58
|
||||
fi
|
||||
else
|
||||
if whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --yesno "Send Diagnostics of LXC Installation?\n\nCurrent setting: ${DIAGNOSTICS}" 10 58 \
|
||||
--yes-button "Yes" --no-button "Back" ; then
|
||||
DIAGNOSTICS="yes"
|
||||
sed -i 's/^DIAGNOSTICS=.*/DIAGNOSTICS=yes/' /usr/local/community-scripts/diagnostics
|
||||
whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --msgbox "Diagnostics settings changed to ${DIAGNOSTICS}." 8 58
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
4)
|
||||
if [[ $DIAGNOSTICS == "yes" ]]; then
|
||||
if whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --yesno "Send Diagnostics of LXC Installation?\n\nCurrent setting: ${DIAGNOSTICS}" 10 58 \
|
||||
--yes-button "No" --no-button "Back"; then
|
||||
DIAGNOSTICS="no"
|
||||
sed -i 's/^DIAGNOSTICS=.*/DIAGNOSTICS=no/' /usr/local/community-scripts/diagnostics
|
||||
whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --msgbox "Diagnostics settings changed to ${DIAGNOSTICS}." 8 58
|
||||
fi
|
||||
else
|
||||
if whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --yesno "Send Diagnostics of LXC Installation?\n\nCurrent setting: ${DIAGNOSTICS}" 10 58 \
|
||||
--yes-button "Yes" --no-button "Back"; then
|
||||
DIAGNOSTICS="yes"
|
||||
sed -i 's/^DIAGNOSTICS=.*/DIAGNOSTICS=yes/' /usr/local/community-scripts/diagnostics
|
||||
whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --msgbox "Diagnostics settings changed to ${DIAGNOSTICS}." 8 58
|
||||
fi
|
||||
fi
|
||||
|
||||
;;
|
||||
5)
|
||||
echo -e "${CROSS}${RD}Exiting.${CL}"
|
||||
exit 0
|
||||
@ -973,8 +1005,8 @@ check_container_storage() {
|
||||
# Check if the /boot partition is more than 80% full
|
||||
total_size=$(df /boot --output=size | tail -n 1)
|
||||
local used_size=$(df /boot --output=used | tail -n 1)
|
||||
usage=$(( 100 * used_size / total_size ))
|
||||
if (( usage > 80 )); then
|
||||
usage=$((100 * used_size / total_size))
|
||||
if ((usage > 80)); then
|
||||
# Prompt the user for confirmation to continue
|
||||
echo -e "${INFO}${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}"
|
||||
echo -ne "Continue anyway? <y/N> "
|
||||
@ -988,6 +1020,9 @@ check_container_storage() {
|
||||
}
|
||||
|
||||
start() {
|
||||
LOGDIR="/usr/local/community-scripts/logs"
|
||||
mkdir -p "$LOGDIR"
|
||||
|
||||
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
|
||||
clear
|
||||
@ -999,11 +1034,32 @@ 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
|
||||
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC Update/Setting" --menu \
|
||||
"Support/Update functions for ${APP} LXC. Choose an option:" \
|
||||
12 60 3 \
|
||||
"1" "YES (Silent Mode)" \
|
||||
"2" "YES (Verbose Mode)" \
|
||||
"3" "NO (Cancel Update)" --nocancel --default-item "1" 3>&1 1>&2 2>&3)
|
||||
|
||||
case "$CHOICE" in
|
||||
1)
|
||||
VERB="no"
|
||||
set_std_mode
|
||||
log_message "INFO" "Update started (Silent Mode)"
|
||||
;;
|
||||
2)
|
||||
VERB="yes"
|
||||
set_std_mode
|
||||
log_message "INFO" "Update started (Verbose Mode)"
|
||||
;;
|
||||
3)
|
||||
clear
|
||||
log_message "INFO" "Update aborted."
|
||||
exit_script
|
||||
exit
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
SPINNER_PID=""
|
||||
update_script
|
||||
fi
|
||||
@ -1168,36 +1224,50 @@ EOF
|
||||
if [[ -f /etc/systemd/system/ping-instances.service ]]; then
|
||||
systemctl start ping-instances.service
|
||||
fi
|
||||
|
||||
|
||||
post_update_to_api "done" "none"
|
||||
}
|
||||
|
||||
set_std_mode() {
|
||||
if [ "$VERB" = "yes" ]; then
|
||||
STD=""
|
||||
else
|
||||
STD="silent"
|
||||
fi
|
||||
}
|
||||
|
||||
# Silent execution function
|
||||
silent() {
|
||||
if [ "$VERB" = "no" ]; then
|
||||
"$@" >>"$LOGFILE" 2>&1
|
||||
else
|
||||
"$@" 2>&1 | tee -a "$LOGFILE"
|
||||
fi
|
||||
}
|
||||
|
||||
exit_script() {
|
||||
exit_code=$? # Capture the exit status of the last executed command
|
||||
exit_code=$? # Capture the exit status of the last executed command
|
||||
#200 exit codes indicate error in create_lxc.sh
|
||||
#100 exit codes indicate error in install.func
|
||||
|
||||
if [ $exit_code -ne 0 ]; then # Check if exit code is nonzero
|
||||
if [ $exit_code -ne 0 ]; then # Check if exit code is nonzero
|
||||
case $exit_code in
|
||||
200) post_update_to_api "failed" "create_lxc.sh: Error during LXC creation" ;;
|
||||
201) post_update_to_api "failed" "create_lxc.sh Invalid Storage class" ;;
|
||||
202) post_update_to_api "failed" "create_lxc.sh Invalid Menu aborted" ;;
|
||||
203) post_update_to_api "failed" "create_lxc.sh CTID was unset" ;;
|
||||
204) post_update_to_api "failed" "create_lxc.sh PCT_OSTYPE was unset" ;;
|
||||
205) post_update_to_api "failed" "create_lxc.sh ID cannot be less than 100" ;;
|
||||
206) post_update_to_api "failed" "create_lxc.sh ID already in use" ;;
|
||||
207) post_update_to_api "failed" "create_lxc.sh Template not found" ;;
|
||||
208) post_update_to_api "failed" "create_lxc.sh Error downloading template" ;;
|
||||
101) post_update_to_api "failed" "create_lxc.sh No Network connection" ;;
|
||||
*) post_update_to_api "failed" "Unknown error, exit code: $exit_code" ;;
|
||||
200) post_update_to_api "failed" "create_lxc.sh: Error during LXC creation" ;;
|
||||
201) post_update_to_api "failed" "create_lxc.sh Invalid Storage class" ;;
|
||||
202) post_update_to_api "failed" "create_lxc.sh Invalid Menu aborted" ;;
|
||||
203) post_update_to_api "failed" "create_lxc.sh CTID was unset" ;;
|
||||
204) post_update_to_api "failed" "create_lxc.sh PCT_OSTYPE was unset" ;;
|
||||
205) post_update_to_api "failed" "create_lxc.sh ID cannot be less than 100" ;;
|
||||
206) post_update_to_api "failed" "create_lxc.sh ID already in use" ;;
|
||||
207) post_update_to_api "failed" "create_lxc.sh Template not found" ;;
|
||||
208) post_update_to_api "failed" "create_lxc.sh Error downloading template" ;;
|
||||
101) post_update_to_api "failed" "create_lxc.sh No Network connection" ;;
|
||||
*) post_update_to_api "failed" "Unknown error, exit code: $exit_code" ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
trap 'exit_script' EXIT
|
||||
trap 'post_update_to_api "failed" "$BASH_COMMAND"' ERR
|
||||
trap 'post_update_to_api "failed" "INTERRUPTED"' SIGINT
|
||||
trap 'post_update_to_api "failed" "INTERRUPTED"' SIGINT
|
||||
trap 'post_update_to_api "failed" "TERMINATED"' SIGTERM
|
||||
|
||||
|
Reference in New Issue
Block a user