platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
161
tests/transport_packaging_auto_update.sh
Executable file
161
tests/transport_packaging_auto_update.sh
Executable file
@@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
AUTO_UPDATER="${ROOT_DIR}/scripts/transport-packaging/auto_update.sh"
|
||||
|
||||
require_cmd() {
|
||||
local cmd="$1"
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
echo "[transport_packaging_auto_update] missing command: ${cmd}" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
require_cmd bash
|
||||
require_cmd sha256sum
|
||||
require_cmd flock
|
||||
|
||||
tmp_dir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmp_dir"' EXIT
|
||||
|
||||
assets_dir="${tmp_dir}/assets"
|
||||
bin_root="${tmp_dir}/bin-root"
|
||||
state_dir="${tmp_dir}/state"
|
||||
mkdir -p "$assets_dir" "$bin_root" "$state_dir"
|
||||
|
||||
asset_v1="${assets_dir}/sing-box-v1"
|
||||
asset_v2="${assets_dir}/sing-box-v2"
|
||||
|
||||
cat >"$asset_v1" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
echo "auto sing-box v1"
|
||||
EOF
|
||||
chmod +x "$asset_v1"
|
||||
|
||||
cat >"$asset_v2" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
echo "auto 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",
|
||||
"rollout": {
|
||||
"stage": "stable",
|
||||
"percent": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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",
|
||||
"rollout": {
|
||||
"stage": "stable",
|
||||
"percent": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "[transport_packaging_auto_update] disabled -> skip"
|
||||
"$AUTO_UPDATER" \
|
||||
--enabled false \
|
||||
--manifest "$manifest_v1" \
|
||||
--bin-root "$bin_root" \
|
||||
--state-dir "$state_dir" \
|
||||
--component singbox \
|
||||
--target linux-amd64 \
|
||||
--min-interval-sec 3600
|
||||
if [[ -e "${bin_root}/sing-box" ]]; then
|
||||
echo "[transport_packaging_auto_update] expected no install when disabled" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[transport_packaging_auto_update] enabled -> install v1"
|
||||
"$AUTO_UPDATER" \
|
||||
--enabled true \
|
||||
--manifest "$manifest_v1" \
|
||||
--bin-root "$bin_root" \
|
||||
--state-dir "$state_dir" \
|
||||
--component singbox \
|
||||
--target linux-amd64 \
|
||||
--min-interval-sec 3600
|
||||
out_v1="$("${bin_root}/sing-box")"
|
||||
if [[ "$out_v1" != "auto sing-box v1" ]]; then
|
||||
echo "[transport_packaging_auto_update] expected v1 output, got: ${out_v1}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[transport_packaging_auto_update] interval gate -> skip update to v2"
|
||||
"$AUTO_UPDATER" \
|
||||
--enabled true \
|
||||
--manifest "$manifest_v2" \
|
||||
--bin-root "$bin_root" \
|
||||
--state-dir "$state_dir" \
|
||||
--component singbox \
|
||||
--target linux-amd64 \
|
||||
--min-interval-sec 3600
|
||||
out_after_gate="$("${bin_root}/sing-box")"
|
||||
if [[ "$out_after_gate" != "auto sing-box v1" ]]; then
|
||||
echo "[transport_packaging_auto_update] expected interval-gated v1 output, got: ${out_after_gate}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[transport_packaging_auto_update] force-now -> install v2"
|
||||
"$AUTO_UPDATER" \
|
||||
--enabled true \
|
||||
--manifest "$manifest_v2" \
|
||||
--bin-root "$bin_root" \
|
||||
--state-dir "$state_dir" \
|
||||
--component singbox \
|
||||
--target linux-amd64 \
|
||||
--min-interval-sec 3600 \
|
||||
--force-now
|
||||
out_v2="$("${bin_root}/sing-box")"
|
||||
if [[ "$out_v2" != "auto sing-box v2" ]]; then
|
||||
echo "[transport_packaging_auto_update] expected forced v2 output, got: ${out_v2}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -s "${state_dir}/last_success_epoch" ]]; then
|
||||
echo "[transport_packaging_auto_update] expected last_success_epoch file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[transport_packaging_auto_update] passed"
|
||||
Reference in New Issue
Block a user