cringe
Some checks failed
CI / agent (push) Has been cancelled
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / containers (push) Has been cancelled

This commit is contained in:
2026-09-20 11:03:09 +03:00
parent c4dc19cd41
commit cf1c31eb2a
6 changed files with 194 additions and 28 deletions

View File

@@ -2,34 +2,113 @@
set -Eeuo pipefail
IFS=$'\n\t'
if [[ $# -ne 3 ]]; then
printf 'Usage: %s X86_64_BINARY AARCH64_BINARY OUTPUT_DIRECTORY\n' "$0" >&2
exit 2
usage() {
printf '%s\n' \
"Usage:" \
" $0 --output DIRECTORY --amd64 BINARY" \
" $0 --output DIRECTORY --arm64 BINARY" \
" $0 --output DIRECTORY --amd64 BINARY --arm64 BINARY" \
"" \
"The legacy form is still supported:" \
" $0 X86_64_BINARY AARCH64_BINARY OUTPUT_DIRECTORY" >&2
}
AMD64_BINARY=""
ARM64_BINARY=""
OUTPUT_DIRECTORY=""
# Preserve the original interface for existing release jobs while allowing each
# architecture to be packaged independently on its native Linux builder.
if [[ $# -eq 3 && "$1" != --* ]]; then
AMD64_BINARY="$1"
ARM64_BINARY="$2"
OUTPUT_DIRECTORY="$3"
else
while [[ $# -gt 0 ]]; do
case "$1" in
--amd64)
[[ $# -ge 2 ]] || { usage; exit 2; }
AMD64_BINARY="$2"
shift 2
;;
--arm64)
[[ $# -ge 2 ]] || { usage; exit 2; }
ARM64_BINARY="$2"
shift 2
;;
--output)
[[ $# -ge 2 ]] || { usage; exit 2; }
OUTPUT_DIRECTORY="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
printf 'unknown argument: %s\n' "$1" >&2
usage
exit 2
;;
esac
done
fi
AMD64_BINARY="$1"
ARM64_BINARY="$2"
OUTPUT_DIRECTORY="$3"
[[ -x "$AMD64_BINARY" ]] || { printf 'amd64 binary is not executable\n' >&2; exit 1; }
[[ -x "$ARM64_BINARY" ]] || { printf 'arm64 binary is not executable\n' >&2; exit 1; }
command -v sha256sum >/dev/null || { printf 'sha256sum is required\n' >&2; exit 1; }
[[ -n "$OUTPUT_DIRECTORY" ]] || { printf 'output directory is required\n' >&2; usage; exit 2; }
[[ -n "$AMD64_BINARY" || -n "$ARM64_BINARY" ]] || {
printf 'at least one architecture binary is required\n' >&2
usage
exit 2
}
command -v file >/dev/null || { printf 'file is required\n' >&2; exit 1; }
AMD64_DESCRIPTION="$(file -b "$AMD64_BINARY")"
ARM64_DESCRIPTION="$(file -b "$ARM64_BINARY")"
[[ "$AMD64_DESCRIPTION" == *ELF* && "$AMD64_DESCRIPTION" == *x86-64* ]] || {
printf 'amd64 artifact is not an x86-64 Linux ELF binary\n' >&2; exit 1;
}
[[ "$ARM64_DESCRIPTION" == *ELF* && ("$ARM64_DESCRIPTION" == *aarch64* || "$ARM64_DESCRIPTION" == *ARM64*) ]] || {
printf 'arm64 artifact is not an aarch64 Linux ELF binary\n' >&2; exit 1;
validate_and_install() {
local architecture="$1"
local source="$2"
local destination="$3"
local description
[[ -x "$source" ]] || { printf '%s binary is not executable\n' "$architecture" >&2; exit 1; }
description="$(file -b "$source")"
case "$architecture" in
amd64)
[[ "$description" == *ELF* && "$description" == *x86-64* ]] || {
printf 'amd64 artifact is not an x86-64 Linux ELF binary\n' >&2
exit 1
}
;;
arm64)
[[ "$description" == *ELF* && ("$description" == *aarch64* || "$description" == *ARM64*) ]] || {
printf 'arm64 artifact is not an aarch64 Linux ELF binary\n' >&2
exit 1
}
;;
esac
install -m 0755 "$source" "$destination"
}
install -d -m 0755 "$OUTPUT_DIRECTORY"
install -m 0755 "$AMD64_BINARY" "$OUTPUT_DIRECTORY/vps-agent-linux-amd64"
install -m 0755 "$ARM64_BINARY" "$OUTPUT_DIRECTORY/vps-agent-linux-arm64"
if [[ -n "$AMD64_BINARY" ]]; then
validate_and_install amd64 "$AMD64_BINARY" "$OUTPUT_DIRECTORY/vps-agent-linux-amd64"
fi
if [[ -n "$ARM64_BINARY" ]]; then
validate_and_install arm64 "$ARM64_BINARY" "$OUTPUT_DIRECTORY/vps-agent-linux-arm64"
fi
CHECKSUM_FILES=()
[[ -f "$OUTPUT_DIRECTORY/vps-agent-linux-amd64" ]] && CHECKSUM_FILES+=(vps-agent-linux-amd64)
[[ -f "$OUTPUT_DIRECTORY/vps-agent-linux-arm64" ]] && CHECKSUM_FILES+=(vps-agent-linux-arm64)
(
cd "$OUTPUT_DIRECTORY"
sha256sum vps-agent-linux-amd64 vps-agent-linux-arm64 > SHA256SUMS
if command -v sha256sum >/dev/null; then
sha256sum "${CHECKSUM_FILES[@]}" > SHA256SUMS
elif command -v shasum >/dev/null; then
shasum -a 256 "${CHECKSUM_FILES[@]}" > SHA256SUMS
else
printf 'sha256sum or shasum is required\n' >&2
exit 1
fi
if [[ -n "${VPS_AGENT_MINISIGN_SECRET_KEY:-}" ]]; then
command -v minisign >/dev/null || { printf 'minisign is required for signing\n' >&2; exit 1; }
minisign -Sm SHA256SUMS -s "$VPS_AGENT_MINISIGN_SECRET_KEY"