#!/usr/bin/env bash # # Build the release zip. # # ./build.sh -> dist/mc-packwiz-deploy-.zip # ./build.sh --iso -> also dist/mc-packwiz-deploy-.iso # ./build.sh -o /tmp -> writes there instead # ./build.sh -v 1.2.0 -> override the version # # Version comes from the latest git tag when there is one, otherwise VERSION # below. A dirty working tree gets a -dirty suffix so a zip built mid-edit is # never mistaken for a tagged release. set -euo pipefail VERSION="0.1.0" NAME="mc-packwiz-deploy" OUTDIR="" MAKE_ISO=0 HERE="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" # Everything the zip ships. Anything not listed here stays out, so stray notes # or test output in the working tree can't leak into a release. FILES=( README.md install.sh deploy.conf.example deploy.sh mc-service-setup.sh packwiz-setup.sh mc-refresh-restart.sh packwiz-http.py ) die() { echo "error: $*" >&2; exit 1; } info() { echo ">>> $*"; } usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; exit "${1:-0}"; } while [ $# -gt 0 ]; do case "$1" in -o|--outdir) OUTDIR="${2:-}"; shift 2 ;; --iso) MAKE_ISO=1; shift ;; -v|--version) VERSION="${2:-}"; VERSION_FORCED=1; shift 2 ;; -h|--help) usage 0 ;; *) echo "unknown option: $1" >&2; usage 1 ;; esac done cd "$HERE" command -v zip >/dev/null || die "zip not found — sudo dnf install zip" # ---------------------------------------------------------------- version --- if [ -z "${VERSION_FORCED:-}" ] && git rev-parse --git-dir >/dev/null 2>&1; then tag="$(git describe --tags --abbrev=0 2>/dev/null || true)" [ -n "$tag" ] && VERSION="${tag#v}" if ! git diff --quiet HEAD -- "${FILES[@]}" 2>/dev/null; then VERSION="${VERSION}-dirty" info "working tree has uncommitted changes to shipped files" fi fi [ -n "$OUTDIR" ] || OUTDIR="$HERE/dist" mkdir -p "$OUTDIR" ZIP="$OUTDIR/${NAME}-${VERSION}.zip" # ------------------------------------------------------------------ check --- for f in "${FILES[@]}"; do [ -f "$f" ] || die "missing file: $f" done info "syntax-checking scripts" fail=0 for f in "${FILES[@]}"; do case "$f" in *.sh) bash -n "$f" || { echo " FAILED: $f" >&2; fail=1; } ;; *.py) python3 -m py_compile "$f" || { echo " FAILED: $f" >&2; fail=1; } ;; esac done (( fail )) && die "refusing to build a zip containing scripts that don't parse" # ------------------------------------------------------------------ stage --- # Staged in a temp tree so the zip has a single top-level directory and the # scripts land executable regardless of how git checked them out. STAGE="$(mktemp -d)" trap 'rm -rf "$STAGE"' EXIT DEST="$STAGE/$NAME" mkdir -p "$DEST" for f in "${FILES[@]}"; do case "$f" in *.sh|*.py) install -m 755 "$f" "$DEST/$f" ;; *) install -m 644 "$f" "$DEST/$f" ;; esac done printf '%s\n' "$VERSION" > "$DEST/VERSION" # ------------------------------------------------------------------ build --- rm -f "$ZIP" ( cd "$STAGE" && zip -qr "$ZIP" "$NAME" ) info "built $ZIP" unzip -l "$ZIP" | sed 's/^/ /' if command -v sha256sum >/dev/null; then sha256sum "$ZIP" | tee "$ZIP.sha256" | sed 's/^/ /' fi # -------------------------------------------------------------------- iso --- if (( MAKE_ISO )); then ISO="$OUTDIR/${NAME}-${VERSION}.iso" mkisofs="" for c in xorrisofs genisoimage mkisofs; do command -v "$c" >/dev/null && { mkisofs="$c"; break; } done [ -n "$mkisofs" ] || die "no ISO tool found — sudo dnf install xorriso" # A ready-to-edit config goes on the media so the target host only needs # the file opened and one command run. cp "$HERE/deploy.conf.example" "$DEST/deploy.conf" cat > "$DEST/README.FIRST.txt" <<'TXT' Minecraft + packwiz hosting kit =============================== The media is read-only, so install.sh copies itself to your home directory before doing anything. 1. Mount this media, then copy the kit somewhere writable: mkdir -p ~/mc-packwiz-deploy cp -r /run/media/*/mc-packwiz-deploy/. ~/mc-packwiz-deploy/ cd ~/mc-packwiz-deploy && chmod +x *.sh *.py 2. Edit deploy.conf. At minimum set MIRROR_URL and ACCEPT_EULA. 3. Check the machine is ready: ./install.sh --check 4. Install: ./install.sh Requires a ZFS dataset already mounted at the SHARE path in deploy.conf. install.sh refuses to run otherwise, rather than filling the root disk. TXT rm -f "$ISO" "$mkisofs" -quiet -o "$ISO" -V "MCPACKWIZ" -J -r "$STAGE" \ || die "$mkisofs failed" info "built $ISO" ls -lh "$ISO" | sed 's/^/ /' command -v sha256sum >/dev/null && sha256sum "$ISO" | tee "$ISO.sha256" | sed 's/^/ /' fi