chore(helpers): update helper scripts for architecture refactoring
- commit
- 61d242c66a9f774b3b75be56edf350c6c36c3f2d
- author
- bnema · · 2025-10-21 06:14 UTC
- parent
- 7cca084
- signature
- unsigned
4 files · +60 -76
M install/bootstrap.sh +9 -0
| @@ -33,6 +33,15 @@ else | |||
| 33 | 33 | echo "[OK] gum already available" | |
| 34 | 34 | fi | |
| 35 | 35 | ||
| 36 | + | # Install jq for JSON parsing (presets) | |
| 37 | + | if ! command -v jq &>/dev/null; then | |
| 38 | + | echo "Installing jq for preset JSON parsing..." | |
| 39 | + | pacman -S --needed --noconfirm jq | |
| 40 | + | echo "[OK] jq installed" | |
| 41 | + | else | |
| 42 | + | echo "[OK] jq already available" | |
| 43 | + | fi | |
| 44 | + | ||
| 36 | 45 | # Any other critical dependencies that preflight needs can go here | |
| 37 | 46 | # Example: pacman -S --needed --noconfirm other-tool | |
| 38 | 47 | ||
| @@ -33,6 +33,15 @@ else | |||||
| 33 | echo "[OK] gum already available" | 33 | echo "[OK] gum already available" | ||
| 34 | fi | 34 | fi | ||
| 35 | 35 | ||||
| 36 | + | # Install jq for JSON parsing (presets) | |||
| 37 | + | if ! command -v jq &>/dev/null; then | |||
| 38 | + | echo "Installing jq for preset JSON parsing..." | |||
| 39 | + | pacman -S --needed --noconfirm jq | |||
| 40 | + | echo "[OK] jq installed" | |||
| 41 | + | else | |||
| 42 | + | echo "[OK] jq already available" | |||
| 43 | + | fi | |||
| 44 | + | ||||
| 36 | # Any other critical dependencies that preflight needs can go here | 45 | # Any other critical dependencies that preflight needs can go here | ||
| 37 | # Example: pacman -S --needed --noconfirm other-tool | 46 | # Example: pacman -S --needed --noconfirm other-tool | ||
| 38 | 47 | ||||
M install/helpers/cleanup.sh +10 -8
| @@ -15,7 +15,6 @@ CLEANUP_MODE="${1:-default}" | |||
| 15 | 15 | # Color codes for output | |
| 16 | 16 | RED='\033[0;31m' | |
| 17 | 17 | GREEN='\033[0;32m' | |
| 18 | - | YELLOW='\033[0;33m' | |
| 19 | 18 | NC='\033[0m' # No Color | |
| 20 | 19 | ||
| 21 | 20 | log_cleanup() { | |
| @@ -187,13 +186,16 @@ cleanup_full() { | |||
| 187 | 186 | ||
| 188 | 187 | if [ -d /mnt ]; then | |
| 189 | 188 | log_cleanup "Removing all files and directories in /mnt..." | |
| 190 | - | if rm -rf /mnt/* 2>/dev/null; then | |
| 191 | - | log_success "Removed /mnt content" | |
| 192 | - | else | |
| 193 | - | # Try alternate approach | |
| 194 | - | log_cleanup "Retry: Using find to remove /mnt content..." | |
| 195 | - | find /mnt -mindepth 1 -delete 2>/dev/null || true | |
| 196 | - | log_success "Removed /mnt content (with find)" | |
| 189 | + | # Safety check: only remove if /mnt exists and is not empty | |
| 190 | + | if [ -d "/mnt" ] && [ "$(ls -A /mnt 2>/dev/null)" ]; then | |
| 191 | + | if rm -rf /mnt/./* /mnt/..?* /mnt/.[!.]* 2>/dev/null; then | |
| 192 | + | log_success "Removed /mnt content" | |
| 193 | + | else | |
| 194 | + | # Try alternate approach | |
| 195 | + | log_cleanup "Retry: Using find to remove /mnt content..." | |
| 196 | + | find /mnt -mindepth 1 -delete 2>/dev/null || true | |
| 197 | + | log_success "Removed /mnt content (with find)" | |
| 198 | + | fi | |
| 197 | 199 | fi | |
| 198 | 200 | fi | |
| 199 | 201 | ||
| @@ -15,7 +15,6 @@ CLEANUP_MODE="${1:-default}" | |||||
| 15 | # Color codes for output | 15 | # Color codes for output | ||
| 16 | RED='\033[0;31m' | 16 | RED='\033[0;31m' | ||
| 17 | GREEN='\033[0;32m' | 17 | GREEN='\033[0;32m' | ||
| 18 | - | YELLOW='\033[0;33m' | |||
| 19 | NC='\033[0m' # No Color | 18 | NC='\033[0m' # No Color | ||
| 20 | 19 | ||||
| 21 | log_cleanup() { | 20 | log_cleanup() { | ||
| @@ -187,13 +186,16 @@ cleanup_full() { | |||||
| 187 | 186 | ||||
| 188 | if [ -d /mnt ]; then | 187 | if [ -d /mnt ]; then | ||
| 189 | log_cleanup "Removing all files and directories in /mnt..." | 188 | log_cleanup "Removing all files and directories in /mnt..." | ||
| 190 | - | if rm -rf /mnt/* 2>/dev/null; then | 189 | + | # Safety check: only remove if /mnt exists and is not empty |
| 191 | - | log_success "Removed /mnt content" | 190 | + | if [ -d "/mnt" ] && [ "$(ls -A /mnt 2>/dev/null)" ]; then |
| 192 | - | else | 191 | + | if rm -rf /mnt/./* /mnt/..?* /mnt/.[!.]* 2>/dev/null; then |
| 193 | - | # Try alternate approach | 192 | + | log_success "Removed /mnt content" |
| 194 | - | log_cleanup "Retry: Using find to remove /mnt content..." | 193 | + | else |
| 195 | - | find /mnt -mindepth 1 -delete 2>/dev/null || true | 194 | + | # Try alternate approach |
| 196 | - | log_success "Removed /mnt content (with find)" | 195 | + | log_cleanup "Retry: Using find to remove /mnt content..." |
| 196 | + | find /mnt -mindepth 1 -delete 2>/dev/null || true | |||
| 197 | + | log_success "Removed /mnt content (with find)" | |||
| 198 | + | fi | |||
| 197 | fi | 199 | fi | ||
| 198 | fi | 200 | fi | ||
| 199 | 201 | ||||
M install/helpers/logging.sh +8 -53
| @@ -1,60 +1,15 @@ | |||
| 1 | 1 | #!/bin/bash | |
| 2 | - | # Logging system for ArchUp installer - fixes variable export issues | |
| 3 | - | # Uses background process for log display instead of exec redirection | |
| 2 | + | # Logging system for ArchUp installer | |
| 3 | + | # All output logged to $ARCHUP_INSTALL_LOG_FILE | |
| 4 | + | # Spinners handle display, errors shown automatically via --show-error | |
| 4 | 5 | ||
| 5 | - | # Global variable for monitor background process | |
| 6 | - | monitor_pid="" | |
| 7 | - | ||
| 8 | - | # Background process to monitor and display log in real-time | |
| 6 | + | # No-op stubs for compatibility (log monitor removed) | |
| 9 | 7 | start_log_output() { | |
| 10 | - | local ANSI_SAVE_CURSOR="\033[s" | |
| 11 | - | local ANSI_RESTORE_CURSOR="\033[u" | |
| 12 | - | local ANSI_CLEAR_BELOW="\033[0J" | |
| 13 | - | local ANSI_HIDE_CURSOR="\033[?25l" | |
| 14 | - | local ANSI_RESET="\033[0m" | |
| 15 | - | local ANSI_GRAY="\033[90m" | |
| 16 | - | ||
| 17 | - | printf $ANSI_SAVE_CURSOR | |
| 18 | - | printf $ANSI_HIDE_CURSOR | |
| 19 | - | ||
| 20 | - | ( | |
| 21 | - | local log_lines=20 | |
| 22 | - | local max_line_width=$((LOGO_WIDTH - 4)) | |
| 23 | - | ||
| 24 | - | while true; do | |
| 25 | - | mapfile -t current_lines < <(tail -n $log_lines "$ARCHUP_INSTALL_LOG_FILE" 2>/dev/null) | |
| 26 | - | ||
| 27 | - | printf "${ANSI_RESTORE_CURSOR}${ANSI_CLEAR_BELOW}" | |
| 28 | - | ||
| 29 | - | for ((i = 0; i < log_lines; i++)); do | |
| 30 | - | line="${current_lines[i]:-}" | |
| 31 | - | ||
| 32 | - | if [ ${#line} -gt $max_line_width ]; then | |
| 33 | - | line="${line:0:$max_line_width}..." | |
| 34 | - | fi | |
| 35 | - | ||
| 36 | - | if [ -n "$line" ]; then | |
| 37 | - | printf "${ANSI_GRAY}${PADDING_LEFT_SPACES} → ${line}${ANSI_RESET}\n" | |
| 38 | - | else | |
| 39 | - | printf "${PADDING_LEFT_SPACES}\n" | |
| 40 | - | fi | |
| 41 | - | done | |
| 42 | - | ||
| 43 | - | sleep 0.1 | |
| 44 | - | done | |
| 45 | - | ) & | |
| 46 | - | monitor_pid=$! | |
| 8 | + | true | |
| 47 | 9 | } | |
| 48 | 10 | ||
| 49 | 11 | stop_log_output() { | |
| 50 | - | if [ -n "${monitor_pid:-}" ]; then | |
| 51 | - | kill $monitor_pid 2>/dev/null || true | |
| 52 | - | wait $monitor_pid 2>/dev/null || true | |
| 53 | - | unset monitor_pid | |
| 54 | - | ||
| 55 | - | # Clean up terminal state | |
| 56 | - | printf "\033[?25h" # Show cursor | |
| 57 | - | fi | |
| 12 | + | true | |
| 58 | 13 | } | |
| 59 | 14 | ||
| 60 | 15 | start_install_log() { | |
| @@ -98,8 +53,8 @@ run_logged() { | |||
| 98 | 53 | echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting: $script" >> "$ARCHUP_INSTALL_LOG_FILE" | |
| 99 | 54 | ||
| 100 | 55 | # Don't start/stop log monitor here - it runs continuously once started | |
| 101 | - | # Use bash -c to create a clean subshell and redirect output to log | |
| 102 | - | bash -c "source '$script'" </dev/null >> "$ARCHUP_INSTALL_LOG_FILE" 2>&1 | |
| 56 | + | # Source helpers in subshell before running the script so functions are available | |
| 57 | + | bash -c "source '$ARCHUP_INSTALL/helpers/all.sh' && source '$script'" </dev/null >> "$ARCHUP_INSTALL_LOG_FILE" 2>&1 | |
| 103 | 58 | ||
| 104 | 59 | local exit_code=$? | |
| 105 | 60 | ||
| @@ -1,60 +1,15 @@ | |||||
| 1 | #!/bin/bash | 1 | #!/bin/bash | ||
| 2 | - | # Logging system for ArchUp installer - fixes variable export issues | 2 | + | # Logging system for ArchUp installer |
| 3 | - | # Uses background process for log display instead of exec redirection | 3 | + | # All output logged to $ARCHUP_INSTALL_LOG_FILE |
| 4 | + | # Spinners handle display, errors shown automatically via --show-error | |||
| 4 | 5 | ||||
| 5 | - | # Global variable for monitor background process | 6 | + | # No-op stubs for compatibility (log monitor removed) |
| 6 | - | monitor_pid="" | |||
| 7 | - | ||||
| 8 | - | # Background process to monitor and display log in real-time | |||
| 9 | start_log_output() { | 7 | start_log_output() { | ||
| 10 | - | local ANSI_SAVE_CURSOR="\033[s" | 8 | + | true |
| 11 | - | local ANSI_RESTORE_CURSOR="\033[u" | |||
| 12 | - | local ANSI_CLEAR_BELOW="\033[0J" | |||
| 13 | - | local ANSI_HIDE_CURSOR="\033[?25l" | |||
| 14 | - | local ANSI_RESET="\033[0m" | |||
| 15 | - | local ANSI_GRAY="\033[90m" | |||
| 16 | - | ||||
| 17 | - | printf $ANSI_SAVE_CURSOR | |||
| 18 | - | printf $ANSI_HIDE_CURSOR | |||
| 19 | - | ||||
| 20 | - | ( | |||
| 21 | - | local log_lines=20 | |||
| 22 | - | local max_line_width=$((LOGO_WIDTH - 4)) | |||
| 23 | - | ||||
| 24 | - | while true; do | |||
| 25 | - | mapfile -t current_lines < <(tail -n $log_lines "$ARCHUP_INSTALL_LOG_FILE" 2>/dev/null) | |||
| 26 | - | ||||
| 27 | - | printf "${ANSI_RESTORE_CURSOR}${ANSI_CLEAR_BELOW}" | |||
| 28 | - | ||||
| 29 | - | for ((i = 0; i < log_lines; i++)); do | |||
| 30 | - | line="${current_lines[i]:-}" | |||
| 31 | - | ||||
| 32 | - | if [ ${#line} -gt $max_line_width ]; then | |||
| 33 | - | line="${line:0:$max_line_width}..." | |||
| 34 | - | fi | |||
| 35 | - | ||||
| 36 | - | if [ -n "$line" ]; then | |||
| 37 | - | printf "${ANSI_GRAY}${PADDING_LEFT_SPACES} → ${line}${ANSI_RESET}\n" | |||
| 38 | - | else | |||
| 39 | - | printf "${PADDING_LEFT_SPACES}\n" | |||
| 40 | - | fi | |||
| 41 | - | done | |||
| 42 | - | ||||
| 43 | - | sleep 0.1 | |||
| 44 | - | done | |||
| 45 | - | ) & | |||
| 46 | - | monitor_pid=$! | |||
| 47 | } | 9 | } | ||
| 48 | 10 | ||||
| 49 | stop_log_output() { | 11 | stop_log_output() { | ||
| 50 | - | if [ -n "${monitor_pid:-}" ]; then | 12 | + | true |
| 51 | - | kill $monitor_pid 2>/dev/null || true | |||
| 52 | - | wait $monitor_pid 2>/dev/null || true | |||
| 53 | - | unset monitor_pid | |||
| 54 | - | ||||
| 55 | - | # Clean up terminal state | |||
| 56 | - | printf "\033[?25h" # Show cursor | |||
| 57 | - | fi | |||
| 58 | } | 13 | } | ||
| 59 | 14 | ||||
| 60 | start_install_log() { | 15 | start_install_log() { | ||
| @@ -98,8 +53,8 @@ run_logged() { | |||||
| 98 | echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting: $script" >> "$ARCHUP_INSTALL_LOG_FILE" | 53 | echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting: $script" >> "$ARCHUP_INSTALL_LOG_FILE" | ||
| 99 | 54 | ||||
| 100 | # Don't start/stop log monitor here - it runs continuously once started | 55 | # Don't start/stop log monitor here - it runs continuously once started | ||
| 101 | - | # Use bash -c to create a clean subshell and redirect output to log | 56 | + | # Source helpers in subshell before running the script so functions are available |
| 102 | - | bash -c "source '$script'" </dev/null >> "$ARCHUP_INSTALL_LOG_FILE" 2>&1 | 57 | + | bash -c "source '$ARCHUP_INSTALL/helpers/all.sh' && source '$script'" </dev/null >> "$ARCHUP_INSTALL_LOG_FILE" 2>&1 |
| 103 | 58 | ||||
| 104 | local exit_code=$? | 59 | local exit_code=$? | ||
| 105 | 60 | ||||
M install/helpers/presentation.sh +33 -15
| @@ -43,23 +43,26 @@ export GUM_TABLE_PADDING="$PADDING" | |||
| 43 | 43 | export GUM_CONFIRM_PADDING="$PADDING" | |
| 44 | 44 | ||
| 45 | 45 | clear_logo() { | |
| 46 | - | printf "\033[H\033[2J" # Clear screen and move cursor to top-left | |
| 46 | + | # Redirect all output to stderr to prevent capture by command substitution | |
| 47 | + | { | |
| 48 | + | printf "\033[H\033[2J" # Clear screen and move cursor to top-left | |
| 47 | 49 | ||
| 48 | - | # ANSI color codes: cyan=36, white=37 | |
| 49 | - | local CYAN="\033[36m" | |
| 50 | - | local WHITE="\033[37m" | |
| 51 | - | local RESET="\033[0m" | |
| 52 | - | local split_pos=34 | |
| 50 | + | # ANSI color codes: cyan=36, white=37 | |
| 51 | + | local CYAN="\033[36m" | |
| 52 | + | local WHITE="\033[37m" | |
| 53 | + | local RESET="\033[0m" | |
| 54 | + | local split_pos=34 | |
| 53 | 55 | ||
| 54 | - | # Print with padding and color split | |
| 55 | - | printf "\n" # Top padding | |
| 56 | - | while IFS= read -r line; do | |
| 57 | - | if [ -n "$line" ]; then | |
| 58 | - | printf "%s${CYAN}%s${WHITE}%s${RESET}\n" "$PADDING_LEFT_SPACES" "${line:0:$split_pos}" "${line:$split_pos}" | |
| 59 | - | else | |
| 60 | - | printf "\n" | |
| 61 | - | fi | |
| 62 | - | done < "$LOGO_PATH" | |
| 56 | + | # Print with padding and color split | |
| 57 | + | printf "\n" # Top padding | |
| 58 | + | while IFS= read -r line; do | |
| 59 | + | if [ -n "$line" ]; then | |
| 60 | + | printf "%s${CYAN}%s${WHITE}%s${RESET}\n" "$PADDING_LEFT_SPACES" "${line:0:$split_pos}" "${line:$split_pos}" | |
| 61 | + | else | |
| 62 | + | printf "\n" | |
| 63 | + | fi | |
| 64 | + | done < "$LOGO_PATH" | |
| 65 | + | } >&2 | |
| 63 | 66 | } | |
| 64 | 67 | ||
| 65 | 68 | # Show cursor (used in cleanup) | |
| @@ -71,3 +74,18 @@ show_cursor() { | |||
| 71 | 74 | hide_cursor() { | |
| 72 | 75 | printf "\033[?25l" | |
| 73 | 76 | } | |
| 77 | + | ||
| 78 | + | # Run a command with a gum spinner, logging output to file | |
| 79 | + | # Usage: run_with_spinner "Title text" "command to run" | |
| 80 | + | run_with_spinner() { | |
| 81 | + | local title="$1" | |
| 82 | + | local command="$2" | |
| 83 | + | ||
| 84 | + | # Redirect only stderr to terminal for gum display | |
| 85 | + | # Command output goes to log file, spinner animation displays on terminal | |
| 86 | + | if gum spin --spinner dot --title "$title" -- bash -c "$command >> \"$ARCHUP_INSTALL_LOG_FILE\" 2>&1" 2>/dev/tty; then | |
| 87 | + | return 0 | |
| 88 | + | else | |
| 89 | + | return 1 | |
| 90 | + | fi | |
| 91 | + | } | |
| @@ -43,23 +43,26 @@ export GUM_TABLE_PADDING="$PADDING" | |||||
| 43 | export GUM_CONFIRM_PADDING="$PADDING" | 43 | export GUM_CONFIRM_PADDING="$PADDING" | ||
| 44 | 44 | ||||
| 45 | clear_logo() { | 45 | clear_logo() { | ||
| 46 | - | printf "\033[H\033[2J" # Clear screen and move cursor to top-left | 46 | + | # Redirect all output to stderr to prevent capture by command substitution |
| 47 | + | { | |||
| 48 | + | printf "\033[H\033[2J" # Clear screen and move cursor to top-left | |||
| 47 | 49 | ||||
| 48 | - | # ANSI color codes: cyan=36, white=37 | 50 | + | # ANSI color codes: cyan=36, white=37 |
| 49 | - | local CYAN="\033[36m" | 51 | + | local CYAN="\033[36m" |
| 50 | - | local WHITE="\033[37m" | 52 | + | local WHITE="\033[37m" |
| 51 | - | local RESET="\033[0m" | 53 | + | local RESET="\033[0m" |
| 52 | - | local split_pos=34 | 54 | + | local split_pos=34 |
| 53 | 55 | ||||
| 54 | - | # Print with padding and color split | 56 | + | # Print with padding and color split |
| 55 | - | printf "\n" # Top padding | 57 | + | printf "\n" # Top padding |
| 56 | - | while IFS= read -r line; do | 58 | + | while IFS= read -r line; do |
| 57 | - | if [ -n "$line" ]; then | 59 | + | if [ -n "$line" ]; then |
| 58 | - | printf "%s${CYAN}%s${WHITE}%s${RESET}\n" "$PADDING_LEFT_SPACES" "${line:0:$split_pos}" "${line:$split_pos}" | 60 | + | printf "%s${CYAN}%s${WHITE}%s${RESET}\n" "$PADDING_LEFT_SPACES" "${line:0:$split_pos}" "${line:$split_pos}" |
| 59 | - | else | 61 | + | else |
| 60 | - | printf "\n" | 62 | + | printf "\n" |
| 61 | - | fi | 63 | + | fi |
| 62 | - | done < "$LOGO_PATH" | 64 | + | done < "$LOGO_PATH" |
| 65 | + | } >&2 | |||
| 63 | } | 66 | } | ||
| 64 | 67 | ||||
| 65 | # Show cursor (used in cleanup) | 68 | # Show cursor (used in cleanup) | ||
| @@ -71,3 +74,18 @@ show_cursor() { | |||||
| 71 | hide_cursor() { | 74 | hide_cursor() { | ||
| 72 | printf "\033[?25l" | 75 | printf "\033[?25l" | ||
| 73 | } | 76 | } | ||
| 77 | + | ||||
| 78 | + | # Run a command with a gum spinner, logging output to file | |||
| 79 | + | # Usage: run_with_spinner "Title text" "command to run" | |||
| 80 | + | run_with_spinner() { | |||
| 81 | + | local title="$1" | |||
| 82 | + | local command="$2" | |||
| 83 | + | ||||
| 84 | + | # Redirect only stderr to terminal for gum display | |||
| 85 | + | # Command output goes to log file, spinner animation displays on terminal | |||
| 86 | + | if gum spin --spinner dot --title "$title" -- bash -c "$command >> \"$ARCHUP_INSTALL_LOG_FILE\" 2>&1" 2>/dev/tty; then | |||
| 87 | + | return 0 | |||
| 88 | + | else | |||
| 89 | + | return 1 | |||
| 90 | + | fi | |||
| 91 | + | } | |||