32 lines
1.6 KiB
Bash
32 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
# Package the same Agent and enrollment outputs for every Linux target.
|
|
set -euo pipefail
|
|
rid="${1:?usage: package-linux-agent.sh <rid> <binaries> <destination>}"
|
|
binaries="${2:?}"; destination="${3:?}"
|
|
case "$rid" in
|
|
linux-x64) suffix=amd64 ;;
|
|
linux-arm64) suffix=arm64 ;;
|
|
linux-musl-arm64) suffix=musl-arm64 ;;
|
|
*) echo "unsupported Linux RID: $rid" >&2; exit 2 ;;
|
|
esac
|
|
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
source "$root/ci/version.sh"
|
|
work="$(mktemp -d)"
|
|
trap 'rm -rf "$work"' EXIT
|
|
mkdir -p "$work/systemd" "$work/openwrt" "$destination"
|
|
install -m 0755 "$binaries/moshiro-agent" "$binaries/fleet-enroll" "$root/packaging/install.sh" "$work/"
|
|
for library in "$binaries"/lib*.so.*; do
|
|
[[ ! -f "$library" ]] || install -m 0644 "$library" "$work/"
|
|
done
|
|
install -m 0644 "$root/LICENSE" "$work/"
|
|
install -m 0644 "$root/backend/agent/README.md" "$work/README.md"
|
|
install -m 0644 "$root/packaging/systemd/moshiro-agent.service" "$work/systemd/"
|
|
install -m 0755 "$root/packaging/openwrt/moshiro-agent.init" "$work/openwrt/"
|
|
install -m 0644 "$root/packaging/openwrt/moshiro.keep" "$work/openwrt/"
|
|
archive="moshiro-agent-v$MOSHIRO_VERSION-linux-$suffix.tar.gz"
|
|
# Name the members explicitly so tar does not add a leading ./ directory.
|
|
mapfile -t members < <(find "$work" -mindepth 1 -maxdepth 1 -printf '%f\n' | LC_ALL=C sort)
|
|
tar --sort=name --mtime='UTC 2000-01-01' --owner=0 --group=0 --numeric-owner -czf "$destination/$archive" -C "$work" "${members[@]}"
|
|
(cd "$destination" && sha256sum "$archive" > "$archive.sha256")
|
|
echo "packaged $archive"
|