Skip to content

Instantly share code, notes, and snippets.

@misuchiru03
Last active May 1, 2020 17:04
Show Gist options
  • Save misuchiru03/f12163e619004e7adf5b3cec1be36d3d to your computer and use it in GitHub Desktop.
Save misuchiru03/f12163e619004e7adf5b3cec1be36d3d to your computer and use it in GitHub Desktop.
Plex Media Server installer for Void Linux
#!/bin/sh
if [ $(id -u) -ne 0 ]; then
echo "You must be root to run this."
exit 0
fi
missing=0
for pkg in wget curl rsync ar; do
echo -n "Checking for $pkg..."
if [ ! -x "$(which $pkg 2>/dev/null)" ]; then
echo "FAIL."
missing=1
else
echo "OK"
fi
done
if [ "$missing" != "0" ]; then
echo "Install the required packages and try again."
exit
fi
USRNAME=$(echo ${SUDO_USER})
DOWNLOADS="/home/${USRNAME}/Downloads"
UPDATEVERSION=$(curl -s "https://plex.tv/downloads/latest/1?channel=16&build=linux-ubuntu-x86_64&distro=ubuntu" | awk -F "_" '{ print $2 }')
#install plex
echo -n "Grabbing plex... in a nice way... nothing inappropriate..."
sudo -u ${USRNAME} wget -q --show-progress -O ${DOWNLOADS}/plex-${UPDATEVERSION}.deb "https://plex.tv/downloads/latest/1?channel=16&build=linux-ubuntu-x86_64&distro=ubuntu"
echo "OK"
echo -n "Making working directories..."
sudo -u ${USRNAME} mkdir ${DOWNLOADS}/plexmediaserver
PLEXDIR="${DOWNLOADS}/plexmediaserver"
cd ${PLEXDIR}
echo "OK"
echo -n "Unpacking plex package..."
sudo -u ${USRNAME} ar x ${DOWNLOADS}/plex-${UPDATEVERSION}.deb
sudo -u ${USRNAME} tar zxf ${PLEXDIR}/data.tar.gz
echo "OK"
echo -n "Patching plex..."
cat <<ENP | patch -Np0
--- usr/sbin/start_pms.orig
+++ usr/sbin/start_pms
@@ -1,5 +1,7 @@
#!/bin/sh
+HOME="/var/lib/plexmediaserver"
+
#change these parameters in /etc/default/plexmediaserver
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
@@ -33,4 +35,5 @@
# Add sleep - Possible fix for start on boot.
sleep 3
-(cd /usr/lib/plexmediaserver; ./Plex\ Media\ Server)
+cd /usr/lib/plexmediaserver
+exec ./Plex\ Media\ Server -f
ENP
echo "OK"
echo -n "Moving files..."
rsync -azru ${PLEXDIR}/etc/default/ /etc/
rsync -azru ${PLEXDIR}/usr/lib/ /usr/lib/
rsync -azru ${PLEXDIR}/lib/ /usr/lib/
rsync -azru ${PLEXDIR}/usr/sbin/ /usr/sbin/
rsync -azru ${PLEXDIR}/usr/share/doc/ /usr/share/doc/
rsync -azru ${PLEXDIR}/usr/share/pixmaps/ /usr/share/pixmaps/
rsync -azru ${PLEXDIR}/usr/share/applications/ /usr/share/applications/
echo "OK"
echo -n "Setting up plex environment..."
useradd _plex
mkdir -p "/var/lib/plexmediaserver/Library/Application Support"
usermod -d /var/lib/plexmediaserver _plex
echo "OK"
echo -n "Creating runit service..."
mkdir -p /etc/sv/plexmediaserver
#cat /usr/sbin/start_pms | sed 's/^(.*)$/exec chpst -u plex \/usr\/lib\/plexmediaserver\/Plex\\ Media\\ Server\ -f/' > /etc/sv/plexmediaserver/run
echo -e '#!/bin/sh\n\nexec chpst -u _plex:_plex /usr/sbin/start_pms' > /etc/sv/plexmediaserver/run
chmod +x /etc/sv/plexmediaserver/run
ln -s /etc/sv/plexmediaserver /var/service/
echo "OK"
echo -n "Removing old files..."
rm -rf ${PLEXDIR}
rm -f ${DOWNLOADS}/plex-${UPDATEVERSION}.deb
echo "OK"
echo "DONE"
exit 0
@misuchiru03
Copy link
Author

Added plex user and plex's home directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment