update jellyfin (#3)
This commit is contained in:
parent
c00d8b92d4
commit
32c7c28ea0
@ -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
|
||||
|
||||
|
||||
|
@ -6,11 +6,11 @@ function index()
|
||||
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()
|
||||
@ -58,14 +65,24 @@ 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
|
||||
docker:write_status("jellyfin installing\n")
|
||||
pull_image(image)
|
||||
install_jellyfin()
|
||||
else
|
||||
install_jellyfin()
|
||||
end
|
||||
docker:write_status("jellyfin image not defined!\n")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(5,'<%=url("admin/services/jellyfin/status")%>', null,
|
||||
function (x, st) {
|
||||
var tb = document.getElementById('linkease_status');
|
||||
var tb = document.getElementById('jellyfin_status');
|
||||
if (st && tb) {
|
||||
if (st.docker_install){
|
||||
if (st.docker_start){
|
||||
@ -21,27 +21,43 @@
|
||||
else {
|
||||
let config = document.getElementById('config')
|
||||
if(!config){
|
||||
tb.innerHTML = '<br/><em><%:The Jellyfin service is not installed.%></em>'
|
||||
+ "<br/><br/><br/>config path:"
|
||||
+ "<br/><input type=\"text\" class=\"cbi-input-text\" name=\"isrc\" id=\"config\" value=\"/root/jellyfin/config\" />"
|
||||
+ "<br/><br/>media path:"
|
||||
+ "<br/><input type=\"text\" class=\"cbi-input-text\" name=\"isrc\" id=\"media\" value=\"/mnt/sda1/media\"/>"
|
||||
+ "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:install Jellyfin%> \" onclick=\"install_container()\" /><br/><br/>";
|
||||
var configs = [
|
||||
{id: "media", label: "<%:Media path%><sup>*</sup>:", value: st.media_path},
|
||||
{id: "config", label: "<%:Config path%><sup>*</sup>:", value: st.config_path},
|
||||
{id: "cache", label: "<%:Transcode cache path (optional)%>:", value: st.cache_path},
|
||||
{id: "port", label: "<%:Port (optional)%>:", value: st.container_port},
|
||||
];
|
||||
tb.innerHTML = '<br/><em><%:The Jellyfin service is not installed.%></em>';
|
||||
configs.forEach(function(c){
|
||||
tb.innerHTML += ("<div class=\"cbi-value\"><label class=\"cbi-value-title\" for=\"" + c.id + "\">" + c.label + "</label>"
|
||||
+ "<div class=\"cbi-value-field\"><input type=\"text\" class=\"cbi-input-text\" id=\"" + c.id + "\" value=\"" + c.value + "\"/></div></div>");
|
||||
});
|
||||
tb.innerHTML += ("<div class=\"cbi-value\"><label class=\"cbi-value-title\"></label>"
|
||||
+ "<div class=\"cbi-value-field\"><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:install Jellyfin%> \" onclick=\"install_container()\" /></div></div><br>");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else{
|
||||
tb.innerHTML = '<em><%:Docker service is not start.%></em>'
|
||||
tb.innerHTML = '<br/><em><%:Docker service is not start.%></em>'
|
||||
}
|
||||
}
|
||||
else{
|
||||
tb.innerHTML = '<em><%:Docker is not installed.%></em>'
|
||||
tb.innerHTML = '<br/><em><%:Docker is not installed.%></em>'
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
var xhr_post = function(url, data, cb) {
|
||||
data = data || {};
|
||||
data.token = '<%=token%>';
|
||||
cb || docker_status_message('notice', '<img src="/luci-static/resources/icons/loading.gif" alt="" style="vertical-align:middle" />');
|
||||
new XHR().post(url, data, (x, d) => {
|
||||
cb || docker_status_message();
|
||||
cb && cb(x, d);
|
||||
});
|
||||
};
|
||||
|
||||
function open_container(x) {
|
||||
Url = "http://" + window.location.hostname + ":" + x
|
||||
// alert(Url)
|
||||
@ -53,9 +69,7 @@
|
||||
|
||||
function stop_container(x) {
|
||||
|
||||
XHR.get(STOP_URL, { container_id: x }, (x, d) => {
|
||||
alert(" 关闭容器'" + d.container_id + "' ");
|
||||
});
|
||||
xhr_post(STOP_URL, { container_id: x });
|
||||
return false
|
||||
}
|
||||
|
||||
@ -63,9 +77,7 @@
|
||||
|
||||
function start_container(x) {
|
||||
|
||||
XHR.get(START_URL, { container_id: x }, (x, d) => {
|
||||
// alert(" 打开容器'" + d.container_id + "' ");
|
||||
});
|
||||
xhr_post(START_URL, { container_id: x });
|
||||
return false
|
||||
}
|
||||
|
||||
@ -73,9 +85,7 @@
|
||||
|
||||
function uninstall_container(x) {
|
||||
|
||||
XHR.get(UNINSTALL_URL, { container_id: x }, (x, d) => {
|
||||
// alert(" 删除容器'" + d.container_id + "' ");
|
||||
});
|
||||
xhr_post(UNINSTALL_URL, { container_id: x });
|
||||
return false
|
||||
}
|
||||
|
||||
@ -84,25 +94,31 @@
|
||||
function install_container(x) {
|
||||
let config = document.getElementById('config')
|
||||
let media = document.getElementById('media')
|
||||
let cache = document.getElementById('cache')
|
||||
let port = document.getElementById('port').value
|
||||
let media_path = media.value
|
||||
let config_path = config.value
|
||||
let cache_path = cache.value
|
||||
|
||||
uci_confirm_docker()
|
||||
XHR.get(INSTALL_URL, { media: media_path,config:config_path }, (x, d) => {
|
||||
if (media_path == "" || config_path == "") {
|
||||
alert("<%:Media path and Config path could not be empty!%>");
|
||||
return false;
|
||||
}
|
||||
|
||||
xhr_post(INSTALL_URL, { media: media_path, config: config_path, cache: cache_path, port: port }, (x, d) => {
|
||||
// alert(" 删除容器'" + d.image_name + "' ");
|
||||
location.reload()
|
||||
});
|
||||
uci_confirm_docker();
|
||||
|
||||
return false
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
<fieldset class="cbi-section">
|
||||
<!-- <legend>
|
||||
<%:Jellyfin Status%>
|
||||
</legend> -->
|
||||
<p id="linkease_status">
|
||||
<fieldset class="cbi-section-node" id="jellyfin_status">
|
||||
<em>
|
||||
<%:Collecting data...%>
|
||||
</em>
|
||||
</p>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
|
@ -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 "媒体文件路径和配置数据路径不能为空!"
|
||||
|
@ -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' ''
|
||||
|
@ -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
|
||||
;;
|
||||
|
Loading…
x
Reference in New Issue
Block a user