Skip to content

Instantly share code, notes, and snippets.

@neokneok
Forked from tommeier/autorun-plexconnect.sh
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neokneok/3d61d49da096837472c4 to your computer and use it in GitHub Desktop.
Save neokneok/3d61d49da096837472c4 to your computer and use it in GitHub Desktop.
#!/bin/sh
# /share/CACHEDEV1_DATA/.qpkg/autorun/autorun-plexconnect.sh
# chmod +x /share/CACHEDEV1_DATA/.qpkg/autorun/autorun-plexconnect.sh
/etc/init.d/Qthttpd.sh stop
curl -L -k https://gist.github.com/neokneok/3d61d49da096837472c4/raw/update_plex_connect.sh | bash &
#!/bin/sh
# http://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup
# Update and run plexconnect (with logging)
[[ -f /share/CACHEDEV1_DATA/.qpkg/autorun/autorun-plexconnect.sh ]] && /share/CACHEDEV1_DATA/.qpkg/autorun/autorun-plexconnect.sh &
#!/bin/bash
set -e
# ======================================================================
#
# Install / Update Plexconnect on Qnap
#
# ======================================================================
# Context:
# This is my build + update script for plexconnect on a Qnap 670. I run this
# script from my QNAP while SSHed in from a Mac.
# You can fork this code here: https://gist.github.com/tommeier/6255771
# Running this raw script is as easy as running this one line on the QNAP:
# curl -L https://gist.github.com/neokneok/3d61d49da096837472c4/raw/update_plex_connect.sh | bash
#
# Requirements:
# - Latest Plex QPkg is installed and running
# - Knowledge on how to SSH on to your QNAP
# - ipkg install bash
# - Ensure your webserver is disabled or change the port from 80 to something else
# - Set autorun.sh to load PlexConnect on boot. See http://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup
# Ensure the following is installed on the QNAP already via QPKGs
# - Optware (http://wiki.qnap.com/wiki/Install_Optware_IPKG)
# - Python
#
# Example usage:
# > ssh on to qnap (ssh admin@192.168.x.x)
# > Simply run this next line from the command line on the QNAP
# curl -L https://gist.github.com/neokneok/3d61d49da096837472c4/raw/update_plex_connect.sh | bash
#
# Useful commands in debugging:
# # Copy all plex logs:
# > scp -r "admin@192.168.0.x:/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex\ Media\ Server/Logs" .
# # Copy certificate files (to install on AppleTV):
# > scp -r "admin@192.168.0.x:/share/CACHEDEV1_DATA/.plexconnect/assets/certificates" .
#
# Global variables
PLEX_GIT="git://github.com/iBaa/PlexConnect.git"
PLEX_GIT_DIR_ROOT="/share/CACHEDEV1_DATA"
PLEX_FOLDER_NAME='.plexconnect'
PLEX_GIT_DIR="${PLEX_GIT_DIR_ROOT}/${PLEX_FOLDER_NAME}"
PLEX_CERT_DIR="${PLEX_GIT_DIR}/assets/certificates"
PLEX_CERT_PATH="${PLEX_CERT_DIR}/trailers.pem" # trailers.cer also required
PYTHON_BIN="/share/CACHEDEV1_DATA/.qpkg/Python/bin/python"
#PLEX_BIN="${PLEX_GIT_DIR}/PlexConnect.py"
PLEX_DAEMON_SH="PlexConnect_daemon.bash"
PLEX_DAEMON_SH_PATH="${PLEX_GIT_DIR}/${PLEX_DAEMON_SH}"
SPACER="--------------------------------------------"
# /Global variables
# Qnap logging with echo
write_to_log() {
local message="$1"
local log_type="0"
#0 = information, 1 = warning, 2 = error
if [[ "$2" != '' ]]; then
local log_type="$2"
fi;
echo "[plexconnect-script] ${message}"
/sbin/log_tool --append "[plexconnect-script] ${message}" --type $log_type
}
check_daemon_exists(){
if [ ! -e $PLEX_DAEMON_SH_PATH ]; then
echo $SPACER
write_to_log ">!! Error: Expected to find '$PLEX_DAEMON_SH_PATH' to control PlexConnect. Change script to match updates."
echo $SPACER
exit 1
fi;
}
echo $SPACER
write_to_log ">>> Start of Plexconnect Install Script <<<<"
echo $SPACER
write_to_log ">>> Checking dependencies..."
echo $SPACER
if [ ! -e $PYTHON_BIN ]; then
echo $SPACER
write_to_log ">!! Error: Please install Python as a QPKG."
echo $SPACER
exit 1
fi;
if [ ! -d "/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer" ]; then
echo $SPACER
write_to_log ">!! Error: Please install Plex Media Server as a QPKG."
echo $SPACER
exit 1
fi;
echo $SPACER
write_to_log ">>> Installing required iPkg dependencies"
echo $SPACER
/opt/bin/ipkg update
/opt/bin/ipkg install bash
/opt/bin/ipkg install git
if [ ! -d $PLEX_GIT_DIR ]; then
echo $SPACER
write_to_log ">>> Cloning latest plexconnect to '$PLEX_GIT_DIR'"
echo $SPACER
cd $PLEX_GIT_DIR_ROOT
/opt/bin/git clone $PLEX_GIT $PLEX_FOLDER_NAME
else
echo $SPACER
write_to_log ">>> Stopping any existing PlexConnect process"
echo $SPACER
check_daemon_exists;
cd $PLEX_GIT_DIR
./$PLEX_DAEMON_SH stop
echo $SPACER
write_to_log ">>> Updating existing plexconnect"
echo $SPACER
cd $PLEX_GIT_DIR
/opt/bin/git pull
fi;
if [ ! -e $PLEX_CERT_PATH ]; then
echo $SPACER
write_to_log ">>> Plex certificate missing."
echo $SPACER
cd $PLEX_CERT_DIR
write_to_log ">>> -> Generating trailers.pem certificate."
openssl req -new -nodes -newkey rsa:2048 -out trailers.pem -keyout trailers.key -x509 -days 7300 -subj "/C=US/CN=trailers.apple.com"
write_to_log ">>> -> Applying key and permissions to certificate."
openssl x509 -in trailers.pem -outform der -out trailers.cer && cat trailers.key >> trailers.pem
write_to_log ">>> -> Done. (optionally - add to apple tv)."
cd $PLEX_GIT_DIR
else
echo $SPACER
write_to_log ">>> Plex certificate present: '${PLEX_CERT_PATH}'"
echo $SPACER
fi;
check_daemon_exists;
echo $SPACER
write_to_log ">>> Starting PlexConnect Daemon"
echo $SPACER
cd $PLEX_GIT_DIR
./$PLEX_DAEMON_SH start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment