From d0f6818386d6f93bf9777ab4b625918c7e101369 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Tue, 23 Sep 2025 14:39:39 +0200 Subject: [PATCH] Move and improve ssh_check and shell_check functions The ssh_check function was moved from build.func to core.func and enhanced to allow an override and to skip warnings for localhost connections. The shell_check function was simplified to directly check for Bash and provide clearer messaging. These changes centralize environment checks and improve user experience. --- misc/build.func | 19 ------------------- misc/core.func | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/misc/build.func b/misc/build.func index b47aaa48..fa132148 100644 --- a/misc/build.func +++ b/misc/build.func @@ -239,25 +239,6 @@ update_motd_ip() { fi } -# ------------------------------------------------------------------------------ -# ssh_check() -# -# - Detects if script is running over SSH -# - Warns user and recommends using Proxmox shell -# - User can choose to continue or abort -# ------------------------------------------------------------------------------ -ssh_check() { - if [ -n "${SSH_CLIENT:+x}" ]; then - if whiptail --backtitle "[dev] 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 "[dev] 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." - exit - fi - fi -} - # ------------------------------------------------------------------------------ # install_ssh_keys_into_ct() # diff --git a/misc/core.func b/misc/core.func index 00c2d6e6..9d6e156b 100644 --- a/misc/core.func +++ b/misc/core.func @@ -154,16 +154,12 @@ silent() { # Check if the shell is using bash shell_check() { - local CURRENT_SHELL - CURRENT_SHELL="$(ps -p $$ -o comm= | xargs)" # trims whitespace - echo "DEBUG: Detected shell is: '$CURRENT_SHELL'" - - if [[ -z "$BASH_VERSION" ]]; then + if [[ "$(ps -p $$ -o comm=)" != "bash" ]]; then clear - msg_error "This script requires bash, but current shell is: $CURRENT_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..." sleep 2 - exit 1 + exit fi } @@ -223,6 +219,39 @@ arch_check() { fi } +# ------------------------------------------------------------------------------ +# ssh_check() +# +# - Detects if script is running over SSH +# - Warns user and recommends using Proxmox shell +# - User can choose to continue or abort +# ------------------------------------------------------------------------------ +ssh_check() { + # Skip if override + if [[ "${ALLOW_SSH:-0}" -eq 1 ]]; then return; fi + + if [ -n "$SSH_CLIENT" ]; then + local client_ip server_port + client_ip=$(awk '{print $1}' <<<"$SSH_CLIENT") + server_port=$(awk '{print $3}' <<<"$SSH_CLIENT") + + # Wenn client_ip = localhost oder host-IP → kein Warnpopup + if [[ "$client_ip" == "127.0.0.1" || "$client_ip" == "$(hostname -I | awk '{print $1}')" ]]; then + return + fi + + # Andernfalls Popup + if ! whiptail --backtitle "[dev] Proxmox VE Helper Scripts" \ + --defaultno \ + --title "SSH DETECTED" \ + --yesno "It's advisable to utilize the Proxmox shell rather than SSH..." 10 72; then + clear + echo "Exiting due to SSH usage." + exit 1 + fi + fi +} + # Function to download & save header files get_header() { local app_name=$(echo "${APP,,}" | tr -d ' ')