Last active
August 29, 2015 14:01
-
-
Save zackbcom/5fbf02aec8ce3393f67c to your computer and use it in GitHub Desktop.
Install CouchPotato 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 | |
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 couchpotato | |
sudo git clone git://github.com/RuudBurger/CouchPotatoServer.git /opt/couchpotato | |
sudo chown -R couchpotato:couchpotato /opt/couchpotato | |
touch /etc/rc.d/rc.couchpotato | |
chmod +x /etc/rc.d/rc.couchpotato | |
#Add rc.couchpotato | |
cat <<'EOF' > /etc/rc.d/rc.couchpotato | |
#!/bin/sh | |
# Start/stop/restart couchpotato. | |
# | |
## The defaults | |
PKG_NAME="couchpotato" | |
# Run as username | |
RUN_AS="couchpotato" | |
# Path to app: CouchPotato.py | |
APP_PATH="/opt/couchpotato" | |
# Data directory where couchpotato.db, cache and logs are stored | |
DATA_DIR="/opt/couchpotato" | |
# Path to store PID file | |
PID_FILE="/var/run/couchpotato/couchpotato.pid" | |
# path to python bin | |
DAEMON="/usr/bin/python" | |
CFG_FILE="${APP_PATH}/settings.conf" | |
PID_PATH=`dirname $PID_FILE` | |
DAEMON_OPTS="CouchPotato.py --daemon --data_dir $DATA_DIR --pid_file ${PID_FILE} --config ${CFG_FILE}" | |
test -x $DAEMON || exit 0 | |
set -e | |
# Create PID directory if not exist and ensure the couchpotato 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 | |
couchpotato_start(){ | |
/bin/echo -n "Starting $PKG_NAME" | |
sudo -u $RUN_AS bash -c "$DAEMON $APP_PATH/$DAEMON_OPTS" | |
/bin/echo " Done ($(/bin/date))" | |
} | |
couchpotato_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 | |
} | |
couchpotato_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))" | |
couchpotato_status #Check if the PKG is not running, else exit | |
couchpotato_start #Start the PKG... (finaly ;) ) | |
;; | |
'stop') | |
/bin/echo "Shutting down ${PKG_NAME} at $(/bin/date)... " | |
couchpotato_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