Verbose_Update (#2583)

This commit is contained in:
CanbiZ 2025-02-24 11:18:38 +01:00 committed by GitHub
parent 35f635bdb4
commit 10d4ce4eef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 223 additions and 129 deletions

View File

@ -36,12 +36,24 @@ color() {
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" # Function to set STD mode based on verbosity
verb_ip6() { set_std_mode() {
if [ "$VERBOSE" = "yes" ]; then if [ "$VERBOSE" = "yes" ]; then
STD="" STD=""
else STD="silent"; fi else
silent() { "$@" >/dev/null 2>&1; } STD="silent"
fi
}
# Silent execution function
silent() {
"$@" >/dev/null 2>&1
}
# This function enables IPv6 if it's not disabled and sets verbose mode
verb_ip6() {
set_std_mode # Set STD mode based on VERBOSE
if [ "$DISABLEIPV6" == "yes" ]; then if [ "$DISABLEIPV6" == "yes" ]; then
$STD sysctl -w net.ipv6.conf.all.disable_ipv6=1 $STD sysctl -w net.ipv6.conf.all.disable_ipv6=1
echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf
@ -108,7 +120,7 @@ network_check() {
set +e set +e
trap - ERR trap - ERR
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 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"; msg_ok "Internet Connected"
else else
msg_error "Internet NOT Connected" msg_error "Internet NOT Connected"
read -r -p "Would you like to continue anyway? <y/N> " prompt read -r -p "Would you like to continue anyway? <y/N> " prompt

View File

@ -80,44 +80,75 @@ error_handler() {
echo -e "\n$error_message\n" echo -e "\n$error_message\n"
} }
# This function displays a spinner. # This function displays an informational message with logging support.
spinner() { start_spinner() {
local msg="$1"
local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏') local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
local spin_i=0 local spin_i=0
local interval=0.1 local interval=0.1
printf "\e[?25l" local term_width=$(tput cols)
local color="${YWB}" {
while [ "${SPINNER_ACTIVE:-1}" -eq 1 ]; do
while true; do printf "\r\e[2K${frames[spin_i]} ${YW}%b${CL}" "$msg" >&2
printf "\r ${color}%s${CL}" "${frames[spin_i]}"
spin_i=$(((spin_i + 1) % ${#frames[@]})) spin_i=$(((spin_i + 1) % ${#frames[@]}))
sleep "$interval" sleep "$interval"
done 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=$! SPINNER_PID=$!
} }
# This function displays a success message with a green color. msg_info() {
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" 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_ok() {
msg_error() { if [ -n "${SPINNER_PID:-}" ] && ps -p "$SPINNER_PID" >/dev/null 2>&1; then
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi kill "$SPINNER_PID" >/dev/null 2>&1
printf "\e[?25h" wait "$SPINNER_PID" 2>/dev/null || true
fi
local msg="$1" 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 # Check if the shell is using bash
@ -936,6 +967,7 @@ install_script() {
whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --msgbox "Diagnostics settings changed to ${DIAGNOSTICS}." 8 58 whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --msgbox "Diagnostics settings changed to ${DIAGNOSTICS}." 8 58
fi fi
fi fi
;; ;;
5) 5)
echo -e "${CROSS}${RD}Exiting.${CL}" echo -e "${CROSS}${RD}Exiting.${CL}"
@ -988,6 +1020,9 @@ check_container_storage() {
} }
start() { start() {
LOGDIR="/usr/local/community-scripts/logs"
mkdir -p "$LOGDIR"
if command -v pveversion >/dev/null 2>&1; then 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 "Proxmox VE Helper Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
clear clear
@ -999,11 +1034,32 @@ start() {
fi fi
if ! command -v pveversion >/dev/null 2>&1; then 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 clear
log_message "INFO" "Update aborted."
exit_script exit_script
exit exit
fi ;;
esac
SPINNER_PID="" SPINNER_PID=""
update_script update_script
fi fi
@ -1172,6 +1228,22 @@ EOF
post_update_to_api "done" "none" 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_script() {
exit_code=$? # Capture the exit status of the last executed command exit_code=$? # Capture the exit status of the last executed command
@ -1195,9 +1267,7 @@ if [ $exit_code -ne 0 ]; then # Check if exit code is nonzero
fi fi
} }
trap 'exit_script' EXIT trap 'exit_script' EXIT
trap 'post_update_to_api "failed" "$BASH_COMMAND"' ERR 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 trap 'post_update_to_api "failed" "TERMINATED"' SIGTERM

View File

@ -36,12 +36,24 @@ color() {
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" # Function to set STD mode based on verbosity
verb_ip6() { set_std_mode() {
if [ "$VERBOSE" = "yes" ]; then if [ "$VERBOSE" = "yes" ]; then
STD="" STD=""
else STD="silent"; fi else
silent() { "$@" >/dev/null 2>&1; } STD="silent"
fi
}
# Silent execution function
silent() {
"$@" >/dev/null 2>&1
}
# This function enables IPv6 if it's not disabled and sets verbose mode
verb_ip6() {
set_std_mode # Set STD mode based on VERBOSE
if [ "$DISABLEIPV6" == "yes" ]; then if [ "$DISABLEIPV6" == "yes" ]; then
echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf
$STD sysctl -p $STD sysctl -p
@ -149,18 +161,18 @@ network_check() {
sleep 1 sleep 1
# Check IPv4 connectivity to Google, Cloudflare & Quad9 DNS servers. # 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 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"; msg_ok "IPv4 Internet Connected"
ipv4_connected=true ipv4_connected=true
else else
msg_error "IPv4 Internet Not Connected"; msg_error "IPv4 Internet Not Connected"
fi fi
# Check IPv6 connectivity to Google, Cloudflare & Quad9 DNS servers. # 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 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"; msg_ok "IPv6 Internet Connected"
ipv6_connected=true ipv6_connected=true
else else
msg_error "IPv6 Internet Not Connected"; msg_error "IPv6 Internet Not Connected"
fi fi
# If both IPv4 and IPv6 checks fail, prompt the user # If both IPv4 and IPv6 checks fail, prompt the user