#!/usr/bin/env bash # 打包:scripts/package.sh → backend/artifacts/packages/moshiro---.tar.gz(附 .sha256) # 内容:节点二进制(agent 还带 fleet-enroll)、systemd 单元、OpenWrt procd 脚本、install.sh。 # 发布产物要先用 scripts/publish.sh 生成(agent 需要 agent 和 fleet-enroll 两个)。 set -euo pipefail role="${1:?usage: package.sh }" rid="${2:?usage: package.sh }" root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" version="$(sed -n 's#.*\(.*\).*#\1#p' "$root/Directory.Build.props" | head -1)" name="moshiro-$role-$version-$rid" stage="$root/backend/artifacts/packages/stage/$name" quic_runtime="$root/backend/artifacts/packages/quic-runtime/$rid" rm -rf "$stage" mkdir -p "$stage/systemd" if [[ "$rid" == linux-* ]]; then if command -v pwsh >/dev/null 2>&1; then pwsh -NoProfile -File "$root/ci/Bundle-QuicRuntime.ps1" -RuntimeIdentifier "$rid" -Destination "$quic_runtime" elif command -v pwsh.exe >/dev/null 2>&1 && command -v wslpath >/dev/null 2>&1; then pwsh.exe -NoProfile -File "$(wslpath -w "$root/ci/Bundle-QuicRuntime.ps1")" -RuntimeIdentifier "$rid" -Destination "$(wslpath -w "$quic_runtime")" else echo "PowerShell 7 is required to bundle the Linux QUIC runtime" >&2 exit 2 fi cp "$quic_runtime"/*.so.* "$stage/" fi cp "$root/backend/artifacts/publish/$role/$rid/moshiro-$role" "$stage/" cp "$root/packaging/install.sh" "$stage/" cp "$root/packaging/systemd/moshiro-$role.service" "$stage/systemd/" cp "$root/$role/README.md" "$stage/README.md" if [ "$role" = agent ]; then cp "$root/backend/artifacts/publish/fleet-enroll/$rid/fleet-enroll" "$stage/" else mkdir -p "$stage/openwrt" cp "$root/packaging/openwrt/"* "$stage/openwrt/" fi mkdir -p "$root/backend/artifacts/packages" tar -C "$root/backend/artifacts/packages/stage" -czf "$root/backend/artifacts/packages/$name.tar.gz" "$name" (cd "$root/backend/artifacts/packages" && sha256sum "$name.tar.gz" > "$name.tar.gz.sha256" && ls -l "$name.tar.gz" && cat "$name.tar.gz.sha256")