| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | cd "$(dirname "$0")/.." |
| 4 | version=v1.19.33 |
| 5 | case "${CAGE_CORE_ARCH:-$(uname -m)}" in |
| 6 | arm64) asset="mihomo-darwin-arm64-$version.gz"; checksum=060b64b0f2c9a310831db0fe4adb2878de67bfa606c311813c1f13966aa504b6 ;; |
| 7 | x86_64|amd64) asset="mihomo-darwin-amd64-compatible-$version.gz"; checksum=eefe967b74312f70b64efa0dfa54929d00c7af8e94416e1b12df09863a40f35b ;; |
| 8 | *) echo 'Unsupported Cage proxy-core architecture' >&2; exit 1 ;; |
| 9 | esac |
| 10 | directory=_output/proxy-core |
| 11 | mkdir -p "$directory" |
| 12 | archive="$directory/$asset" |
| 13 | if [[ ! -f "$archive" ]]; then |
| 14 | curl --fail --location --retry 2 --connect-timeout 15 --max-time 180 "https://github.com/MetaCubeX/mihomo/releases/download/$version/$asset" -o "$archive.part" |
| 15 | mv "$archive.part" "$archive" |
| 16 | fi |
| 17 | actual="$(shasum -a 256 "$archive" | cut -d ' ' -f 1)" |
| 18 | if [[ "$actual" != "$checksum" ]]; then echo 'Cage proxy-core archive checksum mismatch' >&2; exit 1; fi |
| 19 | gzip -dc "$archive" > "$directory/mihomo.part" |
| 20 | chmod 755 "$directory/mihomo.part" |
| 21 | mv "$directory/mihomo.part" "$directory/mihomo" |
| 22 | if [[ ! -f "$directory/LICENSE" ]]; then |
| 23 | curl --fail --location --retry 2 --connect-timeout 15 --max-time 60 "https://raw.githubusercontent.com/MetaCubeX/mihomo/$version/LICENSE" -o "$directory/LICENSE.part" |
| 24 | mv "$directory/LICENSE.part" "$directory/LICENSE" |
| 25 | fi |
| 26 | cat > "$directory/NOTICE" <<EOF |
| 27 | Mihomo $version, distributed as a separate executable by Cage. |
| 28 | Upstream: https://github.com/MetaCubeX/mihomo |
| 29 | Source for this unmodified binary: https://github.com/MetaCubeX/mihomo/archive/refs/tags/$version.tar.gz |
| 30 | License: GPL-3.0. See LICENSE. |
| 31 | Archive: $asset |
| 32 | SHA-256: $checksum |
| 33 | Release digest: https://api.github.com/repos/MetaCubeX/mihomo/releases/tags/$version |
| 34 | EOF |
| 35 | "$directory/mihomo" -v |