secubox-openwrt/package/secubox/luci-app-jellyfin/root/usr/libexec/rpcd/luci.jellyfin
CyberMind-FR 155f9d8005 feat(jellyfin): Add uninstall, update, backup, HAProxy integration and LuCI actions
- Add jellyfinctl commands: uninstall, update, backup, configure-haproxy
- Add RPCD methods: uninstall, update, backup, configure_haproxy
- Add domain and disk_usage to status display
- Add action buttons in LuCI overview: Update, Backup, Configure HAProxy, Uninstall
- Add UCI options: domain, backup_path, haproxy_enabled

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 17:10:44 +01:00

187 lines
5.1 KiB
Bash

#!/bin/sh
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
CONTAINER="secbx-jellyfin"
CONFIG="jellyfin"
case "$1" in
list)
echo '{"status":{},"start":{},"stop":{},"restart":{},"install":{},"uninstall":{},"update":{},"configure_haproxy":{},"backup":{},"restore":{"path":"str"},"logs":{"lines":"int"}}'
;;
call)
case "$2" in
status)
json_init
enabled=$(uci -q get ${CONFIG}.main.enabled)
image=$(uci -q get ${CONFIG}.main.image)
port=$(uci -q get ${CONFIG}.main.port)
data_path=$(uci -q get ${CONFIG}.main.data_path)
timezone=$(uci -q get ${CONFIG}.main.timezone)
hw_accel=$(uci -q get ${CONFIG}.transcoding.hw_accel)
# Network/domain config
domain=$(uci -q get ${CONFIG}.network.domain)
haproxy=$(uci -q get ${CONFIG}.network.haproxy)
firewall_wan=$(uci -q get ${CONFIG}.network.firewall_wan)
# Mesh config
mesh_enabled=$(uci -q get ${CONFIG}.mesh.enabled)
json_add_boolean "enabled" ${enabled:-0}
json_add_string "image" "${image:-jellyfin/jellyfin:latest}"
json_add_int "port" ${port:-8096}
json_add_string "data_path" "${data_path:-/srv/jellyfin}"
json_add_string "timezone" "${timezone:-Europe/Paris}"
json_add_boolean "hw_accel" ${hw_accel:-0}
json_add_string "domain" "${domain:-jellyfin.secubox.local}"
json_add_boolean "haproxy" ${haproxy:-0}
json_add_boolean "firewall_wan" ${firewall_wan:-0}
json_add_boolean "mesh_enabled" ${mesh_enabled:-0}
# Docker availability
if command -v docker >/dev/null 2>&1; then
json_add_boolean "docker_available" 1
else
json_add_boolean "docker_available" 0
fi
# Container status
if docker ps --filter "name=$CONTAINER" --format '{{.Status}}' 2>/dev/null | grep -q .; then
json_add_string "container_status" "running"
uptime=$(docker ps --filter "name=$CONTAINER" --format '{{.Status}}' 2>/dev/null)
json_add_string "container_uptime" "$uptime"
elif docker ps -a --filter "name=$CONTAINER" --format '{{.Status}}' 2>/dev/null | grep -q .; then
json_add_string "container_status" "stopped"
json_add_string "container_uptime" ""
else
json_add_string "container_status" "not_installed"
json_add_string "container_uptime" ""
fi
# HAProxy vhost status
if [ "${haproxy:-0}" = "1" ]; then
vhost_exists=$(uci show haproxy 2>/dev/null | grep "\.domain='${domain:-jellyfin.secubox.local}'" | head -1)
if [ -n "$vhost_exists" ]; then
json_add_string "haproxy_status" "configured"
else
json_add_string "haproxy_status" "pending"
fi
else
json_add_string "haproxy_status" "disabled"
fi
# Disk usage
dp="${data_path:-/srv/jellyfin}"
if [ -d "$dp" ]; then
disk_usage=$(du -sh "$dp" 2>/dev/null | cut -f1)
json_add_string "disk_usage" "${disk_usage:-0}"
else
json_add_string "disk_usage" ""
fi
# Media paths
json_add_array "media_paths"
for mp in $(uci -q get ${CONFIG}.media.media_path); do
json_add_string "" "$mp"
done
json_close_array
json_dump
;;
start)
/etc/init.d/jellyfin start >/dev/null 2>&1
echo '{"success":true}'
;;
stop)
/etc/init.d/jellyfin stop >/dev/null 2>&1
echo '{"success":true}'
;;
restart)
/etc/init.d/jellyfin restart >/dev/null 2>&1
echo '{"success":true}'
;;
install)
output=$(/usr/sbin/jellyfinctl install 2>&1)
code=$?
json_init
json_add_boolean "success" $((code == 0))
json_add_string "output" "$output"
json_dump
;;
uninstall)
output=$(/usr/sbin/jellyfinctl uninstall 2>&1)
code=$?
json_init
json_add_boolean "success" $((code == 0))
json_add_string "output" "$output"
json_dump
;;
update)
output=$(/usr/sbin/jellyfinctl update 2>&1)
code=$?
json_init
json_add_boolean "success" $((code == 0))
json_add_string "output" "$output"
json_dump
;;
configure_haproxy)
output=$(/usr/sbin/jellyfinctl configure-haproxy 2>&1)
code=$?
json_init
json_add_boolean "success" $((code == 0))
json_add_string "output" "$output"
json_dump
;;
backup)
backup_file="/tmp/jellyfin-backup-$(date +%Y%m%d-%H%M%S).tar.gz"
output=$(/usr/sbin/jellyfinctl backup "$backup_file" 2>&1)
code=$?
json_init
json_add_boolean "success" $((code == 0))
json_add_string "path" "$backup_file"
json_add_string "output" "$output"
json_dump
;;
restore)
read -r input
path=$(echo "$input" | jsonfilter -e '@.path' 2>/dev/null)
if [ -z "$path" ]; then
echo '{"success":false,"output":"No backup path specified"}'
else
output=$(/usr/sbin/jellyfinctl restore "$path" 2>&1)
code=$?
json_init
json_add_boolean "success" $((code == 0))
json_add_string "output" "$output"
json_dump
fi
;;
logs)
read -r input
lines=$(echo "$input" | jsonfilter -e '@.lines' 2>/dev/null)
[ -z "$lines" ] && lines=50
logs=$(docker logs --tail "$lines" "$CONTAINER" 2>&1 | tail -100)
json_init
json_add_string "logs" "$logs"
json_dump
;;
esac
;;
esac
exit 0