61 lines
2.3 KiB
Bash
Executable File
61 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
readonly SOURCE_COMMIT=eb20e88f582e1ddb0f32e8acf90cd9e77ec63b8f
|
|
readonly SOURCE_TREE=be6cf1d033f17ab53f23e5b8e5c7f4492f18e2f8
|
|
readonly PATCHED_TREE=29e47624ba86572d278411d229e24f4822046021
|
|
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
readonly PATCH_FILE="$SCRIPT_DIR/podsteadr-archipelago.patch"
|
|
|
|
if [[ $# -ne 2 ]]; then
|
|
echo "usage: $0 SOURCE_GIT_DIR NEW_OUTPUT_DIR" >&2
|
|
exit 2
|
|
fi
|
|
|
|
source_git=$(cd "$1" && pwd)
|
|
output_parent=$(cd "$(dirname "$2")" && pwd)
|
|
output="$output_parent/$(basename "$2")"
|
|
|
|
[[ ! -e "$output" ]] || {
|
|
echo "refusing to overwrite existing output: $output" >&2
|
|
exit 2
|
|
}
|
|
|
|
actual_tree=$(git -C "$source_git" rev-parse "$SOURCE_COMMIT^{tree}")
|
|
[[ "$actual_tree" == "$SOURCE_TREE" ]] || {
|
|
echo "source tree mismatch for $SOURCE_COMMIT" >&2
|
|
exit 1
|
|
}
|
|
|
|
staging=$(mktemp -d "$output_parent/.podsteadr-source.XXXXXX")
|
|
trap 'rm -rf -- "$staging"' EXIT
|
|
|
|
git -C "$source_git" archive "$SOURCE_COMMIT" | tar -x -C "$staging"
|
|
git -C "$staging" init -q
|
|
git -C "$staging" apply --check "$PATCH_FILE"
|
|
git -C "$staging" apply "$PATCH_FILE"
|
|
git -C "$staging" apply --check "$SCRIPT_DIR/podsteadr-lifecycle.patch"
|
|
git -C "$staging" apply "$SCRIPT_DIR/podsteadr-lifecycle.patch"
|
|
git -C "$staging" apply --check "$SCRIPT_DIR/podsteadr-responsive.patch"
|
|
git -C "$staging" apply "$SCRIPT_DIR/podsteadr-responsive.patch"
|
|
git -C "$staging" apply --check "$SCRIPT_DIR/podsteadr-native-bridge.patch"
|
|
git -C "$staging" apply "$SCRIPT_DIR/podsteadr-native-bridge.patch"
|
|
git -C "$staging" apply --check "$SCRIPT_DIR/podsteadr-server-key.patch"
|
|
git -C "$staging" apply "$SCRIPT_DIR/podsteadr-server-key.patch"
|
|
git -C "$staging" add -A
|
|
patched_tree=$(git -C "$staging" write-tree)
|
|
[[ "$patched_tree" == "$PATCHED_TREE" ]] || {
|
|
echo "patched tree mismatch" >&2
|
|
exit 1
|
|
}
|
|
# The temporary repository exists only to calculate the exact patched tree. Do
|
|
# not carry Git metadata or a source remote into the image build context.
|
|
rm -rf -- "$staging/.git"
|
|
printf '%s\n' "$SOURCE_COMMIT" > "$staging/.archipelago-source-commit"
|
|
printf '%s\n' "$SOURCE_TREE" > "$staging/.archipelago-source-tree"
|
|
printf '%s\n' "$patched_tree" > "$staging/.archipelago-patched-tree"
|
|
|
|
mv "$staging" "$output"
|
|
trap - EXIT
|
|
printf 'prepared Podsteadr %s as tree %s\n' "$SOURCE_COMMIT" "$patched_tree"
|