v3-revamp
This commit is contained in:
+38
-8
@@ -4,21 +4,40 @@ set -uo pipefail
|
||||
#------------------------------------------
|
||||
# Color helpers (printf-safe, no tput)
|
||||
#------------------------------------------
|
||||
# ... (Keep your color definitions here) ...
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
CYAN='\033[0;36m'
|
||||
PURPLE='\033[0;35m'
|
||||
BLUE='\033[0;34m'
|
||||
GRAY='\033[0;37m'
|
||||
BOLD='\033[1m'
|
||||
RESET='\033[0m'
|
||||
|
||||
# Disable colors if output is not a terminal
|
||||
if [ ! -t 1 ]; then
|
||||
RED='' GREEN='' YELLOW='' CYAN='' PURPLE='' BLUE='' GRAY='' BOLD='' RESET=''
|
||||
fi
|
||||
|
||||
color_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; }
|
||||
color_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; }
|
||||
color_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; }
|
||||
color_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; }
|
||||
color_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; }
|
||||
|
||||
#------------------------------------------
|
||||
# Debug Flag Initialization (MUST BE OUTSIDE THE GUARD)
|
||||
# Debug Flag Initialization (Outside Guard)
|
||||
#------------------------------------------
|
||||
# We check if $DEBUG_MODE is already true (passed down) or if -d was passed
|
||||
# Checks if DEBUG_MODE is already true (passed from parent) or via arguments
|
||||
if [[ "${DEBUG_MODE:-false}" == "true" || "${1:-}" == "-d" || "${1:-}" == "--debug" ]]; then
|
||||
export DEBUG_MODE=true
|
||||
else
|
||||
export DEBUG_MODE=false
|
||||
set -e # Enable immediate exit on error only if NOT debugging
|
||||
set -e # Enable immediate exit on error only if NOT debugging step-by-step
|
||||
fi
|
||||
|
||||
#------------------------------------------
|
||||
# Debug Pause Helper (MUST BE OUTSIDE THE GUARD)
|
||||
# Debug Pause Helper (Outside Guard)
|
||||
#------------------------------------------
|
||||
pause_if_debug() {
|
||||
if [[ "${DEBUG_MODE:-false}" == "true" ]]; then
|
||||
@@ -37,16 +56,25 @@ pause_if_debug() {
|
||||
# ==========================================
|
||||
# GUARD WRAPPER START
|
||||
# ==========================================
|
||||
# This entire interactive block is skipped if the script is 'sourced'
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
clear # Clean screen only when launching the main menu script directly
|
||||
|
||||
clear # Wipe the terminal history view cleanly for the main menu execution
|
||||
|
||||
if [[ "$DEBUG_MODE" == "true" ]]; then
|
||||
color_red "!!! DEBUG MODE ENABLED !!!"
|
||||
color_red "The script will pause after each major section."
|
||||
echo
|
||||
fi
|
||||
|
||||
#------------------------------------------
|
||||
# Script Version 3.0
|
||||
#------------------------------------------
|
||||
echo
|
||||
color_yellow "----------------------------------------------------------------"
|
||||
color_yellow "Script version 3.0"
|
||||
color_yellow "----------------------------------------------------------------"
|
||||
echo
|
||||
|
||||
#------------------------------------------
|
||||
# OS Detection
|
||||
@@ -250,7 +278,7 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
esac
|
||||
|
||||
#------------------------------------------
|
||||
# Preflight check & run
|
||||
# Preflight check & run (Using source)
|
||||
#------------------------------------------
|
||||
if [[ ! -f "$OS_SCRIPT" ]]; then
|
||||
color_red "ERROR: OS script not found: $OS_SCRIPT"
|
||||
@@ -263,7 +291,9 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
|
||||
echo
|
||||
color_cyan "Running OS script: $OS_SCRIPT"
|
||||
bash "$OS_SCRIPT" || {
|
||||
|
||||
# Crucial change: We source the script instead of launching it via 'bash'
|
||||
source "$OS_SCRIPT" || {
|
||||
color_red "ERROR: OS script failed: $OS_SCRIPT"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user