#!/bin/sh
#
# Synology DSM init script for SABnzbd
# Requires: sabnzbd 
#           python
#           wget 
# 
# Configured Variables: 
# 
PYTHON_EXEC="/opt/bin/python2.6"
SABNZBD_EXEC="/opt/share/sabnzbd/SABnzbd.py"
SABNZBD_PORT="9200"
SAB_API_KEY="ef1a2d46a63395268f01a12091f249ee"
SAB_INI_FILE="/volume2/Temp/sabnzbd/sab.ini"

# Begin script
#
case "$1" in
start)
  PATH=$PATH:/opt/bin
  printf "%-30s" "Starting SABnzbd"
  ${PYTHON_EXEC} ${SABNZBD_EXEC} -s 0.0.0.0:${SABNZBD_PORT} -f ${SAB_INI_FILE} -d
  printf "[%4s]\n" "done"
  ;;
stop)
  printf "%-30s" "Stopping SABnzbd"
  /opt/bin/wget -q --delete-after "http://127.0.0.1:${SABNZBD_PORT}/shutdown?session=${SAB_API_KEY}"
  printf "[%4s]\n" "done"
  ;;
*)
  echo "Usage: $0 {start|stop}"
  exit 1
esac
            
exit 0

