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 <noreply@anthropic.com>
main
Amir Alexander Abdelbaki 2026-08-05 23:36:37 +02:00
parent b32b47f020
commit 908c4ecbb6
2 changed files with 18 additions and 3 deletions

View File

@ -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.

View File

@ -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 <http base url>"
[ -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