Packwiz-Abdelpak-hosting-kit/deploy.sh

83 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# One-shot deploy: systemd service + packwiz pack + player setup guides.
#
# ./deploy.sh -n "Opengames" -a themiro -u https://games.abdelbaki.eu/mods \
# -N 21.1.72 --accept-eula
#
# Runs, in order:
# 1. mc-service-setup.sh (root) — minecraft user, NeoForge, systemd units
# 2. packwiz-setup.sh (you) — pack, mod index from the mirror, guides
#
# Run as your normal user; it calls sudo for the parts that need it.
set -euo pipefail
NAME=""; AUTHOR=""; BASEURL=""; NFVER="latest"; MCVER="1.21.1"
SHARE="/minecraft"; XMX="10G"; XMS="10G"; ACCEPT_EULA=""; PORT="25565"
HERE="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
die() { echo "error: $*" >&2; exit 1; }
step() { printf '\n\033[1m=== %s ===\033[0m\n\n' "$*"; }
usage() { sed -n '2,13p' "$0" | sed 's/^# \?//'; exit "${1:-0}"; }
while [ $# -gt 0 ]; do
case "$1" in
-n|--name) NAME="${2:-}"; shift 2 ;;
-a|--author) AUTHOR="${2:-}"; shift 2 ;;
-u|--base-url) BASEURL="${2:-}"; shift 2 ;;
-N|--neoforge) NFVER="${2:-}"; shift 2 ;;
-m|--mc) MCVER="${2:-}"; shift 2 ;;
-s|--share) SHARE="${2:-}"; shift 2 ;;
-p|--port) PORT="${2:-}"; shift 2 ;;
-X|--xmx) XMX="${2:-}"; shift 2 ;;
-x|--xms) XMS="${2:-}"; shift 2 ;;
--accept-eula) ACCEPT_EULA="--accept-eula"; shift ;;
-h|--help) usage 0 ;;
*) echo "unknown option: $1" >&2; usage 1 ;;
esac
done
[ "$(id -u)" -ne 0 ] || die "run this as your normal user, not root — it sudos where needed"
[ -n "$NAME" ] || die "missing -n <pack name>"
[ -n "$AUTHOR" ] || die "missing -a <author>"
[ -n "$BASEURL" ] || die "missing -u <mirror base url>, e.g. https://games.abdelbaki.eu/mods"
for s in mc-service-setup.sh packwiz-setup.sh mc-refresh-restart.sh; do
[ -x "$HERE/$s" ] || die "missing or not executable: $HERE/$s"
done
# Fail early rather than halfway through, since step 1 makes system changes.
sudo -v || die "sudo is required"
step "1/2 Minecraft systemd service"
sudo "$HERE/mc-service-setup.sh" \
-s "$SHARE" -A "$USER" -X "$XMX" -x "$XMS" -m "$MCVER" -p "$PORT" \
${NFVER:+-N "$NFVER"} ${ACCEPT_EULA}
step "2/2 packwiz pack and player guides"
# The admin group membership from step 1 isn't active in this shell yet, so run
# the pack setup under the new group explicitly rather than telling you to log
# out and back in.
if id -nG "$USER" | tr ' ' '\n' | grep -qx minecraft; then
"$HERE/packwiz-setup.sh" -n "$NAME" -a "$AUTHOR" -m "$MCVER" -u "$BASEURL" -s "$SHARE" -p "$PORT"
else
sg minecraft -c "$(printf '%q ' "$HERE/packwiz-setup.sh" -n "$NAME" -a "$AUTHOR" \
-m "$MCVER" -u "$BASEURL" -s "$SHARE" -p "$PORT")"
fi
step "Done"
cat <<EOF
Start the server:
sudo systemctl start minecraft
journalctl -u minecraft -f
Keep it in sync after adding mods to $SHARE/mods:
$HERE/mc-refresh-restart.sh
Edit the config block at the top of mc-refresh-restart.sh first — it needs
PACK_DIR, BASE_URL and PACK_URL pointed at what this run just created.
EOF