#!/usr/bin/env bash # build.sh — assemble a complete Sirius Press tree. # # Copies the vendored WordPress from wordpress/, drops this repository's # plugins and must-use plugins into it, and leaves the result in # dist/sirius-press/. # # With --zip it also produces dist/sirius-press-.zip, which is the # artifact shared-hosting users upload. # # There is no download and no checksum step, because there is nothing to # fetch: core is in the repository, already patched, and what you build is # exactly what you can read in `git log wordpress/`. Moving to a new upstream # release is tools/update-wordpress.sh, not a flag here. set -euo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$here" # shellcheck source=wordpress.lock source tools/wordpress.lock VERSION="$(grep -m1 "^ \* Version:" plugins/sirius-press-core/sirius-press-core.php | awk '{print $3}')" DIST="$here/dist" TARGET="$DIST/sirius-press" SOURCE="$here/wordpress" MAKE_ZIP=0 for arg in "$@"; do case "$arg" in --zip) MAKE_ZIP=1 ;; *) echo "unknown option: $arg" >&2; exit 2 ;; esac done say() { printf '\033[1m→\033[0m %s\n' "$*"; } die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2; exit 1; } [ -f "$SOURCE/wp-includes/version.php" ] \ || die "wordpress/ is missing or empty — check the whole repository was cloned." vendored="$(grep -m1 'wp_version = ' "$SOURCE/wp-includes/version.php" | sed "s/.*'\(.*\)'.*/\1/")" if [ "$vendored" != "$WP_VERSION" ]; then die "wordpress/ holds $vendored but tools/wordpress.lock says $WP_VERSION. One of them is stale; tools/update-wordpress.sh keeps them in step." fi # ------------------------------------------------------------------ assemble say "copying WordPress $vendored out of wordpress/" rm -rf "$TARGET" mkdir -p "$TARGET" # The trailing /. copies the contents rather than nesting another directory. cp -a "$SOURCE/." "$TARGET/" say "installing Sirius Press plugins" mkdir -p "$TARGET/wp-content/plugins" "$TARGET/wp-content/mu-plugins" for plugin in plugins/*/; do cp -R "$plugin" "$TARGET/wp-content/plugins/" done cp mu-plugins/*.php "$TARGET/wp-content/mu-plugins/" say "built dist/sirius-press ($(du -sh "$TARGET" | cut -f1))" # --------------------------------------------------------------------- zip if [ "$MAKE_ZIP" -eq 1 ]; then archive="$DIST/sirius-press-$VERSION.zip" say "packing $(basename "$archive")" rm -f "$archive" # `zip` is the obvious tool and is missing often enough — minimal container # images, Git Bash on Windows — that falling back to Python's zipfile is # worth nine lines. Both produce the same archive as far as anyone # unpacking it is concerned. if command -v zip >/dev/null; then ( cd "$DIST" && zip -qr "$archive" sirius-press ) elif command -v python3 >/dev/null || command -v python >/dev/null; then py="$(command -v python3 || command -v python)" "$py" - "$DIST" "$archive" <<'PYZIP' import os, sys, zipfile root, archive = sys.argv[1], sys.argv[2] base = os.path.join(root, 'sirius-press') with zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as z: for folder, _dirs, files in os.walk(base): for name in files: full = os.path.join(folder, name) z.write(full, os.path.relpath(full, root).replace(os.sep, '/')) PYZIP else die "--zip needs either the zip command or Python." fi sha256sum "$archive" | cut -d' ' -f1 > "$archive.sha256" say "$(basename "$archive") — $(du -h "$archive" | cut -f1), sha256 $(cat "$archive.sha256")" fi cat <