33 lines
1.1 KiB
Bash
Executable File
33 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# Build a repeatable source archive from this component's clean Git commit.
|
|
set -eu
|
|
|
|
if [ "$#" -ne 1 ]; then
|
|
echo "usage: scripts/package.sh OUTPUT_DIRECTORY" >&2
|
|
exit 2
|
|
fi
|
|
|
|
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
source=$(git -C "$root" rev-parse --verify HEAD)
|
|
if [ -n "$(git -C "$root" status --porcelain)" ]; then
|
|
echo "package: source checkout has uncommitted changes" >&2
|
|
exit 1
|
|
fi
|
|
|
|
output=$(realpath -m -- "$1")
|
|
case "$output/" in
|
|
"$root/"*) echo "package: use an output directory outside the source checkout" >&2; exit 2 ;;
|
|
esac
|
|
mkdir -p -- "$output"
|
|
work=$(mktemp -d "$output/.std-text.XXXXXX")
|
|
trap 'rm -rf -- "$work"' EXIT
|
|
|
|
name="marqdo-std-text-$source"
|
|
archive="$name-source.tar.gz"
|
|
# Keep the operations separate so a failed git archive cannot be masked by gzip.
|
|
git -C "$root" archive --format=tar --prefix="$name/" "$source" > "$work/source.tar"
|
|
gzip -n < "$work/source.tar" > "$work/$archive"
|
|
(cd "$work" && sha256sum "$archive" > "$archive.sha256")
|
|
mv -- "$work/$archive" "$work/$archive.sha256" "$output/"
|
|
printf '%s\n' "$output/$archive"
|