Skip to content

Commit f4594dc

Browse files
committed
chore: Optimize Alist version detection logic
1 parent 0101e8e commit f4594dc

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

alist/Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@
77
include $(TOPDIR)/rules.mk
88

99
PKG_NAME:=alist
10-
PKG_VERSION:=3.45.0
11-
PKG_WEB_VERSION:=3.45.0
10+
PKG_META:=$(shell $(SHELL) $(CURDIR)/scripts/alist-meta.sh)
11+
12+
PKG_VERSION:=$(word 1,$(PKG_META))
13+
PKG_WEB_VERSION:=$(word 2,$(PKG_META))
1214
PKG_RELEASE:=1
1315

1416
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
1517
PKG_SOURCE_URL:=https://codeload.github.com/AlistGo/alist/tar.gz/v$(PKG_VERSION)?
16-
PKG_HASH:=224119ea5a3b43694e5342c460ab471d6477db1bf7ade5180d542a32363cb097
18+
PKG_HASH:=$(word 3,$(PKG_META))
1719

1820
PKG_LICENSE:=GPL-3.0
1921
PKG_LICENSE_FILE:=LICENSE
20-
PKG_MAINTAINER:=sbwml <admin@cooluc.com>
22+
PKG_MAINTAINER:=sbwml <admin@cooluc.com>, okatu-loli
23+
24+
ifneq ($(words $(PKG_META)),4)
25+
$(error Failed to fetch alist metadata from GitHub)
26+
endif
2127

2228
define Download/$(PKG_NAME)-web
2329
FILE:=$(PKG_NAME)-web-$(PKG_WEB_VERSION).tar.gz
2430
URL_FILE:=dist.tar.gz
2531
URL:=https://github.com/AlistGo/alist-web/releases/download/$(PKG_WEB_VERSION)/
26-
HASH:=408b1822893ba6dd6bbeb4055d6c8b96c178d10f4fbb8e5696cf14dcc88dd2fb
32+
HASH:=$(word 4,$(PKG_META))
2733
endef
2834

2935
PKG_BUILD_DEPENDS:=golang/host

alist/scripts/alist-meta.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)