Refactor message output and improve SSH check logic

Replaces many msg_info calls with msg_custom for more consistent and expressive status messages in build.func. Refines SSH client detection in core.func to better distinguish local, subnet, and external connections, and adds additional warnings for external SSH usage.
This commit is contained in:
CanbiZ 2025-11-04 16:38:46 +01:00
parent 2ff12b1f01
commit 8ccd06b596
2 changed files with 39 additions and 26 deletions

View File

@ -220,7 +220,7 @@ maxkeys_check() {
exit 1 exit 1
fi fi
echo -e "${CM}${GN} All kernel key limits are within safe thresholds.${CL}" # Silent success - only show errors if they exist
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -351,7 +351,7 @@ base_settings() {
if [[ -n "$APT_CACHER_IP" && "$APT_CACHER" == "yes" ]]; then if [[ -n "$APT_CACHER_IP" && "$APT_CACHER" == "yes" ]]; then
if ! curl -s --connect-timeout 2 "http://${APT_CACHER_IP}:3142" >/dev/null 2>&1; then if ! curl -s --connect-timeout 2 "http://${APT_CACHER_IP}:3142" >/dev/null 2>&1; then
msg_warn "APT Cacher configured but not reachable at ${APT_CACHER_IP}:3142" msg_warn "APT Cacher configured but not reachable at ${APT_CACHER_IP}:3142"
msg_info "Disabling APT Cacher for this installation" msg_custom "⚠️" "${YW}" "Disabling APT Cacher for this installation"
APT_CACHER="" APT_CACHER=""
APT_CACHER_IP="" APT_CACHER_IP=""
else else
@ -1497,7 +1497,7 @@ maybe_offer_save_app_defaults() {
break break
;; ;;
"Keep Current") "Keep Current")
msg_info "Keeping current app defaults: ${app_vars_path}" msg_custom "" "${BL}" "Keeping current app defaults: ${app_vars_path}"
break break
;; ;;
"View Diff") "View Diff")
@ -1506,7 +1506,7 @@ maybe_offer_save_app_defaults() {
--scrolltext --textbox "$diff_tmp" 25 100 --scrolltext --textbox "$diff_tmp" 25 100
;; ;;
"Cancel" | *) "Cancel" | *)
msg_info "Canceled. No changes to app defaults." msg_custom "🚫" "${YW}" "Canceled. No changes to app defaults."
break break
;; ;;
esac esac
@ -2212,7 +2212,7 @@ build_container() {
# Check for Intel GPU - look for Intel vendor ID [8086] # Check for Intel GPU - look for Intel vendor ID [8086]
if echo "$pci_vga_info" | grep -q "\[8086:"; then if echo "$pci_vga_info" | grep -q "\[8086:"; then
msg_info "Detected Intel GPU" msg_custom "🎮" "${BL}" "Detected Intel GPU"
if [[ -d /dev/dri ]]; then if [[ -d /dev/dri ]]; then
for d in /dev/dri/renderD* /dev/dri/card*; do for d in /dev/dri/renderD* /dev/dri/card*; do
[[ -e "$d" ]] && INTEL_DEVICES+=("$d") [[ -e "$d" ]] && INTEL_DEVICES+=("$d")
@ -2222,7 +2222,7 @@ build_container() {
# Check for AMD GPU - look for AMD vendor IDs [1002] (AMD/ATI) or [1022] (AMD) # Check for AMD GPU - look for AMD vendor IDs [1002] (AMD/ATI) or [1022] (AMD)
if echo "$pci_vga_info" | grep -qE "\[1002:|\[1022:"; then if echo "$pci_vga_info" | grep -qE "\[1002:|\[1022:"; then
msg_info "Detected AMD GPU" msg_custom "🎮" "${RD}" "Detected AMD GPU"
if [[ -d /dev/dri ]]; then if [[ -d /dev/dri ]]; then
# Only add if not already claimed by Intel # Only add if not already claimed by Intel
if [[ ${#INTEL_DEVICES[@]} -eq 0 ]]; then if [[ ${#INTEL_DEVICES[@]} -eq 0 ]]; then
@ -2235,7 +2235,7 @@ build_container() {
# Check for NVIDIA GPU - look for NVIDIA vendor ID [10de] # Check for NVIDIA GPU - look for NVIDIA vendor ID [10de]
if echo "$pci_vga_info" | grep -q "\[10de:"; then if echo "$pci_vga_info" | grep -q "\[10de:"; then
msg_info "Detected NVIDIA GPU" msg_custom "🎮" "${GN}" "Detected NVIDIA GPU"
# Simple passthrough - just bind /dev/nvidia* devices if they exist # Simple passthrough - just bind /dev/nvidia* devices if they exist
for d in /dev/nvidia* /dev/nvidiactl /dev/nvidia-modeset /dev/nvidia-uvm /dev/nvidia-uvm-tools; do for d in /dev/nvidia* /dev/nvidiactl /dev/nvidia-modeset /dev/nvidia-uvm /dev/nvidia-uvm-tools; do
@ -2243,10 +2243,10 @@ build_container() {
done done
if [[ ${#NVIDIA_DEVICES[@]} -gt 0 ]]; then if [[ ${#NVIDIA_DEVICES[@]} -gt 0 ]]; then
msg_info "Found ${#NVIDIA_DEVICES[@]} NVIDIA device(s) for passthrough" msg_custom "🎮" "${GN}" "Found ${#NVIDIA_DEVICES[@]} NVIDIA device(s) for passthrough"
else else
msg_warn "NVIDIA GPU detected via PCI but no /dev/nvidia* devices found" msg_warn "NVIDIA GPU detected via PCI but no /dev/nvidia* devices found"
msg_info "Skipping NVIDIA passthrough (host drivers may not be loaded)" msg_custom "" "${YW}" "Skipping NVIDIA passthrough (host drivers may not be loaded)"
fi fi
fi fi
@ -2307,7 +2307,7 @@ EOF
fi fi
if [[ $gpu_count -eq 0 ]]; then if [[ $gpu_count -eq 0 ]]; then
msg_info "No GPU devices found for passthrough" msg_custom "" "${YW}" "No GPU devices found for passthrough"
return 0 return 0
fi fi
@ -2316,7 +2316,7 @@ EOF
if [[ $gpu_count -eq 1 ]]; then if [[ $gpu_count -eq 1 ]]; then
# Automatic selection for single GPU # Automatic selection for single GPU
selected_gpu="${available_gpus[0]}" selected_gpu="${available_gpus[0]}"
msg_info "Automatically configuring ${selected_gpu} GPU passthrough" msg_custom "⚙️" "${GN}" "Automatically configuring ${selected_gpu} GPU passthrough"
else else
# Multiple GPUs - ask user # Multiple GPUs - ask user
echo -e "\n${INFO} Multiple GPU types detected:" echo -e "\n${INFO} Multiple GPU types detected:"
@ -2407,7 +2407,7 @@ EOF
# Coral TPU passthrough # Coral TPU passthrough
if [[ -e /dev/apex_0 ]]; then if [[ -e /dev/apex_0 ]]; then
msg_info "Detected Coral TPU - configuring passthrough" msg_custom "🔌" "${BL}" "Detected Coral TPU - configuring passthrough"
echo "lxc.mount.entry: /dev/apex_0 dev/apex_0 none bind,optional,create=file" >>"$LXC_CONFIG" echo "lxc.mount.entry: /dev/apex_0 dev/apex_0 none bind,optional,create=file" >>"$LXC_CONFIG"
fi fi
} }
@ -2546,7 +2546,7 @@ destroy_lxc() {
fi fi
;; ;;
"" | n | no) "" | n | no)
msg_info "Container was not removed." msg_custom "" "${BL}" "Container was not removed."
;; ;;
*) *)
msg_warn "Invalid response. Container was not removed." msg_warn "Invalid response. Container was not removed."
@ -2599,7 +2599,7 @@ fix_gpu_gids() {
fi fi
# Silent operation to avoid spinner conflicts # Silent operation to avoid spinner conflicts
echo -e "\n 🔧 Detecting and setting correct GPU group IDs" msg_custom "🔧" "${BL}" "Detecting and setting correct GPU group IDs"
# Ermittle die tatsächlichen GIDs aus dem Container # Ermittle die tatsächlichen GIDs aus dem Container
local video_gid=$(pct exec "$CTID" -- sh -c "getent group video 2>/dev/null | cut -d: -f3") local video_gid=$(pct exec "$CTID" -- sh -c "getent group video 2>/dev/null | cut -d: -f3")
@ -2620,7 +2620,7 @@ fix_gpu_gids() {
[[ -z "$render_gid" ]] && render_gid="104" # Ultimate fallback [[ -z "$render_gid" ]] && render_gid="104" # Ultimate fallback
fi fi
echo " Container GIDs detected - video:${video_gid}, render:${render_gid}" msg_custom "" "${DGN}" "Container GIDs detected - video:${video_gid}, render:${render_gid}"
# Prüfe ob die GIDs von den Defaults abweichen # Prüfe ob die GIDs von den Defaults abweichen
local need_update=0 local need_update=0
@ -2629,7 +2629,7 @@ fix_gpu_gids() {
fi fi
if [[ $need_update -eq 1 ]]; then if [[ $need_update -eq 1 ]]; then
echo " 🔄 Updating device GIDs in container config" msg_custom "🔄" "${YW}" "Updating device GIDs in container config"
# Stoppe Container für Config-Update # Stoppe Container für Config-Update
pct stop "$CTID" >/dev/null 2>&1 pct stop "$CTID" >/dev/null 2>&1
@ -2667,9 +2667,9 @@ fix_gpu_gids() {
pct start "$CTID" >/dev/null 2>&1 pct start "$CTID" >/dev/null 2>&1
sleep 3 sleep 3
echo -e " ✔️ Device GIDs updated successfully\n" msg_ok "Device GIDs updated successfully"
else else
echo -e " ✔️ Device GIDs are already correct\n" msg_ok "Device GIDs are already correct"
fi fi
if [[ "$CT_TYPE" == "0" ]]; then if [[ "$CT_TYPE" == "0" ]]; then
pct exec "$CTID" -- bash -c " pct exec "$CTID" -- bash -c "
@ -3081,7 +3081,7 @@ create_lxc_container() {
exit 225 exit 225
fi fi
else else
msg_info "Installation cancelled" msg_custom "🚫" "${YW}" "Installation cancelled"
exit 0 exit 0
fi fi
else else
@ -3174,7 +3174,7 @@ create_lxc_container() {
exit 220 exit 220
} }
else else
msg_info "Installation cancelled" msg_custom "🚫" "${YW}" "Installation cancelled"
exit 1 exit 1
fi fi
else else
@ -3187,9 +3187,9 @@ create_lxc_container() {
# Validate that we found a template # Validate that we found a template
if [[ -z "$TEMPLATE" ]]; then if [[ -z "$TEMPLATE" ]]; then
msg_error "No template found for ${PCT_OSTYPE} ${PCT_OSVERSION}" msg_error "No template found for ${PCT_OSTYPE} ${PCT_OSVERSION}"
msg_info "Please check:" msg_custom "" "${YW}" "Please check:"
msg_info " - Is pveam catalog available? (run: pveam available -section system)" msg_custom " •" "${YW}" "Is pveam catalog available? (run: pveam available -section system)"
msg_info " - Does the template exist for your OS version?" msg_custom " •" "${YW}" "Does the template exist for your OS version?"
exit 225 exit 225
fi fi
@ -3227,7 +3227,7 @@ create_lxc_container() {
TEMPLATE="$ONLINE_TEMPLATE" TEMPLATE="$ONLINE_TEMPLATE"
NEED_DOWNLOAD=1 NEED_DOWNLOAD=1
else else
msg_info "Continuing with local template $TEMPLATE" msg_custom "" "${BL}" "Continuing with local template $TEMPLATE"
fi fi
fi fi

View File

@ -231,11 +231,24 @@ ssh_check() {
local client_ip=$(awk '{print $1}' <<<"$SSH_CLIENT") local client_ip=$(awk '{print $1}' <<<"$SSH_CLIENT")
local host_ip=$(hostname -I | awk '{print $1}') local host_ip=$(hostname -I | awk '{print $1}')
if [[ "$client_ip" == "127.0.0.1" || "$client_ip" == "$host_ip" ]]; then # Check if connection is local (Proxmox WebUI or same machine)
# - localhost (127.0.0.1, ::1)
# - same IP as host
# - local network range (10.x, 172.16-31.x, 192.168.x)
if [[ "$client_ip" == "127.0.0.1" || "$client_ip" == "::1" || "$client_ip" == "$host_ip" ]]; then
return return
fi fi
# Check if client is in same local network (optional, safer approach)
local host_subnet=$(echo "$host_ip" | cut -d. -f1-3)
local client_subnet=$(echo "$client_ip" | cut -d. -f1-3)
if [[ "$host_subnet" == "$client_subnet" ]]; then
return
fi
# Only warn for truly external connections
msg_warn "Running via external SSH (client: $client_ip)." msg_warn "Running via external SSH (client: $client_ip)."
msg_warn "For better stability, consider using the Proxmox Shell (Console) instead."
fi fi
} }