Add rerun()

This commit is contained in:
2026-01-21 06:47:31 -05:00
parent 869e0995dd
commit 459185ec9d

View File

@@ -236,13 +236,10 @@ init() {
declare -g USER
declare -g SCRIPT_PATH; SCRIPT_PATH=$(readlink -f "${BASH_SOURCE[0]}")
declare -g SCRIPT_DIR; SCRIPT_DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
declare -gi SCRIPT_IS_PIPED=0
# Detect if script is being piped (SCRIPT_PATH won't be a regular file)
if [[ ! -f $SCRIPT_PATH ]]; then
declare -g SCRIPT_IS_PIPED=1
else
declare -g SCRIPT_IS_PIPED=0
fi
[[ ! -f $SCRIPT_PATH ]] && SCRIPT_IS_PIPED=1
declare -g OUTPUT_DIR="$SCRIPT_DIR/output"
declare -g CREATEREPO_WEBROOT="/var/www/jriver"
@@ -265,7 +262,7 @@ init() {
fi
# Run the self-updater if enabled
((SELF_UPDATE_SWITCH)) && update "$@"
((SELF_UPDATE_SWITCH)) && ((! SCRIPT_IS_PIPED)) && update "$@"
# Check that the .jriver directory is owned by the user
((YES_SWITCH)) || fix_permissions "$HOME/.jriver" "$USER"
@@ -1054,7 +1051,7 @@ install_mc_deb() {
execute sudo rm -f "$temp_deb"
if ask_ok "Remove source DEB and retry?"; then
execute sudo rm -f "$MC_DEB"
exec bash "$SCRIPT_PATH" "$@" "--no-update"
rerun "$@"
fi
return 1
fi
@@ -1716,7 +1713,7 @@ update() {
# If the commit hash has changed, an update occurred
if [[ "$before_pull_hash" != $(git -C "$SCRIPT_DIR" rev-parse HEAD) ]]; then
echo "Detected installJRMC update, restarting"
exec bash "$SCRIPT_PATH" "$@" "--no-update"
rerun "$@"
fi
else
debug "Not in the installJRMC repository, checking for installJRMC update via webscrape."
@@ -1747,7 +1744,7 @@ update() {
execute rm -f "$tmp"
echo "Detected installJRMC update, restarting"
exec bash "$SCRIPT_PATH" "$@" "--no-update"
rerun "$@"
else
debug "Current installJRMC $SCRIPT_VERSION is the latest version"
execute rm -f "$tmp"
@@ -1846,13 +1843,7 @@ main() {
[[ -n $LEGACY_REPO_FILE ]] && sudo rm -f "$LEGACY_REPO_FILE"
if [[ $MC_REPO != "$MC_REPO_HARDCODE" ]]; then
echo "Rerunning installJRMC with --mcrepo=$MC_REPO_HARDCODE"
if ((SCRIPT_IS_PIPED)); then
# Re-download and execute if script was piped
curl -fsSL "$SCRIPT_URL" | bash -s -- "$@" "--no-update" "--mcrepo=$MC_REPO_HARDCODE"
exit $?
else
exec bash "$SCRIPT_PATH" "$@" "--no-update" "--mcrepo=$MC_REPO_HARDCODE"
fi
rerun "$@" "--mcrepo=$MC_REPO_HARDCODE"
fi
return 1
fi
@@ -2030,6 +2021,16 @@ create_mc_apt_container() {
buildah run "$CNT" -- sh -c "$cmd" || { err "$cmd failed"; return 1; }
done
}
rerun() {
debug "${FUNCNAME[0]}()" "$@"
if ((SCRIPT_IS_PIPED)); then
# Re-download and execute if script was piped
curl -fsSL "$SCRIPT_URL" | bash -s -- "$@" "--no-update"
exit $?
else
exec bash "$SCRIPT_PATH" "$@" "--no-update"
fi
}
# Roughly turn debugging on for pre-init
# Reset and reparse in parse_input() with getopt