diff options
| -rwxr-xr-x | archsetup | 37 |
1 files changed, 28 insertions, 9 deletions
@@ -586,19 +586,38 @@ git_install() { local prog_name prog_name="$(basename "$1" .git)" local build_dir="$source_dir/$prog_name" + local attempt=1 + local last_exit_code=0 display "task" "building & installing $prog_name from source" - if ! (sudo -u "$username" git clone --depth 1 "$1" "$build_dir" >> "$logfile" 2>&1); then - error_warn "cloning $prog_name - directory may exist, removing and retrying" "$?" - safe_rm_rf "$build_dir" "$source_dir" >> "$logfile" 2>&1 || \ - error_warn "removing existing directory for $prog_name" "$?" - sudo -u "$username" git clone --depth 1 "$1" "$build_dir" >> "$logfile" 2>&1 || \ - error_fatal "re-cloning $prog_name after cleanup" "$?" - fi + while [ $attempt -le $MAX_INSTALL_RETRIES ]; do + # Start each attempt from a clean slate. A leftover dir from a prior + # attempt (or a failed earlier install) makes git clone refuse to write. + if [ -e "$build_dir" ]; then + safe_rm_rf "$build_dir" "$source_dir" >> "$logfile" 2>&1 || \ + error_warn "removing existing directory for $prog_name" "$?" + fi + + # clone && build as one command list, not an `if`-compound — capturing + # $? after `if ...; then ...; fi` reads the if's status (0 when the + # condition is false), masking the real failure. Same trap retry_install + # documents. The list's exit code is the clone's code on a clone failure, + # make's code on a build failure, 0 only when both succeed. + sudo -u "$username" git clone --depth 1 "$1" "$build_dir" >> "$logfile" 2>&1 \ + && (cd "$build_dir" && make install >> "$logfile" 2>&1) + last_exit_code=$? + if [ $last_exit_code -eq 0 ]; then + return 0 + fi + + attempt=$((attempt + 1)) + if [ $attempt -le $MAX_INSTALL_RETRIES ]; then + display "task" "retrying $prog_name (attempt $attempt/$MAX_INSTALL_RETRIES)" + fi + done - (cd "$build_dir" && make install >> "$logfile" 2>&1) || \ - error_warn "building $prog_name from source" "$?" + error_warn "building $prog_name from source" "$last_exit_code" } # PIP Install (using pipx for isolated environments) |
