|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +fetch() { |
| 6 | + url="$1" |
| 7 | + if command -v curl >/dev/null 2>&1; then |
| 8 | + curl -fL --connect-timeout 10 --max-time 60 -sS "$url" |
| 9 | + elif command -v wget >/dev/null 2>&1; then |
| 10 | + wget -qO- --timeout=30 --tries=2 "$url" |
| 11 | + else |
| 12 | + echo "alist-meta: curl/wget not found" >&2 |
| 13 | + return 1 |
| 14 | + fi |
| 15 | +} |
| 16 | + |
| 17 | +download() { |
| 18 | + url="$1" |
| 19 | + dest="$2" |
| 20 | + if command -v curl >/dev/null 2>&1; then |
| 21 | + curl -fL --connect-timeout 10 --max-time 300 -sS "$url" -o "$dest" |
| 22 | + elif command -v wget >/dev/null 2>&1; then |
| 23 | + wget -q -O "$dest" --timeout=60 --tries=2 "$url" |
| 24 | + else |
| 25 | + echo "alist-meta: curl/wget not found" >&2 |
| 26 | + return 1 |
| 27 | + fi |
| 28 | +} |
| 29 | + |
| 30 | +sha256_file() { |
| 31 | + file="$1" |
| 32 | + if command -v sha256sum >/dev/null 2>&1; then |
| 33 | + sha256sum "$file" | awk '{print $1}' |
| 34 | + elif command -v shasum >/dev/null 2>&1; then |
| 35 | + shasum -a 256 "$file" | awk '{print $1}' |
| 36 | + else |
| 37 | + echo "alist-meta: sha256sum/shasum not found" >&2 |
| 38 | + return 1 |
| 39 | + fi |
| 40 | +} |
| 41 | + |
| 42 | +release_json="$(fetch "https://api.github.com/repos/AlistGo/alist/releases/latest")" |
| 43 | +tag_name="$(printf '%s\n' "$release_json" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)" |
| 44 | +tag_name="${tag_name#v}" |
| 45 | + |
| 46 | +if [ -z "$tag_name" ]; then |
| 47 | + echo "alist-meta: failed to parse tag_name from GitHub API" >&2 |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | + |
| 51 | +version="$tag_name" |
| 52 | +pkg_url="https://codeload.github.com/AlistGo/alist/tar.gz/v${version}?" |
| 53 | +web_url="https://github.com/AlistGo/alist-web/releases/download/${version}/dist.tar.gz" |
| 54 | + |
| 55 | +tmpdir="$(mktemp -d)" |
| 56 | +trap 'rm -rf "$tmpdir"' EXIT HUP INT TERM |
| 57 | + |
| 58 | +pkg_file="$tmpdir/alist-${version}.tar.gz" |
| 59 | +web_file="$tmpdir/alist-web-${version}.tar.gz" |
| 60 | + |
| 61 | +download "$pkg_url" "$pkg_file" |
| 62 | +download "$web_url" "$web_file" |
| 63 | + |
| 64 | +pkg_hash="$(sha256_file "$pkg_file")" |
| 65 | +web_hash="$(sha256_file "$web_file")" |
| 66 | + |
| 67 | +printf '%s %s %s %s\n' "$version" "$version" "$pkg_hash" "$web_hash" |
0 commit comments