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

main
ben 1 year ago
parent ee8f42d965
commit 6d13413103

@ -1,106 +1,109 @@
#!/bin/sh
ACTION=${1}
shift 1
do_install() {
local hostnet=`uci get plex.@main[0].hostnet 2>/dev/null`
local claim_token==`uci get plex.@main[0].claim_token 2>/dev/null`
local port=`uci get plex.@main[0].port 2>/dev/null`
local image_name=`uci get plex.@main[0].image_name 2>/dev/null`
local config=`uci get plex.@main[0].config_path 2>/dev/null`
local media=`uci get plex.@main[0].media_path 2>/dev/null`
local cache=`uci get plex.@main[0].cache_path 2>/dev/null`
get_image() {
IMAGE_NAME=$(uci get plex.@main[0].image_name 2>/dev/null)
}
if [ -z "$config" ]; then
echo "config path is empty!"
exit 1
fi
if [ -z "$cache" ]; then
echo "cache path is empty!"
do_install_detail() {
local hostnet=$(uci get plex.@main[0].hostnet 2>/dev/null)
local claim_token=$(uci get plex.@main[0].claim_token 2>/dev/null)
local port=$(uci get plex.@main[0].port 2>/dev/null)
local IMAGE_NAME=$(uci get plex.@main[0].image_name 2>/dev/null)
local config=$(uci get plex.@main[0].config_path 2>/dev/null)
local media=$(uci get plex.@main[0].media_path 2>/dev/null)
local cache=$(uci get plex.@main[0].cache_path 2>/dev/null)
local LAN_IP=$(uci get network.lan.ipaddr)
LAN_IP="${LAN_IP%/*}"
if [ -z "$config" ] || [ -z "$media" ]; then
echo "config or media path is empty!"
exit 1
fi
[ -z "$image_name" ] && image_name="linuxserver/plex:latest"
echo "docker pull ${image_name}"
docker pull ${image_name}
docker rm -f plex
[ -z "$port" ] && port=32400
local cmd="docker run --restart=unless-stopped -d -h PlexServer -v \"$config:/config\" "
if [ -d /dev/dri ]; then
cmd="$cmd\
--device /dev/dri:/dev/dri \
--privileged "
fi
if [ "$hostnet" = 1 ]; then
cmd="$cmd\
--dns=127.0.0.1 \
--network=host "
else
cmd="$cmd\
--dns=172.17.0.1 \
-p 3005:3005/tcp \
-p 8324:8324/tcp \
-p 32469:32469/tcp \
-p 32410:32410/udp \
-p 32412:32412/udp \
-p 32413:32413/udp \
-p 32414:32414/udp \
-p $port:32400 "
fi
local tz="`uci get system.@system[0].zonename`"
[ -z "$tz" ] || cmd="$cmd -e TZ=$tz"
[ -z "$claim_token" ] || cmd="$cmd -e \"PLEX_CLAIM=$claim_token\""
cmd="$cmd -v \"$cache:/transcode\""
cmd="$cmd -v \"$cache:/config/Library/Application Support/Plex Media Server/Cache\""
[ -z "$media" ] || cmd="$cmd -v \"$media:/data\""
cmd="$cmd -v /mnt:/mnt"
mountpoint -q /mnt && cmd="$cmd:rslave"
cmd="$cmd --name plex \"$image_name\""
echo "$cmd"
eval "$cmd"
[ -z "$IMAGE_NAME" ] && IMAGE_NAME="lscr.io/linuxserver/plex:latest"
rm -R /opt/docker2/compose/plex-app
mkdir /opt/docker2/compose/plex-app
touch /opt/docker2/compose/plex-app/docker-compose.yml
cat > /opt/docker2/compose/plex-app/docker-compose.yml <<EOF
version: "2.1"
services:
plex:
image: $IMAGE_NAME
container_name: plex
network_mode: host
environment:
- PUID=1000
- PGID=1000
- TZ=Etc/UTC
- VERSION=docker
- PLEX_CLAIM=${claim_token}
volumes:
- ./config:/config
- ${config}/tv:/tv
- ${config}/movies:/movies
restart: unless-stopped
labels:
plugsy.name: "Plex"
plugsy.category: "Home"
plugsy.link: "http://${LAN_IP}:${port}"
EOF
docker-compose -f /opt/docker2/compose/plex-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() {
echo "usage: $0 sub-command"
echo "where sub-command is one of:"
echo " install Install the plex"
echo " upgrade Upgrade the plex"
echo " rm/start/stop/restart Remove/Start/Stop/Restart the plex"
echo " install Install Plex"
echo " upgrade Upgrade Plex"
echo " rm/start/stop/restart Remove/Start/Stop/Restart Plex"
echo " status Plex status"
echo " port Plex port"
}
case ${ACTION} in
"install")
do_install
;;
"upgrade")
do_install
"install"|"upgrade")
get_image
do_install_detail
;;
"rm")
docker rm -f plex
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")
docker ${ACTION} plex
"start"|"stop"|"restart")
get_image
CONTAINER_IDS=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.ID}}')
for ID in $CONTAINER_IDS; do
docker ${ACTION} ${ID}
done
;;
"status")
docker ps --all -f 'name=plex' --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")
local port=`docker ps --all -f 'name=plex' --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*->32400/tcp' | sed 's/0.0.0.0:\([0-9]*\)->.*/\1/'`
[ -z "$port" ] && port=32400
echo $port
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

Loading…
Cancel
Save