Last active
August 29, 2015 14:01
-
-
Save zackbcom/5cd2b00d48d471fddbc8 to your computer and use it in GitHub Desktop.
Install SickRage on Slackware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#sudo sbopkg -i pysetuptools | |
#sudo sbopkg -i python-oauthlib | |
#sudo sbopkg -i python-requests | |
#sudo sbopkg -i requests-oauthlib | |
#sudo sbopkg -i python-cheetah | |
command -v git >/dev/null 2>&1 || { echo >&2 "git not installed."; exit 1; }; | |
command -v python >/dev/null 2>&1 || { echo >&2 "python not installed."; exit 1; }; | |
command -v cheetah >/dev/null 2>&1 || { echo >&2 "python-cheetah not installed."; exit 1; }; | |
sudo groupadd media | |
sudo useradd --system --user-group --no-create-home --groups media sickrage | |
sudo git clone git://github.com/echel0n/SickRage.git /opt/sickrage | |
sudo chown -R sickrage:sickrage /opt/sickrage | |
touch /etc/rc.d/rc.sickrage | |
chmod +x /etc/rc.d/rc.sickrage | |
#Add rc.sickrage | |
cat <<'EOF' > /etc/rc.d/rc.sickrage | |
#!/bin/sh | |
# Start/stop/restart sickrage. | |
# | |
## The defaults | |
PKG_NAME="SickRage" | |
# Run as username | |
RUN_AS="sickrage" | |
# Path to app: SickBeard.py | |
APP_PATH="/opt/sickrage" | |
# Data directory where sickrage.db, cache and logs are stored | |
DATA_DIR="/opt/sickrage" | |
# Path to store PID file | |
PID_FILE="/var/run/sickrage/sickrage.pid" | |
# path to python bin | |
DAEMON="/usr/bin/python" | |
# Extra daemon option like: --config=/home/sickrage/config.ini" | |
EXTRA_DAEMON_OPTS="" | |
## | |
PID_PATH=`dirname $PID_FILE` | |
DAEMON_OPTS="SickBeard.py -q --daemon --nolaunch --pidfile=${PID_FILE} --datadir=${DATA_DIR} ${EXTRA_DAEMON_OPTS}" | |
## | |
test -x $DAEMON || exit 0 | |
set -e | |
# Create PID directory if not exist and ensure the sickrage user can write to it | |
if [ ! -d $PID_PATH ]; then | |
mkdir -p $PID_PATH | |
chown $RUN_AS $PID_PATH | |
fi | |
if [ ! -d $DATA_DIR ]; then | |
mkdir -p $DATA_DIR | |
chown $RUN_AS $DATA_DIR | |
fi | |
if [ -e $PID_FILE ]; then | |
PID=`cat $PID_FILE` | |
if ! kill -0 $PID > /dev/null 2>&1; then | |
echo "Removing stale $PID_FILE" | |
rm $PID_FILE | |
fi | |
fi | |
sickrage_start(){ | |
/bin/echo -n "Starting $PKG_NAME" | |
sudo -u sickrage bash -c "$DAEMON $APP_PATH/$DAEMON_OPTS" | |
/bin/echo " Done ($(/bin/date))" | |
} | |
sickrage_stop(){ | |
if [ -f $PID_FILE ]; then | |
#grab pid from pid file | |
Pid=$(/bin/cat $PID_FILE) | |
i=0 | |
/bin/kill $Pid | |
/bin/echo -n " Waiting for ${PKG_NAME} to shut down: " | |
while [ -d /proc/$Pid ]; do | |
sleep 1 | |
let i+=1 | |
/bin/echo -n "$i, " | |
if [ $i = 45 ]; then | |
/bin/echo -n " Tired of waiting, killing ${PKG_NAME} now" | |
/bin/kill -9 $Pid | |
/bin/rm -f $PID_FILE | |
/bin/echo " Done ($(/bin/date))" | |
exit 1 | |
fi | |
done | |
/bin/rm -f $PID_FILE | |
/bin/echo "Done ($(/bin/date))" | |
else | |
/bin/echo "${PKG_NAME} is not running? ($(/bin/date))" | |
fi | |
} | |
sickrage_status() { #Is the PKG already running? if so, exit the script | |
if [ -f $PID_FILE ]; then | |
#grab pid from pid file | |
Pid=$(/bin/cat $PID_FILE) | |
if [ -d /proc/$Pid ]; then | |
/bin/echo " $PKG_NAME is already running" | |
exit 1 | |
fi | |
fi | |
#ok, we survived so the PKG should not be running | |
} | |
case "$1" in | |
'start') | |
/bin/echo "$PKG_NAME prestartup checks... ($(/bin/date))" | |
sickrage_status #Check if the PKG is not running, else exit | |
sickrage_start #Start the PKG... (finaly ;) ) | |
;; | |
'stop') | |
/bin/echo "Shutting down ${PKG_NAME} at $(/bin/date)... " | |
sickrage_stop | |
;; | |
'restart') | |
echo "Restarting $PKG_NAME" | |
$0 stop | |
$0 start | |
;; | |
*) | |
echo "Usage: $0 start|stop|restart" | |
esac | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment