64 lines
1.6 KiB
Bash
Executable File
64 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
if [[ $# -lt 4 || $# -gt 5 ]]; then
|
|
echo "usage: $0 RELEASE_ROOT VERSION ECHOIOND ECHOION_CORE [MANIFEST]" >&2
|
|
exit 2
|
|
fi
|
|
|
|
release_root=$1
|
|
version=$2
|
|
executable=$3
|
|
core=$4
|
|
manifest=${5:-"$release_root/pending-release.json"}
|
|
|
|
if [[ ! $version =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$ ]]; then
|
|
echo "invalid release version: $version" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! -x $executable ]]; then
|
|
echo "echoiond is missing or not executable: $executable" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! -f $core ]]; then
|
|
echo "Core library is missing: $core" >&2
|
|
exit 2
|
|
fi
|
|
|
|
mkdir -p "$release_root" "$(dirname "$manifest")"
|
|
staging="$release_root/.staging-$version-$$"
|
|
destination="$release_root/$version"
|
|
trap 'rm -rf -- "$staging"' EXIT
|
|
|
|
if [[ -e $destination ]]; then
|
|
echo "release already exists: $destination" >&2
|
|
exit 2
|
|
fi
|
|
|
|
mkdir "$staging"
|
|
install -m 0755 "$executable" "$staging/echoiond"
|
|
install -m 0644 "$core" "$staging/Echoion.ts"
|
|
|
|
executable_hash=$(sha256sum "$staging/echoiond" | cut -d' ' -f1)
|
|
core_hash=$(sha256sum "$staging/Echoion.ts" | cut -d' ' -f1)
|
|
mv "$staging" "$destination"
|
|
|
|
manifest_tmp="$manifest.tmp.$$"
|
|
trap 'rm -rf -- "$staging"; rm -f -- "$manifest_tmp"' EXIT
|
|
printf '%s\n' \
|
|
'{' \
|
|
" \"version\": \"$version\"," \
|
|
" \"executable\": \"$version/echoiond\"," \
|
|
" \"core\": \"$version/Echoion.ts\"," \
|
|
' "sha256": {' \
|
|
" \"executable\": \"$executable_hash\"," \
|
|
" \"core\": \"$core_hash\"" \
|
|
' }' \
|
|
'}' > "$manifest_tmp"
|
|
chmod 0644 "$manifest_tmp"
|
|
mv -f "$manifest_tmp" "$manifest"
|
|
trap - EXIT
|
|
|
|
echo "staged release $version"
|
|
echo "manifest: $manifest"
|