Skip to content

Commit 72b6c45

Browse files
authored
Merge pull request #387 from linuxserver/chown-transcode
set permissions on Plex Transcoder Temp Directory
2 parents d5e04e3 + 56562f4 commit 72b6c45

File tree

6 files changed

+95
-84
lines changed

6 files changed

+95
-84
lines changed

root/defaults/plexmediaserver

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

34
# create folders
4-
if [ ! -d "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" ]; then \
5+
if [[ ! -d "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" ]]; then
56
mkdir -p "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}"
6-
chown -R abc:abc /config
7+
lsiown -R abc:abc /config
78
fi
89

910
# check Library permissions
1011
PUID=${PUID:-911}
11-
if [ ! "$(stat -c %u /config/Library)" = "$PUID" ]; then
12+
if [[ ! "$(stat -c %u /config/Library)" == "${PUID}" ]]; then
1213
echo "Change in ownership detected, please be patient while we chown existing files"
1314
echo "This could take some time"
14-
chown abc:abc -R \
15-
/config/Library
15+
lsiown abc:abc -R \
16+
/config/Library
1617
fi
1718

1819
# remove plex pid after unclean stop
1920
if [[ -f "/config/Library/Application Support/Plex Media Server/plexmediaserver.pid" ]]; then
2021
rm -f "/config/Library/Application Support/Plex Media Server/plexmediaserver.pid"
2122
fi
2223

24+
# set permissions on Plex Transcoder Temp Directory
25+
PLEX_MEDIA_SERVER_PREFERENCES="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}/Plex Media Server/Preferences.xml"
26+
if [[ -f "${PLEX_MEDIA_SERVER_PREFERENCES}" ]]; then
27+
TranscoderTempDirectory='\bTranscoderTempDirectory="([^"]+)"'
28+
while IFS= read -r line; do
29+
if [[ ${line} =~ ${TranscoderTempDirectory} ]] && [[ -d "${BASH_REMATCH[1]}" ]]; then
30+
echo "Setting permissions on ${BASH_REMATCH[1]}"
31+
lsiown -R abc:abc "${BASH_REMATCH[1]}"
32+
fi
33+
done <"${PLEX_MEDIA_SERVER_PREFERENCES}"
34+
fi
35+
2336
# permissions (non-recursive) on config root and folders
24-
chown abc:abc \
37+
lsiown abc:abc \
2538
/config \
2639
/config/*
Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,89 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

3-
if grep -qs "PlexOnlineToken" "/config/Library/Application Support/Plex Media Server/Preferences.xml"; then
4+
PLEX_MEDIA_SERVER_PREFERENCES="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}/Plex Media Server/Preferences.xml"
5+
6+
if grep -qs "PlexOnlineToken" "${PLEX_MEDIA_SERVER_PREFERENCES}"; then
47
echo "**** Server already claimed ****"
58
exit 0
6-
elif [ -z "$PLEX_CLAIM" ]; then
9+
elif [[ -z "$PLEX_CLAIM" ]]; then
710
echo "**** Server is unclaimed, but no claim token has been set ****"
811
exit 0
912
fi
10-
PREFNAME="/config/Library/Application Support/Plex Media Server/Preferences.xml"
11-
if [ ! -f "${PREFNAME}" ]; then
13+
14+
if [[ ! -f "${PLEX_MEDIA_SERVER_PREFERENCES}" ]]; then
1215
UMASK_SET="${UMASK_SET:-022}"
1316
umask "$UMASK_SET"
1417
echo "Temporarily starting Plex Media Server."
15-
export PLEX_MEDIA_SERVER_INFO_MODEL=$(uname -m)
16-
export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION=$(uname -r)
18+
PLEX_MEDIA_SERVER_INFO_MODEL=$(uname -m)
19+
export PLEX_MEDIA_SERVER_INFO_MODEL
20+
PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION=$(uname -r)
21+
export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION
1722
s6-setuidgid abc /bin/bash -c \
18-
'LD_LIBRARY_PATH=/usr/lib/plexmediaserver:/usr/lib/plexmediaserver/lib /usr/lib/plexmediaserver/Plex\ Media\ Server' & PID=$!
23+
'LD_LIBRARY_PATH=/usr/lib/plexmediaserver:/usr/lib/plexmediaserver/lib /usr/lib/plexmediaserver/Plex\ Media\ Server' &
24+
PID=$!
1925
echo "Waiting for Plex to generate its config"
2026
DBNAME="/config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db-wal"
21-
until [ -f "${DBNAME}" ]; do
27+
until [[ -f "${DBNAME}" ]]; do
2228
sleep 1
2329
done
2430
while true; do
2531
echo "Waiting for database creation to complete..."
26-
if [ -z "${COMPARE_MD5+x}" ]; then
27-
COMPARE_MD5=$(md5sum "${DBNAME}"| cut -c1-8)
32+
if [[ -z "${COMPARE_MD5+x}" ]]; then
33+
COMPARE_MD5=$(md5sum "${DBNAME}" | cut -c1-8)
2834
sleep 3
2935
else
3036
sleep 3
31-
CURRENT_MD5=$(md5sum "${DBNAME}"| cut -c1-8)
32-
if [ "${CURRENT_MD5}" == "${COMPARE_MD5}" ]; then
37+
CURRENT_MD5=$(md5sum "${DBNAME}" | cut -c1-8)
38+
if [[ "${CURRENT_MD5}" == "${COMPARE_MD5}" ]]; then
3339
break
3440
else
35-
COMPARE_MD5=$(md5sum "${DBNAME}"| cut -c1-8)
41+
COMPARE_MD5=$(md5sum "${DBNAME}" | cut -c1-8)
3642
fi
3743
fi
3844
done
39-
until grep -qs "ProcessedMachineIdentifier" "${PREFNAME}"; do
45+
until grep -qs "ProcessedMachineIdentifier" "${PLEX_MEDIA_SERVER_PREFERENCES}"; do
4046
sleep 1
4147
done
4248
while true; do
4349
echo "Waiting for pref file creation to complete..."
44-
if [ -z "${PREF_COMPARE_MD5+x}" ]; then
45-
PREF_COMPARE_MD5=$(md5sum "${PREFNAME}"| cut -c1-8)
50+
if [[ -z "${PREF_COMPARE_MD5+x}" ]]; then
51+
PREF_COMPARE_MD5=$(md5sum "${PLEX_MEDIA_SERVER_PREFERENCES}" | cut -c1-8)
4652
sleep 3
4753
else
4854
sleep 3
49-
PREF_CURRENT_MD5=$(md5sum "${PREFNAME}"| cut -c1-8)
50-
if [ "${PREF_CURRENT_MD5}" == "${PREF_COMPARE_MD5}" ]; then
55+
PREF_CURRENT_MD5=$(md5sum "${PLEX_MEDIA_SERVER_PREFERENCES}" | cut -c1-8)
56+
if [[ "${PREF_CURRENT_MD5}" == "${PREF_COMPARE_MD5}" ]]; then
5157
break
5258
else
53-
PREF_COMPARE_MD5=$(md5sum "${PREFNAME}"| cut -c1-8)
59+
PREF_COMPARE_MD5=$(md5sum "${PLEX_MEDIA_SERVER_PREFERENCES}" | cut -c1-8)
5460
fi
5561
fi
5662
done
5763
echo "Stopping Plex to claim server"
58-
while ps -p $PID > /dev/null; do
64+
while ps -p $PID >/dev/null; do
5965
kill $PID
6066
sleep 1
6167
done
6268
echo "Plex stopped"
6369
fi
6470

65-
ProcessedMachineIdentifier=$(sed -n "s/^.*ProcessedMachineIdentifier=\"\([^\"]*\)\".*$/\1/p" "${PREFNAME}")
71+
ProcessedMachineIdentifier=$(sed -n "s/^.*ProcessedMachineIdentifier=\"\([^\"]*\)\".*$/\1/p" "${PLEX_MEDIA_SERVER_PREFERENCES}")
6672
PlexOnlineToken="$(curl -X POST \
6773
-H 'X-Plex-Client-Identifier: '"${ProcessedMachineIdentifier}" \
68-
-H 'X-Plex-Product: Plex Media Server'\
74+
-H 'X-Plex-Product: Plex Media Server' \
6975
-H 'X-Plex-Version: 1.1' \
7076
-H 'X-Plex-Provides: server' \
7177
-H 'X-Plex-Platform: Linux' \
7278
-H 'X-Plex-Platform-Version: 1.0' \
7379
-H 'X-Plex-Device-Name: PlexMediaServer' \
7480
-H 'X-Plex-Device: Linux' \
75-
"https://plex.tv/api/claim/exchange?token=${PLEX_CLAIM}" \
76-
| sed -n 's/.*<authentication-token>\(.*\)<\/authentication-token>.*/\1/p')"
81+
"https://plex.tv/api/claim/exchange?token=${PLEX_CLAIM}" |
82+
sed -n 's/.*<authentication-token>\(.*\)<\/authentication-token>.*/\1/p')"
7783

78-
if [ -n "$PlexOnlineToken" ]; then
84+
if [[ -n "$PlexOnlineToken" ]]; then
7985
echo "Server claimed successfully, navigate to http://serverip:32400/web to complete plex setup."
80-
sed -i "s/\/>/ PlexOnlineToken=\"${PlexOnlineToken}\"\/>/g" "${PREFNAME}"
86+
sed -i "s/\/>/ PlexOnlineToken=\"${PlexOnlineToken}\"\/>/g" "${PLEX_MEDIA_SERVER_PREFERENCES}"
8187
else
8288
echo "Unable to claim Plex server. Either manually claim by connecting to http://serverip:32400/web from the same network subnet, or recreate container with a new claim token."
8389
fi

root/etc/s6-overlay/s6-rc.d/init-plex-gid-video/run

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

34
FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null)
45

5-
for i in $FILES
6-
do
6+
for i in ${FILES}; do
77
VIDEO_GID=$(stat -c '%g' "${i}")
88
VIDEO_UID=$(stat -c '%u' "${i}")
99
# check if user matches device
1010
if id -u abc | grep -qw "${VIDEO_UID}"; then
1111
echo "**** permissions for ${i} are good ****"
1212
else
1313
# check if group matches and that device has group rw
14-
if id -G abc | grep -qw "${VIDEO_GID}" && [ $(stat -c '%A' "${i}" | cut -b 5,6) = "rw" ]; then
14+
if id -G abc | grep -qw "${VIDEO_GID}" && [[ $(stat -c '%A' "${i}" | cut -b 5,6) == "rw" ]]; then
1515
echo "**** permissions for ${i} are good ****"
1616
# check if device needs to be added to video group
1717
elif ! id -G abc | grep -qw "${VIDEO_GID}"; then
1818
# check if video group needs to be created
1919
VIDEO_NAME=$(getent group "${VIDEO_GID}" | awk -F: '{print $1}')
20-
if [ -z "${VIDEO_NAME}" ]; then
20+
if [[ -z "${VIDEO_NAME}" ]]; then
2121
VIDEO_NAME="video$(head /dev/urandom | tr -dc 'a-z0-9' | head -c4)"
2222
groupadd "${VIDEO_NAME}"
2323
groupmod -g "${VIDEO_GID}" "${VIDEO_NAME}"
@@ -27,7 +27,7 @@ do
2727
usermod -a -G "${VIDEO_NAME}" abc
2828
fi
2929
# check if device has group rw
30-
if [ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]; then
30+
if [[ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]]; then
3131
echo -e "**** The device ${i} does not have group read/write permissions, attempting to fix inside the container. ****"
3232
chmod g+rw "${i}"
3333
fi
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

34
# If docker manages versioning exit
4-
if [ "${VERSION}" ] && [ "${VERSION}" == 'docker' ]; then
5+
if [[ -n "${VERSION}" ]] && [[ "${VERSION}" == "docker" ]]; then
56
echo "Docker is used for versioning skip update check"
67
exit 0
78
fi
@@ -12,30 +13,32 @@ if (dpkg --get-selections plexmediaserver | grep -wq "install"); then
1213
else
1314
echo "for some reason plex doesn't appear to be installed, pulling a new copy and exiting out of update script"
1415
curl -o /tmp/plexmediaserver.deb -L \
15-
"${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb" && \
16+
"${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
1617
dpkg -i --force-confold /tmp/plexmediaserver.deb
1718
rm -f /tmp/plexmediaserver.deb
1819
exit 0
1920
fi
2021

2122
# set no update message
22-
[[ -e /tmp/no-version.nfo ]] && \
23+
if [[ -e /tmp/no-version.nfo ]]; then
2324
rm /tmp/no-version.nfo
25+
fi
2426
NOVERSION_SET='/tmp/no-version.nfo'
25-
cat > "${NOVERSION_SET}" <<-EOFVERSION
27+
cat >"${NOVERSION_SET}" <<-EOFVERSION
2628
#######################################################
27-
# Update routine will not run because you havent set #
29+
# Update routine will not run because you haven't set #
2830
# the VERSION variable or you opted out of updates. #
2931
# For more information checkout :- #
3032
# https://github.com/linuxserver/docker-plex #
3133
#######################################################
3234
EOFVERSION
3335

3436
# set update failed message
35-
[[ -e /tmp/update_fail.nfo ]] && \
37+
if [[ -e /tmp/update_fail.nfo ]]; then
3638
rm /tmp/update_fail.nfo
39+
fi
3740
UPGRADE_FAIL='/tmp/update_fail.nfo'
38-
cat > "${UPGRADE_FAIL}" <<-EOFFAIL
41+
cat >"${UPGRADE_FAIL}" <<-EOFFAIL
3942
########################################################
4043
# Upgrade attempt failed, this could be because either #
4144
# plex update site is down, local network issues, or #
@@ -45,25 +48,27 @@ cat > "${UPGRADE_FAIL}" <<-EOFFAIL
4548
########################################################
4649
EOFFAIL
4750

48-
# test for no version set or opt out for autoupdates
49-
if [[ -z "$VERSION" ]] || [[ "$VERSION" == "0" ]] || [[ -n "$ADVANCED_DISABLEUPDATES" ]]; then
51+
# test for no version set or opt out for auto updates
52+
if [[ -z "${VERSION}" ]] || [[ "${VERSION}" == "0" ]] || [[ -n "${ADVANCED_DISABLEUPDATES}" ]]; then
5053
printf '\n\n\n%s\n\n\n' "$(</tmp/no-version.nfo)"
5154
exit 0
5255
fi
5356

5457
# set header for no preferences/token message
55-
[[ -e /tmp/no-token.nfo ]] && \
58+
if [[ -e /tmp/no-token.nfo ]]; then
5659
rm /tmp/no-token.nfo
60+
fi
5761
NOTOKEN_SET='/tmp/no-token.nfo'
58-
cat > "${NOTOKEN_SET}" <<-EOFTOKEN
62+
cat >"${NOTOKEN_SET}" <<-EOFTOKEN
5963
#####################################################
6064
# Login via the webui at http://<ip>:32400/web #
6165
# and restart the container, because there was no #
6266
EOFTOKEN
6367

6468
# if preferences files doesn't exist, exit out
65-
if [ ! -e "/config/Library/Application Support/Plex Media Server/Preferences.xml" ]; then
66-
cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
69+
PLEX_MEDIA_SERVER_PREFERENCES="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}/Plex Media Server/Preferences.xml"
70+
if [[ ! -e "${PLEX_MEDIA_SERVER_PREFERENCES}" ]]; then
71+
cat >>"${NOTOKEN_SET}" <<-EOFTOKEN
6772
# preference file found, possibly first startup. #
6873
#####################################################
6974
EOFTOKEN
@@ -72,13 +77,13 @@ EOFTOKEN
7277
fi
7378

7479
# attempt to read plex token
75-
PLEX_TOKEN=$( sed -n 's/.*PlexOnlineToken="//p' \
76-
"/config/Library/Application Support/Plex Media Server/Preferences.xml" \
77-
| sed "s/\".*//")
80+
PLEX_TOKEN=$(sed -n 's/.*PlexOnlineToken="//p' \
81+
"${PLEX_MEDIA_SERVER_PREFERENCES}" |
82+
sed "s/\".*//")
7883

7984
# if plex token isn't found, exit out
80-
if [ -z "$PLEX_TOKEN" ]; then
81-
cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
85+
if [[ -z "${PLEX_TOKEN}" ]]; then
86+
cat >>"${NOTOKEN_SET}" <<-EOFTOKEN
8287
# plex token found in the preference file #
8388
#####################################################
8489
EOFTOKEN
@@ -90,22 +95,22 @@ fi
9095
INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' plexmediaserver)
9196

9297
# start update routine
93-
if [[ "${VERSION,,}" = latest ]] || [[ "${VERSION,,}" = plexpass ]] || [[ "$PLEXPASS" == "1" ]]; then
94-
if [[ "${PLEX_ARCH}" = amd64 ]]; then
98+
if [[ "${VERSION,,}" == "latest" ]] || [[ "${VERSION,,}" == "plexpass" ]] || [[ "${PLEXPASS}" == "1" ]]; then
99+
if [[ "${PLEX_ARCH}" == "amd64" ]]; then
95100
PLEX_URL_ARCH="x86_64"
96-
elif [[ "${PLEX_ARCH}" = armhf ]]; then
101+
elif [[ "${PLEX_ARCH}" == "armhf" ]]; then
97102
PLEX_URL_ARCH="armv7hf_neon"
98-
elif [[ "${PLEX_ARCH}" = arm64 ]]; then
103+
elif [[ "${PLEX_ARCH}" == "arm64" ]]; then
99104
PLEX_URL_ARCH="aarch64"
100105
fi
101-
REMOTE_VERSION=$(curl -s "https://plex.tv/downloads/details/5?distro=debian&build=linux-${PLEX_URL_ARCH}&channel=8&X-Plex-Token=$PLEX_TOKEN"| grep -oP 'version="\K[^"]+' | tail -n 1 )
102-
elif [[ "${VERSION,,}" = public ]]; then
106+
REMOTE_VERSION=$(curl -s "https://plex.tv/downloads/details/5?distro=debian&build=linux-${PLEX_URL_ARCH}&channel=8&X-Plex-Token=${PLEX_TOKEN}" | grep -oP 'version="\K[^"]+' | tail -n 1)
107+
elif [[ "${VERSION,,}" == "public" ]]; then
103108
REMOTE_VERSION=$(curl -s 'https://plex.tv/api/downloads/5.json' | jq -r '.computer.Linux.version')
104109
else
105110
REMOTE_VERSION="${VERSION}"
106111
fi
107112

108-
if [[ "$REMOTE_VERSION" == "$INSTALLED_VERSION" ]]; then
113+
if [[ "${REMOTE_VERSION}" == "${INSTALLED_VERSION}" ]]; then
109114
echo "No update required"
110115
exit 0
111116
fi
@@ -115,18 +120,18 @@ if [[ -z "${REMOTE_VERSION}" ]]; then
115120
exit 0
116121
fi
117122

118-
echo "Atempting to upgrade to: $REMOTE_VERSION"
123+
echo "Attempting to upgrade to: ${REMOTE_VERSION}"
119124
rm -f /tmp/plexmediaserver_*.deb
120125
wget -nv -P /tmp \
121126
"${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
122127
last=$?
123128

124129
# test if deb file size is ok, or if download failed
125-
if [[ "$last" -gt "0" ]] || [[ $(stat -c %s /tmp/plexmediaserver_"${REMOTE_VERSION}"_${PLEX_ARCH}.deb) -lt 10000 ]]; then
130+
if [[ "${last}" -gt "0" ]] || [[ $(stat -c %s "/tmp/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb") -lt 10000 ]]; then
126131
printf '\n\n\n%s\n\n\n' "$(</tmp/update_fail.nfo)"
127132
exit 0
128133
# if ok, try to install it.
129134
else
130-
dpkg -i --force-confold /tmp/plexmediaserver_"${REMOTE_VERSION}"_${PLEX_ARCH}.deb
135+
dpkg -i --force-confold "/tmp/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
131136
rm -f /tmp/plexmediaserver_*.deb
132137
fi
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

34
echo "Starting Plex Media Server. . . (you can ignore the libusb_init error)"
4-
export PLEX_MEDIA_SERVER_INFO_MODEL=$(uname -m)
5-
export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION=$(uname -r)
5+
PLEX_MEDIA_SERVER_INFO_MODEL=$(uname -m)
6+
export PLEX_MEDIA_SERVER_INFO_MODEL
7+
PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION=$(uname -r)
8+
export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION
69
exec \
710
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 32400" \
8-
s6-setuidgid abc "/usr/lib/plexmediaserver/Plex Media Server"
11+
s6-setuidgid abc "/usr/lib/plexmediaserver/Plex Media Server"

0 commit comments

Comments
 (0)