fix(args): move --help check before any side effects
- commit
- b91a04a3eb9c229d384c4c07e2ff8b5a2d3ca6a8
- author
- bnema · · 2025-10-21 21:42 UTC
- committer
- bnema · · 2025-10-21 21:07 UTC
- parent
- 090ebff
- signature
- unsigned
1 file · +21 -20
M install.sh +21 -20
| @@ -4,26 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | set -eo pipefail | |
| 6 | 6 | ||
| 7 | - | # Export global paths first (needed for re-exec) | |
| 8 | - | export ARCHUP_PATH="${ARCHUP_PATH:-$HOME/.local/share/archup}" | |
| 9 | - | export ARCHUP_INSTALL="$ARCHUP_PATH/install" | |
| 10 | - | ||
| 11 | - | # If stdin is not a TTY (piped from curl), save and re-exec with TTY | |
| 12 | - | if [ ! -t 0 ]; then | |
| 13 | - | # Save script to proper location | |
| 14 | - | mkdir -p "$ARCHUP_PATH" | |
| 15 | - | INSTALL_SCRIPT="$ARCHUP_PATH/install.sh" | |
| 16 | - | cat > "$INSTALL_SCRIPT" | |
| 17 | - | chmod +x "$INSTALL_SCRIPT" | |
| 18 | - | # Re-exec with TTY connected | |
| 19 | - | exec < /dev/tty "$INSTALL_SCRIPT" "$@" | |
| 20 | - | fi | |
| 21 | - | export ARCHUP_INSTALL_LOG_FILE="/var/log/archup-install.log" | |
| 22 | - | export ARCHUP_INSTALL_CONFIG="/var/log/archup-install.conf" | |
| 23 | - | export ARCHUP_REPO_URL="${ARCHUP_REPO_URL:-https://github.com/bnema/archup}" | |
| 24 | - | export ARCHUP_RAW_URL="${ARCHUP_RAW_URL:-https://raw.githubusercontent.com/bnema/archup/main}" | |
| 25 | - | ||
| 26 | - | # Handle help flag early (doesn't need any files) | |
| 7 | + | # Handle help flag FIRST - before any side effects | |
| 27 | 8 | if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | |
| 28 | 9 | cat << 'HELP' | |
| 29 | 10 | Usage: install.sh [OPTIONS] | |
| @@ -42,6 +23,26 @@ HELP | |||
| 42 | 23 | exit 0 | |
| 43 | 24 | fi | |
| 44 | 25 | ||
| 26 | + | # Export global paths (needed for re-exec) | |
| 27 | + | export ARCHUP_PATH="${ARCHUP_PATH:-$HOME/.local/share/archup}" | |
| 28 | + | export ARCHUP_INSTALL="$ARCHUP_PATH/install" | |
| 29 | + | ||
| 30 | + | # If stdin is not a TTY (piped from curl), save and re-exec with TTY | |
| 31 | + | if [ ! -t 0 ]; then | |
| 32 | + | # Save script to proper location | |
| 33 | + | mkdir -p "$ARCHUP_PATH" | |
| 34 | + | INSTALL_SCRIPT="$ARCHUP_PATH/install.sh" | |
| 35 | + | cat > "$INSTALL_SCRIPT" | |
| 36 | + | chmod +x "$INSTALL_SCRIPT" | |
| 37 | + | # Re-exec with TTY connected | |
| 38 | + | exec < /dev/tty "$INSTALL_SCRIPT" "$@" | |
| 39 | + | fi | |
| 40 | + | ||
| 41 | + | export ARCHUP_INSTALL_LOG_FILE="/var/log/archup-install.log" | |
| 42 | + | export ARCHUP_INSTALL_CONFIG="/var/log/archup-install.conf" | |
| 43 | + | export ARCHUP_REPO_URL="${ARCHUP_REPO_URL:-https://github.com/bnema/archup}" | |
| 44 | + | export ARCHUP_RAW_URL="${ARCHUP_RAW_URL:-https://raw.githubusercontent.com/bnema/archup/main}" | |
| 45 | + | ||
| 45 | 46 | # Bootstrap FIRST: Install gum and jq (required for download script) | |
| 46 | 47 | if [ ! -d "$ARCHUP_INSTALL" ]; then | |
| 47 | 48 | # First time running from curl, need to download bootstrap | |
| @@ -4,26 +4,7 @@ | |||||
| 4 | 4 | ||||
| 5 | set -eo pipefail | 5 | set -eo pipefail | ||
| 6 | 6 | ||||
| 7 | - | # Export global paths first (needed for re-exec) | 7 | + | # Handle help flag FIRST - before any side effects |
| 8 | - | export ARCHUP_PATH="${ARCHUP_PATH:-$HOME/.local/share/archup}" | |||
| 9 | - | export ARCHUP_INSTALL="$ARCHUP_PATH/install" | |||
| 10 | - | ||||
| 11 | - | # If stdin is not a TTY (piped from curl), save and re-exec with TTY | |||
| 12 | - | if [ ! -t 0 ]; then | |||
| 13 | - | # Save script to proper location | |||
| 14 | - | mkdir -p "$ARCHUP_PATH" | |||
| 15 | - | INSTALL_SCRIPT="$ARCHUP_PATH/install.sh" | |||
| 16 | - | cat > "$INSTALL_SCRIPT" | |||
| 17 | - | chmod +x "$INSTALL_SCRIPT" | |||
| 18 | - | # Re-exec with TTY connected | |||
| 19 | - | exec < /dev/tty "$INSTALL_SCRIPT" "$@" | |||
| 20 | - | fi | |||
| 21 | - | export ARCHUP_INSTALL_LOG_FILE="/var/log/archup-install.log" | |||
| 22 | - | export ARCHUP_INSTALL_CONFIG="/var/log/archup-install.conf" | |||
| 23 | - | export ARCHUP_REPO_URL="${ARCHUP_REPO_URL:-https://github.com/bnema/archup}" | |||
| 24 | - | export ARCHUP_RAW_URL="${ARCHUP_RAW_URL:-https://raw.githubusercontent.com/bnema/archup/main}" | |||
| 25 | - | ||||
| 26 | - | # Handle help flag early (doesn't need any files) | |||
| 27 | if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | 8 | if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | ||
| 28 | cat << 'HELP' | 9 | cat << 'HELP' | ||
| 29 | Usage: install.sh [OPTIONS] | 10 | Usage: install.sh [OPTIONS] | ||
| @@ -42,6 +23,26 @@ HELP | |||||
| 42 | exit 0 | 23 | exit 0 | ||
| 43 | fi | 24 | fi | ||
| 44 | 25 | ||||
| 26 | + | # Export global paths (needed for re-exec) | |||
| 27 | + | export ARCHUP_PATH="${ARCHUP_PATH:-$HOME/.local/share/archup}" | |||
| 28 | + | export ARCHUP_INSTALL="$ARCHUP_PATH/install" | |||
| 29 | + | ||||
| 30 | + | # If stdin is not a TTY (piped from curl), save and re-exec with TTY | |||
| 31 | + | if [ ! -t 0 ]; then | |||
| 32 | + | # Save script to proper location | |||
| 33 | + | mkdir -p "$ARCHUP_PATH" | |||
| 34 | + | INSTALL_SCRIPT="$ARCHUP_PATH/install.sh" | |||
| 35 | + | cat > "$INSTALL_SCRIPT" | |||
| 36 | + | chmod +x "$INSTALL_SCRIPT" | |||
| 37 | + | # Re-exec with TTY connected | |||
| 38 | + | exec < /dev/tty "$INSTALL_SCRIPT" "$@" | |||
| 39 | + | fi | |||
| 40 | + | ||||
| 41 | + | export ARCHUP_INSTALL_LOG_FILE="/var/log/archup-install.log" | |||
| 42 | + | export ARCHUP_INSTALL_CONFIG="/var/log/archup-install.conf" | |||
| 43 | + | export ARCHUP_REPO_URL="${ARCHUP_REPO_URL:-https://github.com/bnema/archup}" | |||
| 44 | + | export ARCHUP_RAW_URL="${ARCHUP_RAW_URL:-https://raw.githubusercontent.com/bnema/archup/main}" | |||
| 45 | + | ||||
| 45 | # Bootstrap FIRST: Install gum and jq (required for download script) | 46 | # Bootstrap FIRST: Install gum and jq (required for download script) | ||
| 46 | if [ ! -d "$ARCHUP_INSTALL" ]; then | 47 | if [ ! -d "$ARCHUP_INSTALL" ]; then | ||
| 47 | # First time running from curl, need to download bootstrap | 48 | # First time running from curl, need to download bootstrap | ||