Update 'root/usr/libexec/apps/jellyfin.sh'

main
ben 1 year ago
parent d589e02a1f
commit b629750dbe

@ -1,98 +1,108 @@
#!/bin/sh #!/bin/sh
ACTION=${1} ACTION=${1}
shift 1 shift 1
ARCH="default"
IMAGE_NAME='default'
get_image() { get_image() {
IMAGE_NAME="jellyfin/jellyfin" IMAGE_NAME=$(uci get jellyfin.@jellyfin[0].image_name 2>/dev/null)
}
do_install() {
get_image
echo "docker pull ${IMAGE_NAME}"
docker pull ${IMAGE_NAME}
docker rm -f jellyfin
do_install_detail
} }
do_install_detail() { do_install_detail() {
local hostnet=`uci get jellyfin.@jellyfin[0].hostnet 2>/dev/null` local config=$(uci get jellyfin.@jellyfin[0].config_path 2>/dev/null)
local media=`uci get jellyfin.@jellyfin[0].media_path 2>/dev/null` local port=$(uci get jellyfin.@jellyfin[0].port 2>/dev/null)
local config=`uci get jellyfin.@jellyfin[0].config_path 2>/dev/null` local IMAGE_NAME=$(uci get jellyfin.@jellyfin[0].image_name 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` LAN_IP=$(uci get network.lan.ipaddr)
local dev LAN_IP="${LAN_IP%/*}"
if [ -z "$config" ]; then if [ -z "$config" ]; then
echo "config path is empty!" echo "config path is empty!"
exit 1 exit 1
fi fi
[ -z "$port" ] && port=8096 [ -z "$port" ] && port=8096
[ -z "$IMAGE_NAME" ] && IMAGE_NAME="lscr.io/linuxserver/jellyfin:latest"
local cmd="docker run --restart=unless-stopped -d -v \"$config:/config\" "
rm -R /opt/docker2/compose/jellyfin-app
if [ "$hostnet" = 1 ]; then mkdir /opt/docker2/compose/jellyfin-app
cmd="$cmd\
--dns=127.0.0.1 \ touch /opt/docker2/compose/jellyfin-app/docker-compose.yml
--network=host " cat > /opt/docker2/compose/jellyfin-app/docker-compose.yml <<EOF
else version: "2.1"
cmd="$cmd\ services:
--dns=172.17.0.1 \ jellyfin:
-p $port:8096 " image: $IMAGE_NAME
fi container_name: jellyfin
environment:
local tz="`uci get system.@system[0].zonename`" - PUID=1000
[ -z "$tz" ] || cmd="$cmd -e TZ=$tz" - PGID=1000
- TZ=Etc/UTC
[ -z "$cache" ] || cmd="$cmd -v \"$cache:/config/transcodes\"" - JELLYFIN_PublishedServerUrl=${LAN_IP} #optional
[ -z "$media" ] || cmd="$cmd -v \"$media:/media\"" volumes:
- ./config:/config
cmd="$cmd -v /mnt:/mnt" - $config:/data/tvshows
mountpoint -q /mnt && cmd="$cmd:rslave" - $config:/data/movies
cmd="$cmd --name jellyfin \"$IMAGE_NAME\"" ports:
- ${LAN_IP}:$port:8096
echo "$cmd" - 8920:8920 #optional
eval "$cmd" - 7359:7359/udp #optional
- 1900:1900/udp #optional
restart: unless-stopped
EOF
docker-compose -f /opt/docker2/compose/jellyfin-app/docker-compose.yml up -d
uci add shortcutmenu lists
uci set shortcutmenu.@lists[-1].webname="$IMAGE_NAME"
uci set shortcutmenu.@lists[-1].weburl="$LAN_IP:$port"
uci set shortcutmenu.@lists[-1].webpath="/"
uci commit shortcutmenu
} }
usage() { usage() {
echo "usage: $0 sub-command" echo "usage: $0 sub-command"
echo "where sub-command is one of:" echo "where sub-command is one of:"
echo " install Install the jellyfin" echo " install Install Jellyfin"
echo " upgrade Upgrade the jellyfin" echo " upgrade Upgrade Jellyfin"
echo " rm/start/stop/restart Remove/Start/Stop/Restart the jellyfin" echo " rm/start/stop/restart Remove/Start/Stop/Restart Jellyfin"
echo " status Jellyfin status" echo " status Jellyfin status"
echo " port Jellyfin port" echo " port Jellyfin port"
} }
case ${ACTION} in case ${ACTION} in
"install") "install"|"upgrade")
do_install get_image
;; do_install_detail
"upgrade")
do_install
;; ;;
"rm") "rm")
docker rm -f jellyfin get_image
CONTAINER_IDS=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.ID}}')
echo "Stopping and removing containers..."
for ID in $CONTAINER_IDS; do
docker stop $ID
docker rm $ID
done
docker rmi -f $IMAGE_NAME
;; ;;
"start" | "stop" | "restart") "start"|"stop"|"restart")
docker ${ACTION} jellyfin get_image
CONTAINER_IDS=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.ID}}')
for ID in $CONTAINER_IDS; do
docker ${ACTION} ${ID}
done
;; ;;
"status") "status")
docker ps --all -f 'name=jellyfin' --format '{{.State}}' get_image
CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.Names}}')
docker ps --all -f "name=${CONTAINER_NAMES}" --format '{{.Status}}'
;; ;;
"port") "port")
docker ps --all -f 'name=jellyfin' --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://' get_image
CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.Names}}')
docker ps --all -f "name=${CONTAINER_NAMES}" --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://'
;; ;;
*) *)
usage usage
exit 1 exit 1
;; ;;
esac esac
Loading…
Cancel
Save