#!/bin/bash
#This should always return the name of the docker container running plex - assuming a single plex docker on the system.
con="`docker ps --format "{{.Names}}" | grep -i plex`"
echo ""
echo "<b>Applying hardware decode patch...</b>"
echo "<hr>"
#Check to see if Plex Transcoder2 Exists first.
exists=`docker exec -i $con stat "/usr/lib/plexmediaserver/Plex Transcoder2" >/dev/null 2>&1; echo $?`
if [ $exists -eq 1 ]; then # If it doesn't, we run the clause below
docker exec -i $con mv "/usr/lib/plexmediaserver/Plex Transcoder" "/usr/lib/plexmediaserver/Plex Transcoder2"
docker exec -i $con /bin/sh -c 'printf "#!/bin/sh\nexec /usr/lib/plexmediaserver/Plex\ Transcoder2 -hwaccel nvdec "\""\$@"\""" > "/usr/lib/plexmediaserver/Plex Transcoder";'
docker exec -i $con chmod +x "/usr/lib/plexmediaserver/Plex Transcoder"
docker exec -i $con chmod +x "/usr/lib/plexmediaserver/Plex Transcoder2"
docker restart $con
echo ""
echo '<font color="green"><b>Done!</b></font>' #Green means go!
else
echo ""
echo '<font color="red"><b>Patch already applied or invalid container!</b></font>' #Red means stop!
fi
EDIT:
Just corrected some flawed assumptions on the logic above.
Using grep -i to grab container name so that it matches without case sensitivity.
Using a variable to capture the return value of the stat, since docker exec -it can't be used and docker exec -i always returns 0.
Flipped -eq 0 to -eq 1 since that was the inverse of the intended behavior.
Only weird thing is something prints "plex" lowercase and I don't know where.
EDIT2:
Figured that out, docker restart $con prints the name of the container once it's restarted. Could redirect the output to /dev/null, though.