mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-11-14 04:07:56 +08:00
update 2026-11-04 12:30:17
This commit is contained in:
1 parent
1b82056d99
commit
b1cd3aafd3
1152 files changed
+575878
-7
No files matched your search
Executable
+1257
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
# geo-cron.sh enable|disable
|
||||
# Manage the geo auto-update crontab entry. enable reads the schedule from
|
||||
# honk.main.geo_auto_freq (daily|weekly); both actions are idempotent.
|
||||
|
||||
ACTION="$1"
|
||||
case "$ACTION" in
|
||||
enable|disable) ;;
|
||||
*) echo "usage: $0 enable|disable" >&2; exit 64 ;;
|
||||
esac
|
||||
CRONTAB="/etc/crontabs/root"
|
||||
TAG="# luci-app-honk geo-update"
|
||||
SCRIPT="/usr/share/luci-app-honk/update-geo.sh"
|
||||
|
||||
# Drop any previous honk geo entry (tag line + its command line).
|
||||
clean() {
|
||||
[ -f "$CRONTAB" ] || return 0
|
||||
grep -vF -e "$TAG" -e "$SCRIPT" "$CRONTAB" > "$CRONTAB.tmp" 2>/dev/null
|
||||
mv "$CRONTAB.tmp" "$CRONTAB"
|
||||
}
|
||||
|
||||
clean
|
||||
|
||||
if [ "$ACTION" = "enable" ]; then
|
||||
case "$(uci -q get honk.main.geo_auto_freq)" in
|
||||
weekly) sched="17 4 * * 0" ;; # Sunday 04:17
|
||||
*) sched="17 4 * * *" ;; # every day 04:17
|
||||
esac
|
||||
mkdir -p /etc/crontabs
|
||||
{
|
||||
echo "$TAG"
|
||||
echo "$sched $SCRIPT geoip; $SCRIPT geosite"
|
||||
} >> "$CRONTAB"
|
||||
/etc/init.d/cron enable >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
/etc/init.d/cron restart >/dev/null 2>&1
|
||||
exit 0
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# pkg-info.sh <honk|luci-app-honk>
|
||||
# Prints "<installed>\t<latest>" for the named package, either field empty when
|
||||
# unknown. Used by the Maintenance view to decide whether to enable [升级].
|
||||
|
||||
PKG="$1"
|
||||
case "$PKG" in
|
||||
honk|luci-app-honk) ;;
|
||||
*) printf '\t\n'; exit 64 ;;
|
||||
esac
|
||||
|
||||
installed=""
|
||||
latest=""
|
||||
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
if apk info -e "$PKG" >/dev/null 2>&1; then
|
||||
installed=$(apk list -I "$PKG" 2>/dev/null | awk -v p="$PKG" '
|
||||
$1 ~ "^" p "-" {
|
||||
sub("^" p "-", "", $1);
|
||||
print $1;
|
||||
exit
|
||||
}
|
||||
')
|
||||
fi
|
||||
latest=$(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)
|
||||
fi
|
||||
|
||||
printf '%s\t%s\n' "$installed" "$latest"
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# Background apk index refresh for the Maintenance view. Returns at once.
|
||||
|
||||
LOCK=/tmp/luci-app-honk.idx.lock
|
||||
|
||||
if [ -f "$LOCK" ]; then
|
||||
mtime=$(date -r "$LOCK" +%s 2>/dev/null || echo 0)
|
||||
[ "$(( $(date +%s) - mtime ))" -lt 90 ] && exit 0
|
||||
fi
|
||||
: > "$LOCK"
|
||||
|
||||
(
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
flock -n /tmp/luci-app-honk.apk.lock apk update
|
||||
fi
|
||||
) >/dev/null 2>&1 </dev/null &
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,96 @@
|
||||
#!/bin/sh
|
||||
# update-geo.sh <geoip|geosite>
|
||||
# Fork-and-detach so the LuCI RPC call returns immediately. The maintenance
|
||||
# card polls the .dat file's mtime/size to detect completion. A lock file
|
||||
# in /tmp prevents concurrent runs.
|
||||
|
||||
TYPE="$1"
|
||||
# Default source: Loyalsoldier/v2ray-rules-dat — daily-built, China-optimized,
|
||||
# ships both geoip.dat and geosite.dat. Users can override per-type via
|
||||
# honk.main.geoip_url / geosite_url (empty falls back to the default below).
|
||||
case "$TYPE" in
|
||||
geoip)
|
||||
DEF_URL="https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"
|
||||
URL="$(uci -q get honk.main.geoip_url)"
|
||||
DEST="/usr/share/v2ray/geoip.dat"
|
||||
;;
|
||||
geosite)
|
||||
DEF_URL="https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
|
||||
URL="$(uci -q get honk.main.geosite_url)"
|
||||
DEST="/usr/share/v2ray/geosite.dat"
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 <geoip|geosite>" >&2
|
||||
exit 64
|
||||
;;
|
||||
esac
|
||||
[ -n "$URL" ] || URL="$DEF_URL"
|
||||
|
||||
LOCK="/tmp/luci-app-honk.${TYPE}.lock"
|
||||
LOG="/tmp/luci-app-honk.${TYPE}.log"
|
||||
|
||||
schedule_backend_reload() {
|
||||
if /bin/pidof honk-core >/dev/null 2>&1; then
|
||||
(
|
||||
sleep 25
|
||||
if /usr/bin/honk-core reload >/dev/null 2>&1; then
|
||||
echo "$(date '+%F %T') reloaded honk-core"
|
||||
else
|
||||
echo "$(date '+%F %T') honk-core reload failed"
|
||||
fi
|
||||
) </dev/null >>"$LOG" 2>&1 &
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -f "$LOCK" ]; then
|
||||
# Lock is fresh (< 5 min)? Refuse. Stale? Remove and proceed.
|
||||
mtime=$(date -r "$LOCK" +%s 2>/dev/null || echo 0)
|
||||
age=$(( $(date +%s) - mtime ))
|
||||
if [ "$age" -lt 300 ]; then
|
||||
echo "${TYPE} update already in progress (PID $(cat "$LOCK" 2>/dev/null), age ${age}s)" >&2
|
||||
exit 75
|
||||
fi
|
||||
rm -f "$LOCK"
|
||||
fi
|
||||
|
||||
if ! ( set -C; echo "$$" >"$LOCK" ) 2>/dev/null; then
|
||||
echo "${TYPE} update already in progress" >&2
|
||||
exit 75
|
||||
fi
|
||||
|
||||
# Spawn detached worker — parent returns immediately to LuCI.
|
||||
(
|
||||
exec >"$LOG" 2>&1
|
||||
trap 'rm -f "$LOCK"' EXIT INT TERM
|
||||
|
||||
rc=0
|
||||
TMP="${DEST}.new"
|
||||
mkdir -p "$(dirname "$DEST")"
|
||||
echo "$(date '+%F %T') begin: $URL"
|
||||
|
||||
if ! curl -fsSL --proto '=http,https' --proto-redir '=http,https' --connect-timeout 15 --max-time 240 -o "$TMP" "$URL"; then
|
||||
echo "$(date '+%F %T') download failed"
|
||||
rm -f "$TMP"
|
||||
rc=1
|
||||
else
|
||||
size=$(wc -c < "$TMP" 2>/dev/null || echo 0)
|
||||
magic=$(hexdump -n 1 -e '1/1 "%02x"' "$TMP" 2>/dev/null)
|
||||
if [ "$size" -lt 1024 ]; then
|
||||
echo "$(date '+%F %T') file too small ($size bytes)"
|
||||
rm -f "$TMP"
|
||||
rc=2
|
||||
elif [ "$magic" != "0a" ]; then
|
||||
echo "$(date '+%F %T') invalid geodata format"
|
||||
rm -f "$TMP"
|
||||
rc=3
|
||||
else
|
||||
mv "$TMP" "$DEST"
|
||||
echo "$(date '+%F %T') updated $DEST ($size bytes)"
|
||||
schedule_backend_reload
|
||||
fi
|
||||
fi
|
||||
if [ "$rc" = 0 ]; then echo "$(date '+%F %T') ✓ 完成"; else echo "$(date '+%F %T') ✗ 失败 (rc=$rc)"; fi
|
||||
) </dev/null >/dev/null 2>&1 &
|
||||
|
||||
echo "started in background, see $LOG"
|
||||
exit 0
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# update-pkg.sh <honk|luci-app-honk>
|
||||
# Refresh package indexes and upgrade the named package via apk. Forks to
|
||||
# background; the result is streamed to /tmp/luci-app-honk.pkg.<name>.log.
|
||||
|
||||
PKG="$1"
|
||||
case "$PKG" in
|
||||
honk|luci-app-honk) ;;
|
||||
*)
|
||||
echo "usage: $0 <honk|luci-app-honk>" >&2
|
||||
exit 64
|
||||
;;
|
||||
esac
|
||||
|
||||
# Run from a /tmp copy so upgrading luci-app-honk (which replaces this script)
|
||||
# cannot corrupt the in-flight upgrade.
|
||||
case "$0" in
|
||||
/tmp/.honk-upd-*) ;;
|
||||
*)
|
||||
_self="/tmp/.honk-upd-$$"
|
||||
cp "$0" "$_self" 2>/dev/null && exec sh "$_self" "$@"
|
||||
;;
|
||||
esac
|
||||
|
||||
LOCK="/tmp/luci-app-honk.pkg-${PKG}.lock"
|
||||
LOG="/tmp/luci-app-honk.pkg-${PKG}.log"
|
||||
|
||||
. /usr/share/honk/lifecycle.sh 2>/dev/null || :
|
||||
|
||||
# 运行状态与恢复交给 lifecycle:它已经处理 dae0/BPF 排空、崩溃重启和就绪判定。
|
||||
service_running() {
|
||||
honk_lifecycle_managed_pid >/dev/null 2>&1
|
||||
}
|
||||
|
||||
restore_service_state() {
|
||||
if [ "$was_running" = 1 ]; then
|
||||
echo "--- 升级前为运行状态,重启加载新内核 ---"
|
||||
if honk_lifecycle_restart 30 >/dev/null 2>&1; then
|
||||
echo "result: 服务已恢复运行"
|
||||
return 0
|
||||
fi
|
||||
echo "result: 服务重启失败"
|
||||
return 1
|
||||
fi
|
||||
if service_running; then
|
||||
echo "--- 升级前为停止状态,停止服务 ---"
|
||||
honk_lifecycle_stop 30 >/dev/null 2>&1 || {
|
||||
echo "result: 服务停止或资源排空失败"
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
echo "result: 服务保持停止"
|
||||
return 0
|
||||
}
|
||||
|
||||
if [ -f "$LOCK" ]; then
|
||||
mtime=$(date -r "$LOCK" +%s 2>/dev/null || echo 0)
|
||||
age=$(( $(date +%s) - mtime ))
|
||||
if [ "$age" -lt 300 ]; then
|
||||
echo "${PKG} update already in progress (PID $(cat "$LOCK" 2>/dev/null), age ${age}s)" >&2
|
||||
exit 75
|
||||
fi
|
||||
rm -f "$LOCK"
|
||||
fi
|
||||
|
||||
if ! ( set -C; echo "$$" >"$LOCK" ) 2>/dev/null; then
|
||||
echo "${PKG} update already in progress" >&2
|
||||
exit 75
|
||||
fi
|
||||
|
||||
(
|
||||
exec >"$LOG" 2>&1
|
||||
trap 'rm -f "$LOCK"; [ "${0#/tmp/.honk-upd-}" != "$0" ] && rm -f "$0"' EXIT INT TERM
|
||||
|
||||
echo "$(date '+%F %T') begin upgrade: $PKG"
|
||||
was_running=0
|
||||
service_running && was_running=1
|
||||
echo "升级前服务状态: $([ "$was_running" = 1 ] && echo 运行中 || echo 已停止)"
|
||||
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
(
|
||||
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)
|
||||
if [ -n "$ver" ]; then
|
||||
constraint="$PKG=$ver"
|
||||
else
|
||||
echo "result: 软件源中没有找到 $PKG,请检查网络或软件源配置"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "--- apk add -s $constraint ---"
|
||||
if ! apk add -s "$constraint" 2>&1; then
|
||||
echo "note: apk 预检失败,通常是系统上其它软件包的问题,继续尝试升级"
|
||||
fi
|
||||
echo "--- apk add $constraint ---"
|
||||
apk add "$constraint" 2>&1
|
||||
exit 0
|
||||
) 9>/tmp/luci-app-honk.apk.lock
|
||||
rc=$?
|
||||
if [ "$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
|
||||
else
|
||||
echo "result: $PKG is at the latest available version"
|
||||
rc=0
|
||||
fi
|
||||
else
|
||||
echo "no package manager found"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
service_rc=0
|
||||
if [ "$rc" = "0" ]; then
|
||||
echo "reloading rpcd to pick up new scripts"
|
||||
/etc/init.d/rpcd reload 2>&1
|
||||
restore_service_state || service_rc=$?
|
||||
fi
|
||||
|
||||
# 前端轮询见到 ✓/✗ 即停止,结论只在这里输出一次。
|
||||
if [ "$rc" != "0" ]; then
|
||||
echo "$(date '+%F %T') ✗ 升级失败 (rc=$rc)"
|
||||
elif [ "$service_rc" != "0" ]; then
|
||||
echo "$(date '+%F %T') ✗ 软件包升级成功,但服务启动失败,请查看日志后手动启动"
|
||||
else
|
||||
echo "$(date '+%F %T') ✓ 完成"
|
||||
fi
|
||||
) </dev/null >/dev/null 2>&1 &
|
||||
|
||||
echo "started in background, see $LOG"
|
||||
exit 0
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"admin/services/honk": {
|
||||
"title": "Honk",
|
||||
"order": 35,
|
||||
"action": {
|
||||
"type": "firstchild"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-honk" ]
|
||||
}
|
||||
},
|
||||
"admin/services/honk/overview": {
|
||||
"title": "Overview",
|
||||
"order": 10,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "honk/overview"
|
||||
}
|
||||
},
|
||||
"admin/services/honk/configuration": {
|
||||
"title": "Configuration",
|
||||
"order": 20,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "honk/configuration"
|
||||
}
|
||||
},
|
||||
"admin/services/honk/logs": {
|
||||
"title": "Logs",
|
||||
"order": 30,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "honk/logs"
|
||||
}
|
||||
},
|
||||
"admin/services/honk/maintenance": {
|
||||
"title": "Maintenance",
|
||||
"order": 40,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "honk/maintenance"
|
||||
}
|
||||
},
|
||||
"admin/services/honk/dashboard": {
|
||||
"hidden": true,
|
||||
"action": {
|
||||
"type": "alias",
|
||||
"path": "admin/services/honk/overview"
|
||||
}
|
||||
},
|
||||
"admin/services/honk/settings": {
|
||||
"hidden": true,
|
||||
"action": {
|
||||
"type": "alias",
|
||||
"path": "admin/services/honk/overview"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
{
|
||||
"luci-app-honk": {
|
||||
"description": "Grant access to Honk controls and maintenance",
|
||||
"read": {
|
||||
"ubus": {
|
||||
"honk": [
|
||||
"status",
|
||||
"check",
|
||||
"job_status",
|
||||
"logs",
|
||||
"update_check",
|
||||
"lan_candidates"
|
||||
],
|
||||
"network": [
|
||||
"get_proto_handlers"
|
||||
],
|
||||
"network.interface": [
|
||||
"dump"
|
||||
]
|
||||
},
|
||||
"file": {
|
||||
"/tmp/honk-backup.tar.gz": [
|
||||
"read"
|
||||
],
|
||||
"/usr/share/v2ray/geoip.dat": [
|
||||
"read"
|
||||
],
|
||||
"/usr/share/v2ray/geosite.dat": [
|
||||
"read"
|
||||
],
|
||||
"/tmp/luci-app-honk.geoip.log": [
|
||||
"read"
|
||||
],
|
||||
"/tmp/luci-app-honk.geosite.log": [
|
||||
"read"
|
||||
],
|
||||
"/tmp/luci-app-honk.pkg-honk.log": [
|
||||
"read"
|
||||
],
|
||||
"/tmp/luci-app-honk.pkg-luci-app-honk.log": [
|
||||
"read"
|
||||
],
|
||||
"/usr/share/luci-app-honk/pkg-info.sh honk": [
|
||||
"exec"
|
||||
],
|
||||
"/usr/share/luci-app-honk/pkg-info.sh luci-app-honk": [
|
||||
"exec"
|
||||
],
|
||||
"/usr/share/luci-app-honk/refresh-index.sh": [
|
||||
"exec"
|
||||
]
|
||||
},
|
||||
"uci": [
|
||||
"network",
|
||||
"honk"
|
||||
]
|
||||
},
|
||||
"write": {
|
||||
"cgi-io": [
|
||||
"upload"
|
||||
],
|
||||
"ubus": {
|
||||
"honk": [
|
||||
"initialize",
|
||||
"start",
|
||||
"stop",
|
||||
"restart",
|
||||
"settings",
|
||||
"probe_subscription",
|
||||
"add_subscription",
|
||||
"add_nodes",
|
||||
"import_dae",
|
||||
"config_validate",
|
||||
"config_save",
|
||||
"reset_admin",
|
||||
"repair",
|
||||
"backup",
|
||||
"restore",
|
||||
"restore_prepare",
|
||||
"reset",
|
||||
"update_apply",
|
||||
"config_read",
|
||||
"config_draft_read",
|
||||
"config_apply"
|
||||
]
|
||||
},
|
||||
"file": {
|
||||
"/tmp/honk-maintenance/restore.tar.gz": [
|
||||
"write"
|
||||
],
|
||||
"/tmp/honk-v2-upload/import.dae": [
|
||||
"write"
|
||||
],
|
||||
"/usr/share/luci-app-honk/update-geo.sh geoip": [
|
||||
"exec"
|
||||
],
|
||||
"/usr/share/luci-app-honk/update-geo.sh geosite": [
|
||||
"exec"
|
||||
],
|
||||
"/usr/share/luci-app-honk/geo-cron.sh enable": [
|
||||
"exec"
|
||||
],
|
||||
"/usr/share/luci-app-honk/geo-cron.sh disable": [
|
||||
"exec"
|
||||
],
|
||||
"/usr/share/luci-app-honk/update-pkg.sh honk": [
|
||||
"exec"
|
||||
],
|
||||
"/usr/share/luci-app-honk/update-pkg.sh luci-app-honk": [
|
||||
"exec"
|
||||
]
|
||||
},
|
||||
"uci": [
|
||||
"honk"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user