update 2026-10-21 06:53:29

This commit is contained in:
action committed 2026-10-21 06:53:29 +08:00
1 parent ee55ecd1ef
commit f144cc6010
238 files changed
+301 -19729

No files matched your search

@@ -1,8 +1,8 @@
#!/bin/sh
# pkg-info.sh <package>
# Prints "<installed>\t<latest>" for the named package, where either field is
# empty when unknown. Used by the Updates view to decide whether to enable
# the [Upgrade] button.
# Prints "<installed>\t<latest>\t<state>" for the named package, where either
# version is empty when unknown. Used by the Updates view to decide whether to
# enable the [Upgrade] button.
PKG="$1"
case "$PKG" in
@@ -12,22 +12,26 @@ esac
installed=""
latest=""
state="absent"
if command -v apk >/dev/null 2>&1; then
if apk info -e "$PKG" >/dev/null 2>&1; then
state="managed"
installed=$(apk list -I "$PKG" 2>/dev/null | awk -v p="$PKG" '
$1 ~ "^" p "-" {
$1 ~ "^" p "-[0-9]" {
sub("^" p "-", "", $1);
print $1;
exit
}
')
[ -n "$installed" ] || state="error"
fi
# apk search treats ^ and $ as literal chars (not regex anchors), so the old
# `apk search "^pkg$"` matched nothing. Enumerate the exact-name package
# across all feeds via `apk list` and take the highest version. Restricting
# to "<pkg>-<digit>" avoids sibling names like <pkg>-geoip / luci-app-<pkg>.
latest=$(apk list "$PKG" 2>/dev/null | awk -v p="$PKG" '
# across configured feeds via `apk list -a` and take the highest version.
# The -a flag excludes locally installed packages that are absent from feeds.
# Restricting to "<pkg>-<digit>" avoids sibling names like <pkg>-geoip.
latest=$(apk list -a "$PKG" 2>/dev/null | awk -v p="$PKG" '
$1 ~ "^" p "-[0-9]" {
v = $1; sub("^" p "-", "", v);
print v
@@ -36,15 +40,22 @@ if command -v apk >/dev/null 2>&1; then
elif command -v opkg >/dev/null 2>&1; then
installed=$(opkg status "$PKG" 2>/dev/null | awk -F': ' '$1=="Version"{print $2; exit}')
latest=$(opkg info "$PKG" 2>/dev/null | awk -F': ' '$1=="Version"{print $2; exit}')
[ -n "$installed" ] && state="managed"
fi
case "$PKG" in
dae|daed)
case "$installed" in
20[0-9][0-9].[0-9]*) ;;
*) installed="" ;;
*) [ -n "$installed" ] && state="foreign"; installed="" ;;
esac
;;
esac
printf '%s\t%s\n' "$installed" "$latest"
if [ "$state" = "absent" ]; then
case "$PKG" in
dae|daed) [ -x "/usr/bin/$PKG" ] && state="manual" ;;
esac
fi
printf '%s\t%s\t%s\n' "$installed" "$latest" "$state"
@@ -2,20 +2,39 @@
# Background apk/opkg update for the Updates view. Returns at once; throttled.
LOCK=/tmp/luci-app-daede.idx.lock
STATUS=/tmp/luci-app-daede.idx.status
LOG=/tmp/luci-app-daede.idx.log
if [ -f "$LOCK" ]; then
write_status() {
printf '%s\n' "$1" > "${STATUS}.$$" && mv "${STATUS}.$$" "$STATUS"
}
if [ -f "$LOCK" ] && [ -f "$STATUS" ]; then
mtime=$(date -r "$LOCK" +%s 2>/dev/null || echo 0)
[ "$(( $(date +%s) - mtime ))" -lt 90 ] && exit 0
fi
: > "$LOCK"
write_status running
(
# -n: skip if a package op holds the shared apk lock (no need to refresh then)
flock -n 9 || exit 0
umask 077
# Wait for package upgrades before refreshing the same apk database.
if command -v apk >/dev/null 2>&1; then
flock -n /tmp/luci-app-daede.apk.lock apk update
flock /tmp/luci-app-daede.apk.lock apk update > "$LOG" 2>&1
rc=$?
elif command -v opkg >/dev/null 2>&1; then
opkg update
opkg update > "$LOG" 2>&1
rc=$?
else
printf '%s\n' 'No supported package manager' > "$LOG"
rc=127
fi
) >/dev/null 2>&1 </dev/null &
if [ "$rc" -eq 0 ]; then
write_status success
else
write_status failed
fi
) 9>/tmp/luci-app-daede.idx.run.lock >/dev/null 2>&1 </dev/null &
exit 0
@@ -50,15 +50,27 @@ fi
if command -v apk >/dev/null 2>&1; then
# shared apk lock with the bg index refresh (avoid "Unable to lock database")
(
flock 9
apk update 2>&1
ver=$(apk list "$PKG" 2>/dev/null | awk -v p="$PKG" '$1 ~ "^" p "-[0-9]" { v=$1; sub("^" p "-", "", v); print v }' | sort -V | tail -1)
flock 9 || exit 1
if ! apk info -e "$PKG" >/dev/null 2>&1; then
echo "result: $PKG 未通过包管理器安装,不能在线升级"
exit 1
fi
if ! apk update 2>&1; then
echo "result: 软件源刷新失败,请检查网络和软件源配置"
exit 1
fi
ver=$(apk list -a "$PKG" 2>/dev/null | awk -v p="$PKG" '$1 ~ "^" p "-[0-9]" { v=$1; sub("^" p "-", "", v); print v }' | sort -V | tail -1)
if [ -n "$ver" ]; then
constraint="$PKG=$ver"
else
echo "result: 软件源中没有找到 $PKG,请检查网络或软件源配置"
exit 1
fi
installed=$(apk list -I "$PKG" 2>/dev/null | awk -v p="$PKG" '$1 ~ "^" p "-[0-9]" { v=$1; sub("^" p "-", "", v); print v; exit }')
if [ -n "$installed" ] && [ "$(printf '%s\n%s\n' "$ver" "$installed" | sort -V | tail -1)" = "$installed" ]; then
echo "result: $PKG 已安装版本不低于软件源版本,无需升级"
exit 2
fi
echo "--- apk add -s $constraint ---"
if ! apk add -s "$constraint" 2>&1; then
@@ -66,14 +78,19 @@ fi
fi
echo "--- apk add $constraint ---"
apk add "$constraint" 2>&1
add_rc=$?
[ "$add_rc" -eq 0 ] || exit 1
if ! apk list -I "$PKG" 2>/dev/null | awk -v p="$PKG" -v v="$ver" '$1 == p "-" v { found = 1 } END { exit !found }'; then
echo "result: $PKG was not upgraded to $ver"
exit 1
fi
exit 0
) 9>/tmp/luci-app-daede.apk.lock
rc=$?
if [ "$rc" != 0 ]; then
if [ "$rc" = 2 ]; then
:
elif [ "$rc" != 0 ]; then
:
elif ! apk list --installed 2>/dev/null | grep -q "^${PKG}-"; then
echo "result: $PKG is not installed"
rc=1
elif apk list -u 2>/dev/null | grep -q "^${PKG}-"; then
echo "result: $PKG still has a pending upgrade"
rc=1
@@ -83,16 +100,26 @@ fi
fi
elif command -v opkg >/dev/null 2>&1; then
echo "--- opkg update ---"
opkg update 2>&1
echo "--- opkg upgrade $PKG ---"
opkg upgrade "$PKG" 2>&1
rc=$?
if opkg update 2>&1; then
echo "--- opkg upgrade $PKG ---"
opkg upgrade "$PKG" 2>&1
rc=$?
else
echo "result: 软件源刷新失败,请检查网络和软件源配置"
rc=1
fi
else
echo "no package manager found"
exit 3
rc=3
fi
if [ "$rc" = 0 ]; then echo "$(date '+%F %T') ✓ 完成"; else echo "$(date '+%F %T') ✗ 失败 (rc=$rc)"; fi
if [ "$rc" = 0 ]; then
echo "$(date '+%F %T') ✓ 完成"
elif [ "$rc" = 2 ]; then
echo "$(date '+%F %T') ✓ 无需升级"
else
echo "$(date '+%F %T') ✗ 失败 (rc=$rc)"
fi
# luci-app-daede upgrade replaces ACL JSON — reload rpcd so changes apply.
if [ "$PKG" = "luci-app-daede" ] && [ "$rc" = "0" ]; then
@@ -20,6 +20,7 @@
"/tmp/luci-app-daede.pkg-dae.log": [ "read" ],
"/tmp/luci-app-daede.pkg-daed.log": [ "read" ],
"/tmp/luci-app-daede.pkg-luci-app-daede.log": [ "read" ],
"/tmp/luci-app-daede.idx.status": [ "read" ],
"/tmp/luci-app-daede.backup.log": [ "read" ],
"/bin/pidof dae": [ "exec" ],
"/bin/pidof daed": [ "exec" ],