114 lines
2.7 KiB
Bash
Executable File
114 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
UPDATER="${ROOT_DIR}/scripts/transport-packaging/update.sh"
|
|
ROLLBACK="${ROOT_DIR}/scripts/transport-packaging/rollback.sh"
|
|
|
|
require_cmd() {
|
|
local cmd="$1"
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
echo "[transport_packaging_smoke] missing command: ${cmd}" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
require_cmd bash
|
|
require_cmd python3
|
|
require_cmd curl
|
|
require_cmd sha256sum
|
|
|
|
tmp_dir="$(mktemp -d)"
|
|
trap 'rm -rf "$tmp_dir"' EXIT
|
|
|
|
assets_dir="${tmp_dir}/assets"
|
|
bin_root="${tmp_dir}/bin-root"
|
|
mkdir -p "$assets_dir" "$bin_root"
|
|
|
|
asset_v1="${assets_dir}/sing-box-v1"
|
|
asset_v2="${assets_dir}/sing-box-v2"
|
|
|
|
cat >"$asset_v1" <<'EOF'
|
|
#!/usr/bin/env bash
|
|
echo "sing-box v1"
|
|
EOF
|
|
chmod +x "$asset_v1"
|
|
|
|
cat >"$asset_v2" <<'EOF'
|
|
#!/usr/bin/env bash
|
|
echo "sing-box v2"
|
|
EOF
|
|
chmod +x "$asset_v2"
|
|
|
|
sha_v1="$(sha256sum "$asset_v1" | awk '{print $1}')"
|
|
sha_v2="$(sha256sum "$asset_v2" | awk '{print $1}')"
|
|
|
|
manifest_v1="${tmp_dir}/manifest-v1.json"
|
|
manifest_v2="${tmp_dir}/manifest-v2.json"
|
|
|
|
cat >"$manifest_v1" <<EOF
|
|
{
|
|
"schema_version": 1,
|
|
"components": {
|
|
"singbox": {
|
|
"enabled": true,
|
|
"binary_name": "sing-box",
|
|
"targets": {
|
|
"linux-amd64": {
|
|
"version": "1.0.0",
|
|
"url": "file://${asset_v1}",
|
|
"sha256": "${sha_v1}",
|
|
"asset_type": "raw"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
|
|
cat >"$manifest_v2" <<EOF
|
|
{
|
|
"schema_version": 1,
|
|
"components": {
|
|
"singbox": {
|
|
"enabled": true,
|
|
"binary_name": "sing-box",
|
|
"targets": {
|
|
"linux-amd64": {
|
|
"version": "2.0.0",
|
|
"url": "file://${asset_v2}",
|
|
"sha256": "${sha_v2}",
|
|
"asset_type": "raw"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
|
|
echo "[transport_packaging_smoke] install v1"
|
|
"$UPDATER" --manifest "$manifest_v1" --bin-root "$bin_root" --component singbox --target linux-amd64
|
|
out_v1="$("$bin_root/sing-box")"
|
|
if [[ "$out_v1" != "sing-box v1" ]]; then
|
|
echo "[transport_packaging_smoke] expected v1 output, got: ${out_v1}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "[transport_packaging_smoke] update to v2"
|
|
"$UPDATER" --manifest "$manifest_v2" --bin-root "$bin_root" --component singbox --target linux-amd64
|
|
out_v2="$("$bin_root/sing-box")"
|
|
if [[ "$out_v2" != "sing-box v2" ]]; then
|
|
echo "[transport_packaging_smoke] expected v2 output, got: ${out_v2}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "[transport_packaging_smoke] rollback to v1"
|
|
"$ROLLBACK" --bin-root "$bin_root" --component singbox
|
|
out_after_rb="$("$bin_root/sing-box")"
|
|
if [[ "$out_after_rb" != "sing-box v1" ]]; then
|
|
echo "[transport_packaging_smoke] expected rollback to v1, got: ${out_after_rb}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "[transport_packaging_smoke] passed"
|