🗽 Sync 2026-10-23 00:46:23

This commit is contained in:
github-actions[bot] committed 2026-10-23 00:46:23 +08:00
1 parent 6032a57538
commit 2b29b0c4e1
112 files changed
+1859 -6208

No files matched your search

@@ -4,7 +4,17 @@
readonly state_dir='/var/run/argon-update'
readonly cache_file='/var/run/argon-update/release.json'
readonly release_api='https://api.github.com/repos/jerrykuku/luci-theme-argon/releases/latest'
readonly sources_file='/usr/share/argon/update-sources.json'
readonly repository='jerrykuku/luci-theme-argon'
opkg_query() (
# OPKG locks its database even for status and comparison commands. Keep our
# RPC reads from racing the worker's version checks against that native lock.
prepare_state || exit 1
exec 6>"$state_dir/package-query.lock"
flock -w 2 6 || exit 1
opkg "$@"
)
installed_version() {
current_version=''
@@ -15,7 +25,7 @@ installed_version() {
[ -z "$current_version" ] || package_manager=apk
fi
if [ -z "$current_version" ] && command -v opkg >/dev/null 2>&1; then
current_version="$(opkg status luci-theme-argon 2>/dev/null | awk '
current_version="$(opkg_query status luci-theme-argon 2>/dev/null | awk '
/^Version: / { version=$2 }
/^Status: .* installed$/ { installed=1 }
END { if (installed) print version }')"
@@ -31,9 +41,110 @@ read_cache() {
[ -f "$cache_file" ] && [ ! -L "$cache_file" ] &&
[ "$(wc -c < "$cache_file")" -le 1048576 ] || return 1
json_load_file "$cache_file" || return 1
json_get_var schema schema
json_get_var cached_repository repository
json_get_var tag tag
json_get_var checked_at checked_at
valid_tag "$tag" && printf '%s\n' "$checked_at" | grep -Eq '^[0-9]{1,11}$'
[ "$schema" = 1 ] && [ "$cached_repository" = "$repository" ] &&
valid_tag "$tag" && printf '%s\n' "$checked_at" | grep -Eq '^[0-9]{1,11}$'
}
valid_source() {
[ "${#1}" -le 512 ] && printf '%s\n' "$1" |
grep -Eq '^https://[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?(/[A-Za-z0-9._~-]+)+$'
}
load_sources() {
primary_url=''
fallback_url='https://jerrykuku.github.io/luci-theme-argon/updates/stable.json'
if [ -f "$sources_file" ] && [ ! -L "$sources_file" ] &&
[ "$(wc -c < "$sources_file")" -le 4096 ] && json_load_file "$sources_file"; then
json_get_var configured_primary primary
json_get_var configured_fallback fallback
valid_source "$configured_primary" && primary_url="$configured_primary"
valid_source "$configured_fallback" && fallback_url="$configured_fallback"
fi
}
normalize_manifest() {
json_load_file "$1" || return 1
json_get_var schema schema
json_get_var manifest_repository repository
json_get_var tag tag
[ "$schema" = 1 ] && [ "$manifest_repository" = "$repository" ] && valid_tag "$tag" || return 1
# Both formats must be complete. Never combine fields from different sources.
package_manager=apk
select_package || return 1
package_manager=opkg
select_package || return 1
for field in ipk apk ipk_sha256 apk_sha256 ipk_size apk_size published_at notes; do
json_get_var "$field" "$field"
done
printf '%s\n' "$published_at" | grep -Eq '^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$' || return 1
[ "${#notes}" -le 131072 ] || return 1
# Copy only the contract fields, not remote status, URLs or local timestamps.
json_init
json_add_int schema 1
json_add_string repository "$repository"
json_add_string tag "$tag"
json_add_string published_at "$published_at"
json_add_string notes "$notes"
json_add_string ipk "$ipk"
json_add_string apk "$apk"
json_add_string ipk_sha256 "$ipk_sha256"
json_add_string apk_sha256 "$apk_sha256"
json_add_int ipk_size "$ipk_size"
json_add_int apk_size "$apk_size"
json_add_int checked_at "$(date +%s)"
}
check_failure() {
read_cache || json_init
json_add_int retry_at "$retry_at"
respond 1
}
check_updates() {
prepare_state || { fail 1; return; }
# Separate from the installation lock. Concurrent tabs reuse the first check.
exec 7>"$state_dir/check.lock"
flock -w 15 7 || { retry_at="$(($(date +%s) + 5))"; check_failure; return; }
now="$(date +%s)"
if read_cache && [ "$now" -ge "$checked_at" ] && [ "$((now - checked_at))" -lt 300 ]; then
respond 0
return
fi
retry_at=0
if [ -f "$state_dir/retry_at" ] && [ ! -L "$state_dir/retry_at" ] &&
[ "$(wc -c < "$state_dir/retry_at")" -le 12 ]; then
retry_at="$(cat "$state_dir/retry_at")"
fi
if printf '%s\n' "$retry_at" | grep -Eq '^[0-9]{1,11}$' &&
[ "$retry_at" -gt "$now" ] && [ "$((retry_at - now))" -le 60 ]; then
check_failure
return
fi
load_sources
work="$(mktemp -d "$state_dir/check.XXXXXX")" || { fail 1; return; }
trap 'rm -rf "$work"' EXIT
trap 'exit 1' HUP INT TERM
for source_url in "$primary_url" "$fallback_url"; do
[ -n "$source_url" ] || continue
# The two attempts together stay below rpcd's request timeout.
if (ulimit -f 2048; timeout -k 1 5 wget -T 4 -q -U 'luci-theme-argon' \
-O "$work/manifest.json" "$source_url") 2>/dev/null &&
[ "$(wc -c < "$work/manifest.json")" -le 1048576 ] && normalize_manifest "$work/manifest.json"; then
json_dump > "$work/cache.json"
[ ! -L "$cache_file" ] && mv -f "$work/cache.json" "$cache_file" 2>/dev/null || :
rm -f "$state_dir/retry_at"
respond 0
return
fi
[ "$primary_url" != "$fallback_url" ] || break
done
retry_at="$(($(date +%s) + 60))"
printf '%s\n' "$retry_at" > "$state_dir/retry_at"
check_failure
}
select_package() {
@@ -57,7 +168,7 @@ select_package() {
esac
printf '%s\n' "$revision" | grep -Eq '^[0-9]{1,8}$' &&
printf '%s\n' "$digest" | grep -Eq '^[a-f0-9]{64}$' &&
printf '%s\n' "$size" | grep -Eq '^[0-9]{1,8}$' &&
printf '%s\n' "$size" | grep -Eq '^[1-9][0-9]{0,7}$' &&
[ "$size" -gt 0 ] && [ "$size" -le 8388608 ]
}
@@ -66,13 +177,13 @@ is_upgrade() {
printf '%s\n' "$current_version" | grep -Eq '^[0-9]+(\.[0-9]+){1,3}((~|_)(alpha|beta|rc)[0-9]+|-(alpha|beta|rc)\.[0-9]+)?(-r?[0-9]+)?$' || return 1
case "$package_manager" in
apk) [ "$(apk version -t "$current_version" "$target_version" 2>/dev/null)" = '<' ] ;;
opkg) opkg compare-versions "$current_version" '<<' "$target_version" ;;
opkg) opkg_query compare-versions "$current_version" '<<' "$target_version" ;;
*) return 1 ;;
esac
}
prepare_state() {
[ ! -L "$state_dir" ] && { [ -d "$state_dir" ] || mkdir -m 700 "$state_dir"; } &&
[ ! -L "$state_dir" ] && mkdir -p -m 700 "$state_dir" && [ ! -L "$state_dir" ] &&
command -v flock >/dev/null 2>&1 && command -v sha256sum >/dev/null 2>&1 && command -v timeout >/dev/null 2>&1
}
@@ -129,7 +240,11 @@ respond() {
# Read after the job snapshot so a completed job reports its installed version.
installed_version
can_upgrade=0
if select_package && is_upgrade && command -v flock >/dev/null 2>&1 && command -v sha256sum >/dev/null 2>&1 && command -v timeout >/dev/null 2>&1; then
now="$(date +%s)"
json_get_var checked_at checked_at
if [ "$1" = 0 ] && printf '%s\n' "$checked_at" | grep -Eq '^[0-9]{1,11}$' &&
[ "$now" -ge "$checked_at" ] && [ "$((now - checked_at))" -lt 300 ] &&
select_package && is_upgrade && command -v flock >/dev/null 2>&1 && command -v sha256sum >/dev/null 2>&1 && command -v timeout >/dev/null 2>&1; then
can_upgrade=1
fi
json_add_int result "$1"
@@ -260,92 +375,6 @@ call)
respond 0
exit 0
fi
now="$(date +%s)"
if read_cache && [ "$now" -ge "$checked_at" ] && [ "$((now - checked_at))" -lt 300 ]; then
respond 0
exit 0
fi
[ -L "$state_dir" ] || [ -d "$state_dir" ] || mkdir -m 700 "$state_dir" 2>/dev/null || :
umask 077
work="$(mktemp -d /tmp/argon-update.XXXXXX)" || { fail 1; exit 0; }
trap 'rm -rf "$work"' EXIT
trap 'exit 1' HUP INT TERM
# Bound the request to less than rpcd's timeout and limit the response size.
(ulimit -f 2048; timeout -k 2 12 wget -T 10 -q -U 'luci-theme-argon' \
--header='Accept: application/vnd.github+json' \
--header='Cache-Control: no-cache' \
-O "$work/release.json" "$release_api") 2>/dev/null || { fail 1; exit 0; }
[ "$(wc -c < "$work/release.json")" -le 1048576 ] &&
json_load_file "$work/release.json" || { fail 2; exit 0; }
json_get_var tag tag_name
json_get_var draft draft
json_get_var prerelease prerelease
valid_tag "$tag" && [ "$draft" = 0 ] && [ "$prerelease" = 0 ] || { fail 2; exit 0; }
json_get_var published_at published_at
json_get_var notes body
base="${tag#v}"
ipk=''
apk=''
ipk_sha256=''
apk_sha256=''
ipk_size=0
apk_size=0
ipk_revision=-1
apk_revision=-1
if json_select assets; then
json_get_keys asset_keys
for asset_key in $asset_keys; do
json_select "$asset_key" || continue
json_get_var asset name
json_get_var asset_digest digest
json_get_var asset_size size
# Older releases may not expose a checksum. Keep manual downloads,
# but only checksum-backed assets can be installed through this RPC.
asset_digest="${asset_digest#sha256:}"
printf '%s\n' "$asset_digest" | grep -Eq '^[a-f0-9]{64}$' || asset_digest=''
printf '%s\n' "$asset_size" | grep -Eq '^[0-9]{1,8}$' || asset_size=0
case "$asset" in
"luci-theme-argon_${base}"*_all.ipk)
revision="${asset#luci-theme-argon_${base}}"
revision="${revision%_all.ipk}"
case "$revision" in '') revision=1 ;; -*) revision="${revision#-}" ;; *) revision='' ;; esac
if printf '%s\n' "$revision" | grep -Eq '^[0-9]{1,8}$' && [ "$revision" -gt "$ipk_revision" ]; then
ipk="$asset"
ipk_sha256="$asset_digest"
ipk_size="$asset_size"
ipk_revision="$revision"
fi
;;
"luci-theme-argon-${base}-r"*.apk)
revision="${asset#luci-theme-argon-${base}-r}"
revision="${revision%.apk}"
if printf '%s\n' "$revision" | grep -Eq '^[0-9]{1,8}$' && [ "$revision" -gt "$apk_revision" ]; then
apk="$asset"
apk_sha256="$asset_digest"
apk_size="$asset_size"
apk_revision="$revision"
fi
;;
esac
json_select ..
done
fi
json_init
json_add_string tag "$tag"
json_add_string published_at "$published_at"
json_add_string notes "$notes"
json_add_string ipk "$ipk"
json_add_string apk "$apk"
json_add_string ipk_sha256 "$ipk_sha256"
json_add_string apk_sha256 "$apk_sha256"
json_add_int ipk_size "$ipk_size"
json_add_int apk_size "$apk_size"
json_add_int checked_at "$now"
json_dump > "$work/cache.json"
# Cache only successful checks, atomically; a failed cache write is nonfatal.
if [ ! -L "$cache_file" ] && { [ ! -e "$cache_file" ] || [ -f "$cache_file" ]; }; then
mv -f "$work/cache.json" "$cache_file" 2>/dev/null || :
fi
respond 0
check_updates
;;
esac
@@ -0,0 +1,4 @@
{
"primary": "",
"fallback": "https://jerrykuku.github.io/luci-theme-argon/updates/stable.json"
}