first commit

main
Ben 1 year ago
commit 9d0012ce4d

@ -0,0 +1,17 @@
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for jellyfin
LUCI_PKGARCH:=all
LUCI_DEPENDS:=+lsblk +docker +luci-lib-taskd
define Package/luci-app-jellyfin/conffiles
/etc/config/jellyfin
endef
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

@ -0,0 +1,7 @@
module("luci.controller.jellyfin", package.seeall)
function index()
entry({"admin", "apps", "jellyfin"}, alias("admin", "apps", "jellyfin", "config"), _("Jellyfin"), 30).dependent = true
entry({"admin", "apps", "jellyfin", "config"}, cbi("jellyfin"))
end

@ -0,0 +1,55 @@
--[[
LuCI - Lua Configuration Interface
]]--
local taskd = require "luci.model.tasks"
local jellyfin_model = require "luci.model.jellyfin"
local m, s, o
m = taskd.docker_map("jellyfin", "jellyfin", "/usr/libexec/apps/jellyfin/jellyfin.sh",
translate("Jellyfin"),
translate("Jellyfin is the volunteer-built media solution that puts you in control of your media. Stream to any device from your own server, with no strings attached. Your media, your server, your way."))
s = m:section(SimpleSection, translate("Service Status"), translate("Jellyfin status:"))
s:append(Template("jellyfin/status"))
s = m:section(TypedSection, "jellyfin", translate("Setup"),
translate("The initial installation of Jellyfin requires at least 2GB of space, please make sure that the Docker data directory has enough space. It is recommended to migrate Docker to a hard drive before installing Jellyfin.")
.. "<br>" .. translate("The following parameters will only take effect during installation or upgrade:"))
s.addremove=false
s.anonymous=true
o = s:option(Flag, "hostnet", translate("Host network"), translate("Jellyfin running in host network, for DLNA application, port is always 8096 if enabled"))
o.default = 0
o.rmempty = false
o = s:option(Value, "port", translate("Port").."<b>*</b>")
o.default = "8096"
o.datatype = "port"
o:depends("hostnet", 0)
local blocks = jellyfin_model.blocks()
local home = jellyfin_model.home()
o = s:option(Value, "config_path", translate("Config path").."<b>*</b>")
o.rmempty = false
o.datatype = "string"
local paths, default_path = jellyfin_model.find_paths(blocks, home, "Configs")
for _, val in pairs(paths) do
o:value(val, val)
end
o.default = default_path
o = s:option(Value, "media_path", translate("Media path"), translate("Not required, all disk is mounted in") .. " <a href='/cgi-bin/luci/admin/services/linkease/file/?path=/root/mnt' target='_blank'>/mnt</a>")
o.datatype = "string"
o = s:option(Value, "cache_path", translate("Transcode cache path"), translate("Default use 'transcodes' in 'config path' if not set, please make sure there has enough space"))
o.datatype = "string"
local paths, default_path = jellyfin_model.find_paths(blocks, home, "Caches")
for _, val in pairs(paths) do
o:value(val, val)
end
o.default = default_path
return m

@ -0,0 +1,55 @@
local util = require "luci.util"
local jsonc = require "luci.jsonc"
local jellyfin = {}
jellyfin.blocks = function()
local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r")
local vals = {}
if f then
local ret = f:read("*all")
f:close()
local obj = jsonc.parse(ret)
for _, val in pairs(obj["blockdevices"]) do
local fsize = val["fssize"]
if fsize ~= nil and string.len(fsize) > 10 and val["mountpoint"] then
-- fsize > 1G
vals[#vals+1] = val["mountpoint"]
end
end
end
return vals
end
jellyfin.home = function()
local uci = require "luci.model.uci".cursor()
local home_dirs = {}
home_dirs["main_dir"] = uci:get_first("quickstart", "main", "main_dir", "/root")
home_dirs["Configs"] = uci:get_first("quickstart", "main", "conf_dir", home_dirs["main_dir"].."/Configs")
home_dirs["Public"] = uci:get_first("quickstart", "main", "pub_dir", home_dirs["main_dir"].."/Public")
home_dirs["Downloads"] = uci:get_first("quickstart", "main", "dl_dir", home_dirs["Public"].."/Downloads")
home_dirs["Caches"] = uci:get_first("quickstart", "main", "tmp_dir", home_dirs["main_dir"].."/Caches")
return home_dirs
end
jellyfin.find_paths = function(blocks, home_dirs, path_name)
local default_path = ''
local configs = {}
default_path = home_dirs[path_name] .. "/Jellyfin"
if #blocks == 0 then
table.insert(configs, default_path)
else
for _, val in pairs(blocks) do
table.insert(configs, val .. "/" .. path_name .. "/Jellyfin")
end
local without_conf_dir = "/root/" .. path_name .. "/Jellyfin"
if default_path == without_conf_dir then
default_path = configs[1]
end
end
return configs, default_path
end
return jellyfin

@ -0,0 +1,31 @@
<%
local util = require "luci.util"
local container_status = util.trim(util.exec("/usr/libexec/apps/jellyfin.sh status"))
local container_install = (string.len(container_status) > 0)
local container_running = container_status == "running"
-%>
<div class="cbi-value">
<label class="cbi-value-title"><%:Status%></label>
<div class="cbi-value-field">
<% if container_running then %>
<button class="cbi-button cbi-button-success" disabled="true"><%:Jellyfin is running%></button>
<% else %>
<button class="cbi-button cbi-button-negative" disabled="true"><%:Jellyfin is not running%></button>
<% end %>
</div>
</div>
<%
if container_running then
local port=util.trim(util.exec("/usr/libexec/apps/jellyfin.sh port"))
if port == "" then
port="8096"
end
-%>
<div class="cbi-value cbi-value-last">
<label class="cbi-value-title">&nbsp;</label>
<div class="cbi-value-field">
<input type="button" class="btn cbi-button cbi-button-apply" name="start" value="<%:Open Jellyfin%>" onclick="window.open('http://'+location.hostname+':<%=port%>/', '_blank')">
</div>
</div>
<% end %>

@ -0,0 +1,7 @@
config jellyfin
option 'hostnet' '0'
option 'port' '8096'
option 'image' 'default'
option 'media_path' '/opt/docker2/compose/media'
option 'config_path' '/opt/docker2/compose/jellyfin/config'
option 'cache_path' ''

@ -0,0 +1,11 @@
#!/bin/sh
image_name=`uci get jellyfin.@jellyfin[0].image 2>/dev/null`
if [ "$image_name" == "jjm2473/jellyfin-rtk:latest" ]; then
uci -q batch <<-EOF >/dev/null
set jellyfin.@jellyfin[0].image="default"
commit jellyfin
EOF
fi
exit 0

@ -0,0 +1,98 @@
#!/bin/sh
ACTION=${1}
shift 1
ARCH="default"
IMAGE_NAME='default'
get_image() {
IMAGE_NAME="jellyfin/jellyfin"
}
do_install() {
get_image
echo "docker pull ${IMAGE_NAME}"
docker pull ${IMAGE_NAME}
docker rm -f jellyfin
do_install_detail
}
do_install_detail() {
local hostnet=`uci get jellyfin.@jellyfin[0].hostnet 2>/dev/null`
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`
local dev
if [ -z "$config" ]; then
echo "config path is empty!"
exit 1
fi
[ -z "$port" ] && port=8096
local cmd="docker run --restart=unless-stopped -d -v \"$config:/config\" "
if [ "$hostnet" = 1 ]; then
cmd="$cmd\
--dns=127.0.0.1 \
--network=host "
else
cmd="$cmd\
--dns=172.17.0.1 \
-p $port:8096 "
fi
local tz="`uci get system.@system[0].zonename`"
[ -z "$tz" ] || cmd="$cmd -e TZ=$tz"
[ -z "$cache" ] || cmd="$cmd -v \"$cache:/config/transcodes\""
[ -z "$media" ] || cmd="$cmd -v \"$media:/media\""
cmd="$cmd -v /mnt:/mnt"
mountpoint -q /mnt && cmd="$cmd:rslave"
cmd="$cmd --name jellyfin \"$IMAGE_NAME\""
echo "$cmd"
eval "$cmd"
}
usage() {
echo "usage: $0 sub-command"
echo "where sub-command is one of:"
echo " install Install the jellyfin"
echo " upgrade Upgrade the jellyfin"
echo " rm/start/stop/restart Remove/Start/Stop/Restart the jellyfin"
echo " status Jellyfin status"
echo " port Jellyfin port"
}
case ${ACTION} in
"install")
do_install
;;
"upgrade")
do_install
;;
"rm")
docker rm -f jellyfin
;;
"start" | "stop" | "restart")
docker ${ACTION} jellyfin
;;
"status")
docker ps --all -f 'name=jellyfin' --format '{{.State}}'
;;
"port")
docker ps --all -f 'name=jellyfin' --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://'
;;
*)
usage
exit 1
;;
esac

@ -0,0 +1,11 @@
{
"luci-app-jellyfin": {
"description": "Grant UCI access for luci-app-jellyfin",
"read": {
"uci": [ "jellyfin" ]
},
"write": {
"uci": [ "jellyfin" ]
}
}
}
Loading…
Cancel
Save