diff --git a/applications/luci-app-jellyfin/Makefile b/applications/luci-app-jellyfin/Makefile index 79c621e..e569306 100644 --- a/applications/luci-app-jellyfin/Makefile +++ b/applications/luci-app-jellyfin/Makefile @@ -2,16 +2,18 @@ include $(TOPDIR)/rules.mk -PKG_NAME:=luci-app-jellyfin -PKG_VERSION:=1.0.1 -PKG_RELEASE:=20211014 +PKG_VERSION:=1.0.2 +PKG_RELEASE:=20211015 LUCI_TITLE:=LuCI support for jellyfin LUCI_PKGARCH:=all LUCI_DEPENDS:=+docker +luci-app-dockerman +define Package/luci-app-jellyfin/conffiles +/etc/config/jellyfin +endef + include $(TOPDIR)/feeds/luci/luci.mk # call BuildPackage - OpenWrt buildroot signature - diff --git a/applications/luci-app-jellyfin/luasrc/controller/jellyfin.lua b/applications/luci-app-jellyfin/luasrc/controller/jellyfin.lua index 4c8c56e..2257eb0 100755 --- a/applications/luci-app-jellyfin/luasrc/controller/jellyfin.lua +++ b/applications/luci-app-jellyfin/luasrc/controller/jellyfin.lua @@ -1,16 +1,16 @@ module("luci.controller.jellyfin", package.seeall) function index() - + entry({'admin', 'services', 'jellyfin'}, alias('admin', 'services', 'jellyfin', 'client'), _('Jellyfin'), 10).dependent = true -- 首页 entry({"admin", "services", "jellyfin",'client'}, cbi("jellyfin/status", {hideresetbtn=true, hidesavebtn=true}), _("Jellyfin"), 20).leaf = true -- entry({'admin', 'services', 'jellyfin', 'script'}, form('jellyfin/script'), _('Script'), 20).leaf = true -- 直接配置脚本 - entry({"admin", "services", "jellyfin","status"}, call("container_status")) - entry({"admin", "services", "jellyfin","stop"}, call("stop_container")) - entry({"admin", "services", "jellyfin","start"}, call("start_container")) - entry({"admin", "services", "jellyfin","install"}, call("install_container")) - entry({"admin", "services", "jellyfin","uninstall"}, call("uninstall_container")) + entry({"admin", "services", "jellyfin","status"}, call("get_container_status")) + entry({"admin", "services", "jellyfin","stop"}, post("stop_container")) + entry({"admin", "services", "jellyfin","start"}, post("start_container")) + entry({"admin", "services", "jellyfin","install"}, post("install_container")) + entry({"admin", "services", "jellyfin","uninstall"}, post("uninstall_container")) end @@ -25,10 +25,10 @@ function container_status() local docker_server_version = util.exec("docker info | grep 'Server Version'") local docker_install = (string.len(docker_path) > 0) local docker_start = (string.len(docker_server_version) > 0) - local port = tonumber(uci:get_first(keyword, keyword, "port")) - local container_id = util.trim(util.exec("docker ps -aqf'name='"..keyword.."''")) + local port = tonumber(uci:get_first(keyword, keyword, "port", "8096")) + local container_id = util.trim(util.exec("docker ps -aqf 'name="..keyword.."'")) local container_install = (string.len(container_id) > 0) - local container_running = (sys.call("pidof '"..keyword.."' >/dev/null") == 0) + local container_running = container_install and (string.len(util.trim(util.exec("docker ps -qf 'id="..container_id.."'"))) > 0) local status = { docker_install = docker_install, @@ -37,11 +37,18 @@ function container_status() container_install = container_install, container_running = container_running, container_port = (port or 8096), + media_path = uci:get_first(keyword, keyword, "media_path", "/mnt/sda1/media"), + config_path = uci:get_first(keyword, keyword, "config_path", "/root/jellyfin/config"), + cache_path = uci:get_first(keyword, keyword, "cache_path", ""), } + return status +end + +function get_container_status() + local status = container_status() luci.http.prepare_content("application/json") luci.http.write_json(status) - return status end function stop_container() @@ -57,15 +64,25 @@ function start_container() end function install_container() - - docker:write_status("jellyfin installing\n") - local dk = docker.new() - local images = dk.images:list().body + local image = util.exec("sh /usr/share/jellyfin/install.sh -l") local media_path = luci.http.formvalue("media") local config_path = luci.http.formvalue("config") + local cache_path = luci.http.formvalue("cache") + local port = luci.http.formvalue("port") + + uci:tset(keyword, "@"..keyword.."[0]", { + media_path = media_path or "/mnt/sda1/media", + config_path = config_path or "/root/jellyfin/config", + cache_path = cache_path or "", + port = port or "8096", + }) + uci:save(keyword) + uci:commit(keyword) + local pull_image = function(image) docker:append_status("Images: " .. "pulling" .. " " .. image .. "...\n") + local dk = docker.new() local res = dk.images:create({query = {fromImage=image}}, docker.pull_image_show_status_cb) if res and res.code and res.code == 200 and (res.body[#res.body] and not res.body[#res.body].error and res.body[#res.body].status and (res.body[#res.body].status == "Status: Downloaded newer image for ".. image or res.body[#res.body].status == "Status: Image is up to date for ".. image)) then docker:append_status("done\n") @@ -78,8 +95,8 @@ function install_container() local install_jellyfin = function() local os = require "os" local fs = require "nixio.fs" - local c = ("sh /usr/share/jellyfin/install.sh -m " ..media_path.. " -c " ..config_path.. " -i >/tmp/log/jellyfin.stdout 2>/tmp/log/jellyfin.stderr") - -- docker:write_status(c) + local c = ("sh /usr/share/jellyfin/install.sh -i >/tmp/log/jellyfin.stdout 2>/tmp/log/jellyfin.stderr") + -- docker:append_status(c) local r = os.execute(c) local e = fs.readfile("/tmp/log/jellyfin.stderr") @@ -89,9 +106,9 @@ function install_container() fs.unlink("/tmp/log/jellyfin.stdout") if r == 0 then - docker:write_status(o) + docker:append_status(o) else - docker:write_status( e ) + docker:append_status( e ) end end @@ -102,20 +119,12 @@ function install_container() -- luci.http.prepare_content("application/json") -- luci.http.write_json(status) - local exist_image = false if image then - for _, v in ipairs (images) do - if v.RepoTags and v.RepoTags[1] == image then - exist_image = true - break - end - end - if not exist_image then - pull_image(image) - install_jellyfin() - else - install_jellyfin() - end + docker:write_status("jellyfin installing\n") + pull_image(image) + install_jellyfin() + else + docker:write_status("jellyfin image not defined!\n") end end diff --git a/applications/luci-app-jellyfin/luasrc/view/jellyfin/jellyfin.htm b/applications/luci-app-jellyfin/luasrc/view/jellyfin/jellyfin.htm index 84b23f8..2008ef2 100755 --- a/applications/luci-app-jellyfin/luasrc/view/jellyfin/jellyfin.htm +++ b/applications/luci-app-jellyfin/luasrc/view/jellyfin/jellyfin.htm @@ -1,7 +1,7 @@
diff --git a/applications/luci-app-jellyfin/po/zh-cn/jellyfin.po b/applications/luci-app-jellyfin/po/zh-cn/jellyfin.po index 66a030b..0f52a87 100644 --- a/applications/luci-app-jellyfin/po/zh-cn/jellyfin.po +++ b/applications/luci-app-jellyfin/po/zh-cn/jellyfin.po @@ -25,3 +25,17 @@ msgstr "安装Jellyfin" msgid "Collecting data..." msgstr "收集数据..." +msgid "Media path" +msgstr "媒体文件路径" + +msgid "Config path" +msgstr "配置数据路径" + +msgid "Transcode cache path (optional)" +msgstr "转码缓存路径(选填)" + +msgid "Port (optional)" +msgstr "端口(选填)" + +msgid "Media path and Config path could not be empty!" +msgstr "媒体文件路径和配置数据路径不能为空!" diff --git a/applications/luci-app-jellyfin/root/etc/config/jellyfin b/applications/luci-app-jellyfin/root/etc/config/jellyfin index 6711a2c..1b2fea0 100644 --- a/applications/luci-app-jellyfin/root/etc/config/jellyfin +++ b/applications/luci-app-jellyfin/root/etc/config/jellyfin @@ -1,3 +1,6 @@ config jellyfin option 'port' '8096' - option 'enabled' '1' + option 'image' 'jjm2473/jellyfin-rtk:latest' + option 'media_path' '/mnt/sda1/media' + option 'config_path' '/root/jellyfin/config' + option 'cache_path' '' diff --git a/applications/luci-app-jellyfin/root/usr/share/jellyfin/install.sh b/applications/luci-app-jellyfin/root/usr/share/jellyfin/install.sh index ac108c4..4fd8ee2 100755 --- a/applications/luci-app-jellyfin/root/usr/share/jellyfin/install.sh +++ b/applications/luci-app-jellyfin/root/usr/share/jellyfin/install.sh @@ -1,9 +1,25 @@ #!/bin/sh -image_name="jjm2473/jellyfin-rtk:latest" -config="/root/jellyfin/config" -media="/mnt/sda1/media" + +image_name=`uci get jellyfin.@jellyfin[0].image 2>/dev/null` + +[ -z "$image_name" ] && image_name="jjm2473/jellyfin-rtk:latest" install(){ + local media=`uci get jellyfin.@jellyfin[0].media_path 2>/dev/null` + local config=`uci get jellyfin.@jellyfin[0].config_path 2>/dev/null` + local cache=`uci get jellyfin.@jellyfin[0].cache_path 2>/dev/null` + local port=`uci get jellyfin.@jellyfin[0].port 2>/dev/null` + + if [ -z "$media" -o -z "$config"]; then + echo "media path or config path is empty!" >&2 + exit 1 + fi + + local cachev + [ -z "$cache" ] || cachev="-v $cache:/config/transcodes" + + [ -z "$port" ] && port=8096 + docker run --restart=unless-stopped -d \ --device /dev/rpc0:/dev/rpc0 \ --device /dev/rpc1:/dev/rpc1 \ @@ -27,22 +43,16 @@ install(){ -v /var/tmp/vowb:/var/tmp/vowb \ --pid=host \ --dns=172.17.0.1 \ - -p 8096:8096 -v $config:/config -v $media:/media --name myjellyfin-rtk $image_name + -p $port:8096 -v "$config:/config" $cachev -v "$media:/media" --name myjellyfin-rtk "$image_name" } -while getopts ":ilc:m:" optname +while getopts ":il" optname do case "$optname" in "l") echo -n $image_name ;; - "c") - config=$OPTARG - ;; - "m") - media=$OPTARG - ;; "i") install ;;