#!/usr/bin/env bash # # Packs client-package/ into a single ZIP for handover. # # The result contains the client code AND its documentation, so a project can be # integrated without access to this repository. # # ./scripts/build-client-package.sh # ./scripts/build-client-package.sh --server-url https://manage.example.org # # With --server-url the placeholder in the shipped config.sample.php is replaced, # so the recipient only has to fill in instance and token. set -euo pipefail SERVER_URL="" VERSION="$(date +%Y%m%d)" while [[ $# -gt 0 ]]; do case "$1" in --server-url) SERVER_URL="${2:-}" shift 2 ;; --version) VERSION="${2:-}" shift 2 ;; -h|--help) cat <.zip from client-package/. --server-url URL Prefill MANAGE_SERVER_URL in the shipped config.sample.php --version LABEL Label for the file name (default: today's date) USAGE exit 0 ;; *) echo "Error: unknown option: $1" >&2 exit 1 ;; esac done if ! command -v zip >/dev/null 2>&1; then echo "Error: zip is required." >&2 exit 1 fi REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" SOURCE_DIR="${REPO_ROOT}/client-package" BUILD_DIR="${REPO_ROOT}/build" if [[ ! -d "$SOURCE_DIR" ]]; then echo "Error: client-package/ not found at ${SOURCE_DIR}" >&2 exit 1 fi STAGE="$(mktemp -d)" trap 'rm -rf "$STAGE"' EXIT cp -r "$SOURCE_DIR" "${STAGE}/manage-client-package" # A config.php from local testing must never be handed out: it holds a token. # Scoped to manage-client/ on purpose - examples/ ships config.php files that are # documentation and must survive. rm -f "${STAGE}/manage-client-package/manage-client/config.php" find "${STAGE}/manage-client-package" -name "*.log" -delete find "${STAGE}/manage-client-package" -name ".DS_Store" -delete if [[ -n "$SERVER_URL" ]]; then SERVER_URL="${SERVER_URL%/}" SAMPLE="${STAGE}/manage-client-package/manage-client/config.sample.php" sed -i.bak -E \ "s|(define\\(\"MANAGE_SERVER_URL\", \")[^\"]*(\"\\);)|\\1${SERVER_URL}\\2|" \ "$SAMPLE" rm -f "${SAMPLE}.bak" echo "MANAGE_SERVER_URL prefilled: ${SERVER_URL}" fi # Stamp the build so a recipient can tell versions apart. cat > "${STAGE}/manage-client-package/BUILD.txt" </dev/null 2>&1; then SHA="$(sha256sum "$ARCHIVE" | awk '{print $1}')" else SHA="$(shasum -a 256 "$ARCHIVE" | awk '{print $1}')" fi cat <