Debian (Lenny/any) install script
Posted: January 2nd, 2011, 2:08 am
As root:
# cut and paste this in to a file (Eg. /root/setup_sabnzbd.sh )
# set execute privs: chmod 744 /root/setup_sabnzbd.sh
# run it: /root/setup_sabnzbd.sh
It will (should) automatically download the latest version and install it
...With luck you now have sab installed and running
Feel free to change PORT and PORTS (port-Secure) to any values you wish (they must be different) -
both values must be in the range 1025-65535 (1-1024 can only be used by root - and for security we will not run as root)
You can also safely edit the CACHE and DESTination directories (if you care.)
This is NOT intended to be worthy of a POSTINST script - but it /does/ contain eveything you need to know to write one
Edit: s/unrar-free/unrar/ ... free version lacks certain features [see below]
# cut and paste this in to a file (Eg. /root/setup_sabnzbd.sh )
# set execute privs: chmod 744 /root/setup_sabnzbd.sh
# run it: /root/setup_sabnzbd.sh
It will (should) automatically download the latest version and install it
...With luck you now have sab installed and running
Feel free to change PORT and PORTS (port-Secure) to any values you wish (they must be different) -
both values must be in the range 1025-65535 (1-1024 can only be used by root - and for security we will not run as root)
You can also safely edit the CACHE and DESTination directories (if you care.)
This is NOT intended to be worthy of a POSTINST script - but it /does/ contain eveything you need to know to write one

Code: Select all
#!/bin/bash
PORT=5481
PORTS=5485
CACHE=/var/cache
DEST=/usr/share
PKG=`wget -q http://sabnzbd.org/download/ -O - | \
grep sourceforge\.net | grep Linux | \
sed 's/.*href=\"\(.*\)\".*/\1/'`
LCL=$CACHE/`echo $PKG | sed 's/.*\(SAB.*\.gz\).*/\1/'`
wget -q $PKG -O $LCL
( cd $DEST && tar -xzf $LCL )
DIR=`ls -d $DEST/SABnzbd*`
mv $DIR $DEST/sabnzbd
apt-get install python2.5 python-cheetah python-yenc python-pyopenssl \
par2 unrar unzip sudo
adduser --disabled-login --gecos ,,,, --no-create-home sabnzbd
mkdir /home/sabnzbd
chown sabnzbd:sabnzbd /home/sabnzbd
sudo -u sabnzbd -H -- \
$DEST/sabnzbd/SABnzbd.py -b 0 -d -f /home/sabnzbd/.sabnzbd/sabnzbd.ini \
-s 0.0.0.0:$PORT --https $PORTS
APIKEY=
while [ x$APIKEY == x ]; do
APIKEY=`grep ^api_key /home/sabnzbd/.sabnzbd/sabnzbd.ini | \
sed 's/.*=\(.*\)/\1/' | sed 's/\ //g'`
echo -n "." ; sleep 1
done
echo ""
wget -q --delete-after \
"http://127.0.0.1:$PORT/sabnzbd/api?mode=shutdown&apikey=$APIKEY"
cat <<EOF >/etc/init.d/sabnzbd
#!/bin/bash
case "\$1" in
start)
echo "Starting SABnzbd."
/usr/bin/sudo -u sabnzbd -H -- \\
$DEST/sabnzbd/SABnzbd.py -b 0 -d \\
-f /home/sabnzbd/.sabnzbd/sabnzbd.ini
;;
stop)
echo "Shutting down SABnzbd."
PORT=`grep ^port\ /home/sabnzbd/.sabnzbd/sabnzbd.ini | \
sed 's/.*=\(.*\)/\1/' | sed 's/\ //g'`
APIKEY=`grep ^api_key /home/sabnzbd/.sabnzbd/sabnzbd.ini | \
sed 's/.*=\(.*\)/\1/' | sed 's/\ //g'`
/usr/bin/wget -q --delete-after \\
"http://127.0.0.1:\$PORT/sabnzbd/api?mode=shutdown&apikey=\$APIKEY"
;;
*)
echo "Usage: \$0 {start|stop}"
exit 1
esac
exit 0
EOF
chmod 755 /etc/init.d/sabnzbd
ln -s -f /etc/init.d/sabnzbd /etc/rcS.d/S60sabnzbd
/etc/init.d/sabnzbd start
echo -e "\nSAB can now be found at http://127.0.0.1:$PORT or https://127.0.0.1:$PORTS"