From 908c4ecbb65822467d886a0823dd5bf9bfcdfe66 Mon Sep 17 00:00:00 2001 From: The_miro Date: Wed, 5 Aug 2026 23:36:37 +0200 Subject: [PATCH] Do not fail when the mods directory is absent or empty On a first deploy the server has not run yet, so /minecraft/mods does not exist and packwiz-setup.sh died before creating anything. It now creates the directory, and mc-service-setup.sh also creates it up front with setgid so jars dropped in by either the service user or the admin stay group-readable. An empty mods directory is likewise no longer fatal. A pack with no mods yet is a valid starting point: the pack, the index and the player guides are all generated, and jars registered later with mc-refresh-restart.sh. Co-Authored-By: Claude Opus 5 --- mc-service-setup.sh | 4 ++++ packwiz-setup.sh | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mc-service-setup.sh b/mc-service-setup.sh index 3c6e237..cc004b2 100755 --- a/mc-service-setup.sh +++ b/mc-service-setup.sh @@ -87,6 +87,10 @@ fi info "setting ownership of $SHARE to $MCUSER" chown -R "$MCUSER":"$MCUSER" "$SHARE" +# The server creates mods/ on first run, but the pack setup needs it to exist +# before that. Setgid so jars dropped in by either side stay group-readable. +install -d -o "$MCUSER" -g "$MCUSER" -m 2775 "$SHARE/mods" + # Without this the chown above locks the human out of the share they author the # pack on. Share root and packs/ become group-writable and setgid, so files # created by either side stay readable to both. diff --git a/packwiz-setup.sh b/packwiz-setup.sh index 8998e58..4f94689 100755 --- a/packwiz-setup.sh +++ b/packwiz-setup.sh @@ -98,7 +98,12 @@ mkdir -p "$PACKROOT" 2>/dev/null || true [ -n "$BASEURL" ] && [ -z "$MODSDIR" ] && MODSDIR="$SHARE/mods" if [ -n "$MODSDIR$BASEURL" ]; then [ -n "$BASEURL" ] || die "-M given without -u " - [ -d "$MODSDIR" ] || die "mods dir does not exist: $MODSDIR" + # On a first deploy the server has not run yet, so mods/ may not exist. + # That is not an error — create it and carry on with an empty pack. + if [ ! -d "$MODSDIR" ]; then + info "creating $MODSDIR" + mkdir -p "$MODSDIR" || die "could not create $MODSDIR" + fi fi BASEURL="${BASEURL%/}" @@ -242,10 +247,14 @@ if [ -n "$MODSDIR" ]; then shopt -s nullglob jars=("$MODSDIR"/*.jar) shopt -u nullglob - [ "${#jars[@]}" -gt 0 ] || die "no .jar files found in $MODSDIR" - info "adding ${#jars[@]} mods from the mirror" 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. + warn "no .jar files in $MODSDIR yet — creating an empty pack" + else + info "adding ${#jars[@]} mods from the mirror" for jar in "${jars[@]}"; do file="$(basename "$jar")" @@ -266,6 +275,8 @@ if [ -n "$MODSDIR" ]; then fi done + fi + "$PACKWIZ" refresh if [ "${#failed[@]}" -gt 0 ]; then