| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | cd "$(dirname "$0")/.." |
| 4 | directory="$PWD/_output/linux-deps" |
| 5 | mkdir -p "$directory" |
| 6 | for component in mihomo mihomoSource; do |
| 7 | metadata=$(node -e 'const d=JSON.parse(require("fs").readFileSync("packaging/linux/dependencies.json"))[process.argv[1]]; console.log([d.file,d.url,d.sha256].join("\t"))' "$component") |
| 8 | IFS=$'\t' read -r file url checksum <<< "$metadata" |
| 9 | archive="$directory/$file" |
| 10 | if [[ ! -f "$archive" ]]; then |
| 11 | curl --fail --location --retry 2 --connect-timeout 15 --max-time 300 "$url" -o "$archive.part" |
| 12 | mv "$archive.part" "$archive" |
| 13 | fi |
| 14 | actual=$(shasum -a 256 "$archive" | cut -d ' ' -f 1) |
| 15 | [[ "$actual" == "$checksum" ]] || { echo "Checksum mismatch: $file" >&2; exit 1; } |
| 16 | done |
| 17 | gzip -dc "$directory/mihomo-linux-amd64-compatible-v1.19.33.gz" > "$directory/mihomo.part" |
| 18 | chmod 755 "$directory/mihomo.part" |
| 19 | mv "$directory/mihomo.part" "$directory/mihomo" |
| 20 | tar -xOf "$directory/mihomo-v1.19.33-source.tar.gz" mihomo-1.19.33/LICENSE > "$directory/LICENSE" |
| 21 | cat > "$directory/NOTICE" <<'EOF' |
| 22 | Mihomo v1.19.33, unmodified executable distributed under GPL-3.0. |
| 23 | Source: https://github.com/MetaCubeX/mihomo/tree/v1.19.33 |
| 24 | Corresponding source accompanies the Cage Linux release as mihomo-v1.19.33-source.tar.gz. |
| 25 | Binary checksum and download URL: packaging/linux/dependencies.json in Cage sources. |
| 26 | EOF |