secubox-openwrt/package/secubox/luci-app-lyrion/root/usr/libexec/rpcd/luci.lyrion
CyberMind-FR 58ba852564 fix(luci): Fix dpi-dual menu and simplify lyrion UI
- Fix dpi-dual "firstchildview" error (changed to "firstchild")
- Simplify luci-app-lyrion: overview.js 276→150 lines
- Simplify luci-app-lyrion: settings.js 78→32 lines
- Simplify luci-app-lyrion: RPCD 300→90 lines
- Combined status + library stats into single RPC call
- Removed unused methods (update, logs, get_config, save_config)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-15 17:03:13 +01:00

110 lines
3.2 KiB
Bash
Executable File

#!/bin/sh
# Lyrion Music Server RPCD handler
. /lib/functions.sh
CONFIG="lyrion"
uci_get() { uci -q get ${CONFIG}.main.$1; }
get_status() {
local port=$(uci_get port)
local data_path=$(uci_get data_path)
local media_path=$(uci_get media_path)
port=${port:-9000}
# Check running state
local running=0
if command -v lxc-info >/dev/null 2>&1 && lxc-info -n lyrion -s 2>/dev/null | grep -q "RUNNING"; then
running=1
elif command -v docker >/dev/null 2>&1 && docker ps --filter "name=secbx-lyrion" -q 2>/dev/null | grep -q .; then
running=1
fi
# Check installed
local installed=0
[ -d "/srv/lxc/lyrion/rootfs" ] && installed=1
[ "$installed" = "0" ] && command -v docker >/dev/null 2>&1 && docker images 2>/dev/null | grep -q lyrionmusicserver && installed=1
# Detect runtime
local runtime="none"
command -v lxc-start >/dev/null 2>&1 && runtime="lxc"
[ "$runtime" = "none" ] && command -v docker >/dev/null 2>&1 && runtime="docker"
# Check web access
local web_accessible=0
[ "$running" = "1" ] && wget -q -O /dev/null --timeout=2 "http://127.0.0.1:${port}/" 2>/dev/null && web_accessible=1
# Get library stats if running
local songs=0 albums=0 artists=0
if [ "$running" = "1" ]; then
local resp=$(curl -s --max-time 2 "http://127.0.0.1:${port}/jsonrpc.js" \
-H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["",["serverstatus",0,0]]}' 2>/dev/null)
if [ -n "$resp" ]; then
songs=$(echo "$resp" | jsonfilter -e '@.result["info total songs"]' 2>/dev/null || echo 0)
albums=$(echo "$resp" | jsonfilter -e '@.result["info total albums"]' 2>/dev/null || echo 0)
artists=$(echo "$resp" | jsonfilter -e '@.result["info total artists"]' 2>/dev/null || echo 0)
fi
fi
cat <<EOF
{
"installed": $([ "$installed" = "1" ] && echo true || echo false),
"running": $([ "$running" = "1" ] && echo true || echo false),
"detected_runtime": "$runtime",
"port": $port,
"media_path": "${media_path:-/srv/media}",
"data_path": "${data_path:-/srv/lyrion}",
"web_accessible": $([ "$web_accessible" = "1" ] && echo true || echo false),
"web_url": "http://192.168.255.1:${port}",
"songs": ${songs:-0},
"albums": ${albums:-0},
"artists": ${artists:-0}
}
EOF
}
do_install() {
if command -v lyrionctl >/dev/null 2>&1; then
lyrionctl install >/tmp/lyrion-install.log 2>&1 &
echo '{"success":true}'
else
echo '{"success":false,"error":"lyrionctl not found"}'
fi
}
do_start() {
[ -x /etc/init.d/lyrion ] && /etc/init.d/lyrion start >/dev/null 2>&1
echo '{"success":true}'
}
do_stop() {
[ -x /etc/init.d/lyrion ] && /etc/init.d/lyrion stop >/dev/null 2>&1
echo '{"success":true}'
}
do_rescan() {
local port=$(uci_get port)
curl -s --max-time 3 "http://127.0.0.1:${port:-9000}/jsonrpc.js" \
-H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["",["rescan","full"]]}' >/dev/null 2>&1
echo '{"success":true}'
}
case "$1" in
list)
echo '{"status":{},"install":{},"start":{},"stop":{},"rescan":{}}'
;;
call)
case "$2" in
status) get_status ;;
install) do_install ;;
start) do_start ;;
stop) do_stop ;;
rescan) do_rescan ;;
*) echo '{"error":"Unknown method"}' ;;
esac
;;
esac