mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-30 12:05:13 +08:00
🎁 Sync 2026-03-15 08:51:25
This commit is contained in:
1 parent
2d75925beb
commit
a485533d81
10 files changed
+597
-354
No files matched your search
+64
@@ -0,0 +1,64 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# netspeedtest init script
|
||||
|
||||
START=95
|
||||
STOP=15
|
||||
USE_PROCD=1
|
||||
|
||||
PATH=/usr/bin:/bin:/usr/sbin:/sbin
|
||||
|
||||
start_service() {
|
||||
|
||||
START_IPERF3=$(uci get netspeedtest.config.iperf3_enabled 2>/dev/null || echo "0")
|
||||
START_HOMEBOX=$(uci get netspeedtest.config.homebox_enabled 2>/dev/null || echo "0")
|
||||
|
||||
[ "$START_HOMEBOX" = "1" ] || return 0
|
||||
port=$(uci get netspeedtest.config.homebox_port 2>/dev/null || echo "3300")
|
||||
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command /usr/bin/homebox serve --port "$port"
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
logger -t netspeedtest "Stopping homebox"
|
||||
|
||||
ubus call service delete '{ "name": "netspeedtest" }' 2>/dev/null
|
||||
|
||||
killall homebox 2>/dev/null || true
|
||||
|
||||
local retries=5
|
||||
while pidof homebox >/dev/null 2>&1 && [ $retries -gt 0 ]; do
|
||||
sleep 0.2
|
||||
retries=$((retries-1))
|
||||
done
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "netspeedtest"
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
status() {
|
||||
|
||||
START_HOMEBOX=$(uci get netspeedtest.config.homebox_enabled 2>/dev/null || echo "0")
|
||||
|
||||
if [ "$START_HOMEBOX" != "1" ]; then
|
||||
return 3
|
||||
fi
|
||||
|
||||
_procd_status
|
||||
}
|
||||
|
||||
boot() {
|
||||
sleep 2
|
||||
start
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2019-2026 sirpdboy
|
||||
# RPC plugin for netspeedtest
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
get_ookla_servers() {
|
||||
local servers="[]"
|
||||
|
||||
if [ -f '/usr/bin/ookla-speedtest' ] && [ -x '/usr/bin/ookla-speedtest' ]; then
|
||||
local json_output=$(/usr/bin/ookla-speedtest --servers --format=json 2>/dev/null)
|
||||
|
||||
if [ -n "$json_output" ]; then
|
||||
servers=$(echo "$json_output" | sed -n 's/.*"servers":\(\[.*\]\).*/\1/p')
|
||||
[ -z "$servers" ] && servers="[]"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$servers"
|
||||
}
|
||||
|
||||
get_python_servers() {
|
||||
local servers="[]"
|
||||
local temp_file="/tmp/python_servers.tmp"
|
||||
|
||||
if [ -f '/usr/bin/speedtest' ] && [ -x '/usr/bin/speedtest' ]; then
|
||||
/usr/bin/speedtest --list > "$temp_file" 2>/dev/null
|
||||
|
||||
if [ -s "$temp_file" ]; then
|
||||
local json=""
|
||||
local count=0
|
||||
|
||||
while IFS= read -r line; do
|
||||
if echo "$line" | grep -qE '^[0-9]+\)'; then
|
||||
local id=$(echo "$line" | sed -E 's/^([0-9]+)\).*/\1/')
|
||||
local sponsor=$(echo "$line" | sed -E 's/^[0-9]+\)[[:space:]]+([^(]+).*/\1/' | sed -e 's/[[:space:]]*$//' -e 's/"/\\"/g')
|
||||
local city_country=$(echo "$line" | grep -o '([^)]*)' | head -1 | sed 's/[()]//g')
|
||||
local city=$(echo "$city_country" | cut -d',' -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/"/\\"/g')
|
||||
local country=$(echo "$city_country" | cut -d',' -f2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/"/\\"/g')
|
||||
local distance=$(echo "$line" | grep -o '\[[0-9.]* km\]' | sed 's/\[//g' | sed 's/ km\]//g')
|
||||
|
||||
[ -z "$distance" ] && distance="0"
|
||||
|
||||
if [ $count -gt 0 ]; then
|
||||
json="$json,"
|
||||
fi
|
||||
|
||||
json="$json{\"id\":$id,\"sponsor\":\"$sponsor\",\"city\":\"$city\",\"country\":\"$country\",\"distance\":$distance}"
|
||||
count=$((count + 1))
|
||||
|
||||
[ $count -ge 10 ] && break
|
||||
fi
|
||||
done < "$temp_file"
|
||||
|
||||
[ -n "$json" ] && servers="[$json]"
|
||||
fi
|
||||
rm -f "$temp_file"
|
||||
fi
|
||||
|
||||
echo "$servers"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
list)
|
||||
echo '{
|
||||
"get_servers": {
|
||||
"signature": [],
|
||||
"help": "Get speedtest servers"
|
||||
}
|
||||
}'
|
||||
;;
|
||||
call)
|
||||
case "$2" in
|
||||
get_servers)
|
||||
json_init
|
||||
json_add_string "ookla" "$(get_ookla_servers)"
|
||||
json_add_string "python" "$(get_python_servers)"
|
||||
json_dump
|
||||
;;
|
||||
*)
|
||||
echo '{"error": "Method not found"}'
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo '{"error": "Invalid command"}'
|
||||
;;
|
||||
esac
|
||||
Reference in new issue
Block a user