1 parent
818d391022
commit
639362fbf5
40 files changed
+6701
-429
No files matched your search
Executable
+90
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# != 6 ]]; then
|
||||
echo "usage: $0 STAGE ARTIFACT_BASE SOURCE_DATE_EPOCH ARCHIVE INSTALLER WORK_DIR" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
stage=$(realpath -e -- "$1")
|
||||
artifact_base=$2
|
||||
source_date_epoch=$3
|
||||
archive=$(realpath -m -- "$4")
|
||||
installer=$(realpath -m -- "$5")
|
||||
work_dir=$(realpath -m -- "$6")
|
||||
|
||||
[[ $artifact_base =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$ ]] || {
|
||||
echo "invalid artifact base: $artifact_base" >&2
|
||||
exit 2
|
||||
}
|
||||
[[ $source_date_epoch =~ ^[0-9]+$ ]] || {
|
||||
echo "SOURCE_DATE_EPOCH must be a non-negative integer" >&2
|
||||
exit 2
|
||||
}
|
||||
[[ -x $stage/install.sh && -x $stage/uninstall.sh ]] || {
|
||||
echo "stage is missing executable installer helpers" >&2
|
||||
exit 2
|
||||
}
|
||||
[[ -f $stage/manifest.json && -x $stage/bin/echoiond && -f $stage/lib/Echoion.ts ]] || {
|
||||
echo "stage is missing required Echoion payload files" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
mkdir -p -- "$(dirname -- "$archive")" "$(dirname -- "$installer")" "$work_dir"
|
||||
archive_tmp="$(dirname -- "$archive")/.$(basename -- "$archive").tmp.$$"
|
||||
installer_tmp="$(dirname -- "$installer")/.$(basename -- "$installer").tmp.$$"
|
||||
gzip_payload="$work_dir/$artifact_base.tar.gz.$$"
|
||||
header="$work_dir/$artifact_base.run-header.$$"
|
||||
cleanup() {
|
||||
rm -f -- "$archive_tmp" "$installer_tmp" "$gzip_payload" "$header"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
tar_options=(
|
||||
--sort=name
|
||||
"--mtime=@$source_date_epoch"
|
||||
--owner=0
|
||||
--group=0
|
||||
--numeric-owner
|
||||
--format=posix
|
||||
'--pax-option=delete=atime,delete=ctime'
|
||||
)
|
||||
|
||||
tar -C "$stage" "${tar_options[@]}" \
|
||||
--transform="s,^\\.$,$artifact_base," \
|
||||
--transform="s,^\\./,$artifact_base/," \
|
||||
-cf - . |
|
||||
zstd -T1 -19 --no-progress -o "$archive_tmp"
|
||||
mv -f -- "$archive_tmp" "$archive"
|
||||
|
||||
tar -C "$stage" "${tar_options[@]}" -cf - . | gzip -n -9 >"$gzip_payload"
|
||||
cat >"$header" <<'RUN_HEADER'
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
self=$0
|
||||
case $self in
|
||||
/*) ;;
|
||||
*) self=$(pwd)/$self ;;
|
||||
esac
|
||||
temporary=$(mktemp -d "${TMPDIR:-/tmp}/echoion-installer.XXXXXX")
|
||||
cleanup() {
|
||||
rm -rf -- "$temporary"
|
||||
}
|
||||
trap cleanup EXIT HUP INT TERM
|
||||
payload_line=$(awk '/^__ECHOION_PAYLOAD_BELOW__$/ { print NR + 1; exit }' "$self")
|
||||
if [ -z "$payload_line" ]; then
|
||||
echo "Echoion installer payload marker is missing" >&2
|
||||
exit 2
|
||||
fi
|
||||
tail -n "+$payload_line" "$self" |
|
||||
tar --same-permissions --no-same-owner -xzf - -C "$temporary"
|
||||
"$temporary/install.sh" "$@"
|
||||
status=$?
|
||||
exit "$status"
|
||||
__ECHOION_PAYLOAD_BELOW__
|
||||
RUN_HEADER
|
||||
cat "$header" "$gzip_payload" >"$installer_tmp"
|
||||
chmod 0755 "$installer_tmp"
|
||||
mv -f -- "$installer_tmp" "$installer"
|
||||
trap - EXIT
|
||||
Reference in new issue
Block a user