From 10d4ce4eef9e10979ad1dae9b86d56f543324ccf Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 24 Feb 2025 11:18:38 +0100 Subject: [PATCH] Verbose_Update (#2583) --- misc/alpine-install.func | 50 +++++---- misc/build.func | 236 +++++++++++++++++++++++++-------------- misc/install.func | 66 ++++++----- 3 files changed, 223 insertions(+), 129 deletions(-) diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 313b091f0..019c291e5 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -18,7 +18,7 @@ color() { BFR="\\r\\033[K" BOLD=$(echo "\033[1m") TAB=" " - + # System RETRY_NUM=10 RETRY_EVERY=3 @@ -36,12 +36,24 @@ color() { 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() { +# Function to set STD mode based on verbosity +set_std_mode() { if [ "$VERBOSE" = "yes" ]; then STD="" - else STD="silent"; fi - silent() { "$@" >/dev/null 2>&1; } + else + 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 $STD sysctl -w net.ipv6.conf.all.disable_ipv6=1 echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf @@ -107,15 +119,15 @@ setting_up_container() { network_check() { set +e 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 - msg_ok "Internet Connected"; + 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 "${INFO}${RD}Expect Issues Without Internet${CL}" else - echo -e "${NETWORK}Check Network Settings" + echo -e "${NETWORK}Check Network Settings" exit 1 fi fi @@ -148,13 +160,13 @@ motd_ssh() { fi PROFILE_FILE="/etc/profile.d/00_lxc-details.sh" - echo "echo -e \"\"" > "$PROFILE_FILE" - echo -e "echo -e \"${BOLD}${APPLICATION} LXC Container${CL}"\" >> "$PROFILE_FILE" - echo -e "echo -e \"${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\"" >> "$PROFILE_FILE" - echo "echo \"\"" >> "$PROFILE_FILE" - echo -e "echo -e \"${TAB}${OS}${YW} OS: ${GN}${OS_NAME} - Version: ${OS_VERSION}${CL}\"" >> "$PROFILE_FILE" - echo -e "echo -e \"${TAB}${HOSTNAME}${YW} Hostname: ${GN}\$(hostname)${CL}\"" >> "$PROFILE_FILE" - echo -e "echo -e \"${TAB}${INFO}${YW} IP Address: ${GN}\$(ip -4 addr show eth0 | awk '/inet / {print \$2}' | cut -d/ -f1 | head -n 1)${CL}\"" >> "$PROFILE_FILE" + echo "echo -e \"\"" >"$PROFILE_FILE" + echo -e "echo -e \"${BOLD}${APPLICATION} LXC Container${CL}"\" >>"$PROFILE_FILE" + echo -e "echo -e \"${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\"" >>"$PROFILE_FILE" + echo "echo \"\"" >>"$PROFILE_FILE" + echo -e "echo -e \"${TAB}${OS}${YW} OS: ${GN}${OS_NAME} - Version: ${OS_VERSION}${CL}\"" >>"$PROFILE_FILE" + echo -e "echo -e \"${TAB}${HOSTNAME}${YW} Hostname: ${GN}\$(hostname)${CL}\"" >>"$PROFILE_FILE" + echo -e "echo -e \"${TAB}${INFO}${YW} IP Address: ${GN}\$(ip -4 addr show eth0 | awk '/inet / {print \$2}' | cut -d/ -f1 | head -n 1)${CL}\"" >>"$PROFILE_FILE" # Configure SSH if enabled if [[ "${SSH_ROOT}" == "yes" ]]; then @@ -170,8 +182,8 @@ motd_ssh() { # This function customizes the container and enables 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" + msg_info "Customizing Container" + bash -c "passwd -d root" >/dev/null 2>&1 + msg_ok "Customized Container" fi -} \ No newline at end of file +} diff --git a/misc/build.func b/misc/build.func index a8659dfd6..9ef8c5419 100644 --- a/misc/build.func +++ b/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 </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 </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? " @@ -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 - diff --git a/misc/install.func b/misc/install.func index b02344797..656c97222 100644 --- a/misc/install.func +++ b/misc/install.func @@ -19,7 +19,7 @@ color() { BOLD=$(echo "\033[1m") HOLD=" " TAB=" " - + # System RETRY_NUM=10 RETRY_EVERY=3 @@ -36,12 +36,24 @@ color() { 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() { +# Function to set STD mode based on verbosity +set_std_mode() { if [ "$VERBOSE" = "yes" ]; then STD="" - else STD="silent"; fi - silent() { "$@" >/dev/null 2>&1; } + else + 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 echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf $STD sysctl -p @@ -57,7 +69,7 @@ catch_errors() { # This function handles errors error_handler() { source <(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 + 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" @@ -83,7 +95,7 @@ spinner() { while true; do printf "\r ${color}%s${CL}" "${frames[spin_i]}" - spin_i=$(( (spin_i + 1) % ${#frames[@]} )) + spin_i=$(((spin_i + 1) % ${#frames[@]})) sleep "$interval" done } @@ -98,7 +110,7 @@ msg_info() { # 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 + 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}" @@ -106,7 +118,7 @@ msg_ok() { # 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 + 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}" @@ -147,23 +159,23 @@ network_check() { ipv4_connected=false ipv6_connected=false sleep 1 -# 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"; + # 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 else - msg_error "IPv4 Internet Not Connected"; + msg_error "IPv4 Internet Not Connected" 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 - msg_ok "IPv6 Internet Connected"; + msg_ok "IPv6 Internet Connected" ipv6_connected=true else - msg_error "IPv6 Internet Not Connected"; + msg_error "IPv6 Internet Not Connected" fi -# If both IPv4 and IPv6 checks fail, prompt the user + # If both IPv4 and IPv6 checks fail, prompt the user 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 @@ -193,7 +205,7 @@ else echo -n "DIRECT" fi EOF - chmod +x /usr/local/bin/apt-proxy-detect.sh + 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 @@ -204,7 +216,7 @@ EOF # This function modifies the message of the day (motd) and SSH settings motd_ssh() { # Set terminal to 256-color mode - grep -qxF "export TERM='xterm-256color'" /root/.bashrc || echo "export TERM='xterm-256color'" >> /root/.bashrc + grep -qxF "export TERM='xterm-256color'" /root/.bashrc || echo "export TERM='xterm-256color'" >>/root/.bashrc # Get OS information (Debian / Ubuntu) if [ -f "/etc/os-release" ]; then @@ -216,13 +228,13 @@ motd_ssh() { fi PROFILE_FILE="/etc/profile.d/00_lxc-details.sh" - echo "echo -e \"\"" > "$PROFILE_FILE" - echo -e "echo -e \"${BOLD}${APPLICATION} LXC Container${CL}"\" >> "$PROFILE_FILE" - echo -e "echo -e \"${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\"" >> "$PROFILE_FILE" - echo "echo \"\"" >> "$PROFILE_FILE" - echo -e "echo -e \"${TAB}${OS}${YW} OS: ${GN}${OS_NAME} - Version: ${OS_VERSION}${CL}\"" >> "$PROFILE_FILE" - echo -e "echo -e \"${TAB}${HOSTNAME}${YW} Hostname: ${GN}\$(hostname)${CL}\"" >> "$PROFILE_FILE" - echo -e "echo -e \"${TAB}${INFO}${YW} IP Address: ${GN}\$(hostname -I | awk '{print \$1}')${CL}\"" >> "$PROFILE_FILE" + echo "echo -e \"\"" >"$PROFILE_FILE" + echo -e "echo -e \"${BOLD}${APPLICATION} LXC Container${CL}"\" >>"$PROFILE_FILE" + echo -e "echo -e \"${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\"" >>"$PROFILE_FILE" + echo "echo \"\"" >>"$PROFILE_FILE" + echo -e "echo -e \"${TAB}${OS}${YW} OS: ${GN}${OS_NAME} - Version: ${OS_VERSION}${CL}\"" >>"$PROFILE_FILE" + echo -e "echo -e \"${TAB}${HOSTNAME}${YW} Hostname: ${GN}\$(hostname)${CL}\"" >>"$PROFILE_FILE" + echo -e "echo -e \"${TAB}${INFO}${YW} IP Address: ${GN}\$(hostname -I | awk '{print \$1}')${CL}\"" >>"$PROFILE_FILE" # Disable default MOTD scripts chmod -x /etc/update-motd.d/* @@ -253,7 +265,7 @@ EOF if [[ -n "${SSH_AUTHORIZED_KEY}" ]]; then mkdir -p /root/.ssh - echo "${SSH_AUTHORIZED_KEY}" > /root/.ssh/authorized_keys + echo "${SSH_AUTHORIZED_KEY}" >/root/.ssh/authorized_keys chmod 700 /root/.ssh chmod 600 /root/.ssh/authorized_keys fi