#!/bin/sh # Rewrite the reference outputs luci/servers.js is checked against (tools/test.sh): # tests/links/.expected.json and tests/yaml/.expected.json, made by mihomo's own # code (tools/servers-ref/main.go). Needs git and Go. # tools/servers-ref.sh mihomo CORE_OFFICIAL of router/mihomo-kit.sh # tools/servers-ref.sh v1.19.34 another tag # After a mihomo update: run it, then tools/test.sh; a FAIL of links/... means mihomo # now converts a link differently and luci/servers.js needs the same change (diff # common/convert between the tags). Review the expected files in git diff. set -eu cd "$(dirname "$0")/.." root=$(pwd) tag=${1:-$(sed -n 's/^CORE_OFFICIAL=//p' router/mihomo-kit.sh)} work=$(mktemp -d) trap 'rm -rf "$work"' EXIT git -c advice.detachedHead=false clone -q --depth 1 --branch "$tag" https://github.com/MetaCubeX/mihomo.git "$work/mihomo" mkdir -p "$work/mihomo/cmd/servers-ref" cp tools/servers-ref/main.go "$work/mihomo/cmd/servers-ref/" (cd "$work/mihomo" && go build -o "$work/servers-ref" ./cmd/servers-ref) # the fixed ws User-Agent of luci/servers.js ua=$(sed -n "s/^[[:space:]]*var USER_AGENT = '\(.*\)';$/\1/p" luci/servers.js) [ -n "$ua" ] || { echo "no USER_AGENT in luci/servers.js" >&2; exit 1; } for f in tests/links/*; do case "$f" in *.expected.json) continue ;; esac "$work/servers-ref" links "$ua" "$f" "${f%.*}.expected.json" >/dev/null 2>&1 echo "mihomo $tag: ${f%.*}.expected.json" done for f in tests/yaml/*.yaml; do "$work/servers-ref" yaml "$f" "${f%.yaml}.expected.json" echo "mihomo $tag: ${f%.yaml}.expected.json" done