34 lines
1.3 KiB
Bash
Executable File
34 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
OUT=${OUT:-"$ROOT/dist/qiu.subscription-admin.s2plugin"}
|
|
command -v jq >/dev/null 2>&1 || { printf '%s\n' 'jq is required to build a package' >&2; exit 2; }
|
|
TMP=$(mktemp -d)
|
|
cleanup() {
|
|
rm -rf "$TMP"
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
mkdir -p "$TMP/ui" "$(dirname -- "$OUT")"
|
|
cp "$ROOT/ui/index.html" "$ROOT/ui/app.js" "$ROOT/ui/styles.css" "$TMP/ui/"
|
|
|
|
# Recompute declared hashes at package time so a UI change cannot produce an
|
|
# archive that the control plane rejects. The repository descriptor remains
|
|
# the human-readable source contract.
|
|
INDEX_HASH=$(shasum -a 256 "$ROOT/ui/index.html" | awk '{print $1}')
|
|
APP_HASH=$(shasum -a 256 "$ROOT/ui/app.js" | awk '{print $1}')
|
|
STYLES_HASH=$(shasum -a 256 "$ROOT/ui/styles.css" | awk '{print $1}')
|
|
jq --arg index_hash "$INDEX_HASH" --arg app_hash "$APP_HASH" --arg styles_hash "$STYLES_HASH" \
|
|
'.files["ui/index.html"]=$index_hash | .files["ui/app.js"]=$app_hash | .files["ui/styles.css"]=$styles_hash' \
|
|
"$ROOT/business-plugin-manifest.v1.json" > "$TMP/manifest.json"
|
|
|
|
if [ -n "${SIGNATURE_FILE:-}" ]; then
|
|
cp "$SIGNATURE_FILE" "$TMP/signature.json"
|
|
fi
|
|
|
|
OUT_DIR=$(CDPATH= cd -- "$(dirname -- "$OUT")" && pwd)
|
|
OUT_PATH="$OUT_DIR/$(basename -- "$OUT")"
|
|
(cd "$TMP" && zip -q -r "$OUT_PATH" manifest.json ui)
|
|
printf '%s\n' "$OUT_PATH"
|