Changed script to avoid slow usermod when possible.

This commit is contained in:
Graham Booker 2017-01-09 09:31:00 -06:00
parent 3ae89855b4
commit d1ea49cc79
No known key found for this signature in database
GPG Key ID: 7FA620B73BAFAB5B

View File

@ -37,7 +37,23 @@ prefFile="${pmsApplicationSupportDir}/Plex Media Server/Preferences.xml"
# Setup user/group ids
if [ ! -z "${PLEX_UID}" ]; then
if [ ! "$(id -u plex)" -eq "${PLEX_UID}" ]; then
# usermod likes to chown the home directory, so create a new one and use that
# However, if the new UID is 0, we can't set the home dir back because the
# UID of 0 is already in use (executing this script).
if [ ! "${PLEX_UID}" -eq 0 ]; then
mkdir /tmp/temphome
usermod -d /tmp/temphome plex
fi
# Change the UID
usermod -o -u "${PLEX_UID}" plex
# Cleanup the temp home dir
if [ ! "${PLEX_UID}" -eq 0 ]; then
usermod -d /config plex
rm -Rf /tmp/temphome
fi
fi
fi