Created
January 30, 2026 14:15
-
-
Save hde-moff/65eb1699e1fd29b92af86435d9d36d0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -eu | |
| # Mirror IP addresses for updates.cdn-apple.com | |
| MIRRORS=" | |
| 17.253.53.35 | |
| 17.253.53.203 | |
| 17.253.53.202 | |
| 37.143.84.100 | |
| 37.143.84.113 | |
| 91.241.30.48 | |
| " | |
| STAT_FILE="$HOME/.aria2-cdn-stats" | |
| touch "$STAT_FILE" | |
| URL="${1:?Usage: $0 <URL>}" | |
| FILENAME="${URL##*/}" | |
| # Fetch the expected SHA-256 hash from the header | |
| printf 'Fetching SHA-256 hash...\n' | |
| EXPECTED_HASH=$(curl -sI "$URL" | tr -d '\r' | awk -F': ' 'tolower($1) == "x-amz-meta-digest-sha256" {print $2}') | |
| if [ -z "$EXPECTED_HASH" ]; then | |
| printf 'Error: could not retrieve x-amz-meta-digest-sha256 header.\n' >&2 | |
| exit 1 | |
| fi | |
| printf 'Expected SHA-256: %s\n' "$EXPECTED_HASH" | |
| # Build the list of mirror URIs by replacing the hostname with each IP | |
| URIS="" | |
| COUNT=0 | |
| for IP in $MIRRORS; do | |
| URI=$(printf '%s' "$URL" | sed "s|updates\.cdn-apple\.com|${IP}|") | |
| URIS="${URIS} ${URI}" | |
| COUNT=$((COUNT + 1)) | |
| done | |
| SPLIT=12 | |
| # Download using aria2c | |
| printf 'Downloading with %d mirrors (%d connections)...\n' "$COUNT" "$SPLIT" | |
| aria2c \ | |
| --check-certificate=false \ | |
| --file-allocation=falloc \ | |
| --header='Host: updates.cdn-apple.com' \ | |
| --split="$SPLIT" \ | |
| --max-connection-per-server=12 \ | |
| --uri-selector=adaptive \ | |
| --server-stat-if="$STAT_FILE" \ | |
| --server-stat-of="$STAT_FILE" \ | |
| --out="$FILENAME" \ | |
| $URIS | |
| # Verify the downloaded file | |
| printf 'Verifying SHA-256...\n' | |
| ACTUAL_HASH=$(openssl dgst -sha256 "$FILENAME" | awk '{print $NF}') | |
| if [ "$ACTUAL_HASH" = "$EXPECTED_HASH" ]; then | |
| printf 'OK: hash matches.\n' | |
| else | |
| printf 'MISMATCH!\n expected: %s\n actual: %s\n' "$EXPECTED_HASH" "$ACTUAL_HASH" >&2 | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment