diff --git a/mc-refresh-restart.sh b/mc-refresh-restart.sh index 6d05df0..807407b 100755 --- a/mc-refresh-restart.sh +++ b/mc-refresh-restart.sh @@ -57,13 +57,19 @@ DATASET="$(findmnt -no SOURCE "${SHARE}" 2>/dev/null || true)" log "Syncing pack metadata against ${MODS_DIR}..." cd "${PACK_DIR}" -probe="$(curl -so /dev/null -w '%{http_code}' --max-time 10 "${BASE_URL}/" || echo 000)" -[ "${probe}" = "000" ] && die "cannot reach ${BASE_URL} — packwiz needs it to hash each mod" - shopt -s nullglob JARS=("${MODS_DIR}"/*.jar) shopt -u nullglob -(( ${#JARS[@]} > 0 )) || die "no .jar files in ${MODS_DIR}" + +# Zero jars is legitimate — an empty pack, or every mod deliberately removed. +# The orphan sweep below then clears the metadata to match. +if (( ${#JARS[@]} > 0 )); then + probe="$(curl -so /dev/null -w '%{http_code}' --max-time 10 "${BASE_URL}/" || true)" + probe="${probe:-000}" + [ "${probe}" = "000" ] && die "cannot reach ${BASE_URL} — packwiz needs it to hash each mod" +else + log "WARNING: no .jar files in ${MODS_DIR} — pack will end up empty" +fi added=0; updated=0; unchanged=0; FAILED=() declare -A SEEN=() @@ -150,7 +156,8 @@ if [ -n "${PACK_URL}" ]; then fi # index.toml is fetched as a separate request and cached separately. - idx="$(curl -fsS --max-time 10 -o /dev/null -w '%{http_code}' "${PACK_URL}/index.toml" || echo 000)" + idx="$(curl -fsS --max-time 10 -o /dev/null -w '%{http_code}' "${PACK_URL}/index.toml" || true)" + idx="${idx:-000}" [ "${idx}" = "200" ] || die "${PACK_URL}/index.toml returned HTTP ${idx} — clients cannot resolve the pack" fi diff --git a/packwiz-setup.sh b/packwiz-setup.sh index 4f94689..c1cc5fa 100755 --- a/packwiz-setup.sh +++ b/packwiz-setup.sh @@ -234,16 +234,6 @@ if [ -n "$MODSDIR" ]; then grep -q 'url' <<<"$("$PACKWIZ" --help 2>&1 || true)" \ || die "this packwiz build has no 'url' subcommand — cannot add mods by URL" - # packwiz downloads each URL to hash it, so a mirror that isn't up yet - # produces a pile of confusing per-mod failures. Check once, up front. - info "checking mirror at $BASEURL" - probe="$(curl -so /dev/null -w '%{http_code}' --max-time 10 "$BASEURL/" || echo 000)" - case "$probe" in - 2*|3*|40[34]) ;; # a listing may legitimately be forbidden - 000) die "cannot reach $BASEURL — start the mirror before running this" ;; - *) warn "$BASEURL/ returned HTTP $probe; continuing, individual mods may fail" ;; - esac - shopt -s nullglob jars=("$MODSDIR"/*.jar) shopt -u nullglob @@ -251,9 +241,21 @@ if [ -n "$MODSDIR" ]; then failed=() if [ "${#jars[@]}" -eq 0 ]; then # An empty pack is a valid starting point: drop jars in later and run - # mc-refresh-restart.sh to register them. + # mc-refresh-restart.sh to register them. Nothing needs fetching, so the + # mirror does not have to be reachable yet either. warn "no .jar files in $MODSDIR yet — creating an empty pack" else + # packwiz downloads each URL to hash it, so a mirror that isn't up yet + # produces a pile of confusing per-mod failures. Check once, up front. + info "checking mirror at $BASEURL" + probe="$(curl -so /dev/null -w '%{http_code}' --max-time 10 "$BASEURL/" || true)" + probe="${probe:-000}" + case "$probe" in + 2*|3*|40[34]) ;; # a listing may legitimately be forbidden + 000) die "cannot reach $BASEURL — the pack server or proxy is not up yet" ;; + *) warn "$BASEURL/ returned HTTP $probe; continuing, individual mods may fail" ;; + esac + info "adding ${#jars[@]} mods from the mirror" for jar in "${jars[@]}"; do file="$(basename "$jar")"