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