Files
piscine-graph-tweaks/build.sh
T
2026-09-12 14:29:44 +02:00

47 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# Builds the package to hand out: dist/piscine-graph-tweaks-<version>.zip
# A Firefox .xpi is just a zip, so the .xpi copy is produced alongside it.
set -eu
cd "$(dirname "$0")"
version=$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' manifest.json | head -n 1)
if [ -z "$version" ]; then
echo "build.sh: no version found in manifest.json" >&2
exit 1
fi
name="piscine-graph-tweaks-$version"
mkdir -p dist
rm -f "dist/$name.zip" "dist/$name.xpi"
# Zip the CONTENTS (manifest.json at the archive root), not the folder itself.
# -r: recursive, -X: no system metadata.
if command -v zip >/dev/null 2>&1; then
zip -qr -X "dist/$name.zip" manifest.json src README.md
elif command -v python3 >/dev/null 2>&1; then
# Dependency-free fallback: same result through the zipfile module.
python3 - "dist/$name.zip" manifest.json src README.md <<-'EOF'
import os, sys, zipfile
out, sources = sys.argv[1], sys.argv[2:]
with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as z:
for src in sources:
if os.path.isdir(src):
for root, _, files in os.walk(src):
for f in sorted(files):
p = os.path.join(root, f)
z.write(p, os.path.relpath(p, "."))
else:
z.write(src, src)
EOF
else
echo "build.sh: needs 'zip' (pacman -S zip) or python3" >&2
exit 1
fi
cp "dist/$name.zip" "dist/$name.xpi"
echo "→ dist/$name.zip"
echo "→ dist/$name.xpi (unsigned — see README, \"Sharing it with friends\")"