fixes for aur/sabnzbd

This commit is contained in:
Kevin Mihelich 2011-10-23 15:30:03 -04:00
parent a48b483015
commit 2b5c100245
7 changed files with 97 additions and 82 deletions

View file

@ -1,54 +1,50 @@
plugrel=1
pkgname=sabnzbd
_pkgname=SABnzbd
pkgver=0.6.10
pkgrel=1
pkgdesc="A web-interface based binary newsgrabber with NZB file support"
arch=(arm armv7h)
url="http://www.sabnzbd.org/"
license=('GPL')
depends=('par2cmdline' 'python2' 'python-cheetah' 'python-feedparser' 'python-yenc' 'python2-pyopenssl' 'unrar' 'unzip' 'sqlite3' 'curl')
install=sabnzbd.install
backup=('etc/conf.d/sabnzbd' 'opt/sabnzbd/sabnzbd.ini')
source=("http://downloads.sourceforge.net/sabnzbdplus/SABnzbd-$pkgver-src.tar.gz"
sabnzbd sabnzbd.init sabnzbd.confd sabnzbd.desktop x-nzb.xml nzb-2.png sab2_64.png addnzb.sh)
url="http://www.sabnzbd.org"
arch=("any")
license=("GPL")
depends=("curl" "par2cmdline"
"python2" "python2-cheetah" "python2-feedparser" "python2-pyopenssl" "python2-yenc"
"sqlite3" "unrar" "unzip")
install="${pkgname}.install"
backup=("etc/conf.d/${pkgname}" "opt/${pkgname}/${pkgname}.ini")
source=("http://downloads.sourceforge.net/sabnzbdplus/${_pkgname}-${pkgver}-src.tar.gz"
"${pkgname}" "${pkgname}.confd" "${pkgname}.init" "${pkgname}.desktop"
"addnzb.sh" "nzb-2.png" "sab2_64.png" "x-nzb.xml")
md5sums=("4ade5eef10fa652bb96cb53e6864063c"
"48d60a1c626503c7fef1bc5374390513"
"014c37c32114806191cce361e16862fa"
"d1d545b67ddea706e607db52c90c4ccd"
"f9bd5485072714b11f8c30a28024dc4d"
"c0d52ba8d47f731790cd717fde46b829"
"2a49c07b1e3e6448eabe92644315f983"
"fdc878dd0f6f25617e627b04409abbbd"
"11fb2cd1451e3725b08bfc2bd045be54")
md5sums=('d11d0805b5f1febc8c775f8baf0fb180'
'f45907d98a19052eaeb7ad98ff13b16d'
'2cd5c68bedc609dcff49871e0c94df54'
'dc5fdcc132033b38e2f34d2355d573be'
'503f31869e13ed19288175596e8114c9'
'11fb2cd1451e3725b08bfc2bd045be54'
'2a49c07b1e3e6448eabe92644315f983'
'fdc878dd0f6f25617e627b04409abbbd'
'65d60b1b2209138e0825a8e7b1abdcdd')
package() {
mkdir -p "${pkgdir}/opt/${pkgname}"
touch "${pkgdir}/opt/${pkgname}/${pkgname}.ini"
cp -rv "${srcdir}/${_pkgname}-${pkgver}/"* "${pkgdir}/opt/${pkgname}"
build() {
mkdir -p $startdir/pkg/opt/sabnzbd
touch $startdir/pkg/opt/sabnzbd/sabnzbd.ini
mv -v $startdir/src/SABnzbd-$pkgver/* $startdir/pkg/opt/sabnzbd/
find $startdir/pkg/opt/sabnzbd -type d -exec chmod 755 {} \;
find $startdir/pkg/opt/sabnzbd -type f -exec chmod 644 {} \;
chmod 755 $startdir/pkg/opt/sabnzbd/SABnzbd.py
chmod 755 $startdir/pkg/opt/sabnzbd/Sample-PostProc.sh
install -D -m755 $startdir/sabnzbd $startdir/pkg/usr/bin/sabnzbd
install -D -m755 $startdir/sabnzbd.init $startdir/pkg/etc/rc.d/sabnzbd
install -D -m644 $startdir/sabnzbd.confd $startdir/pkg/etc/conf.d/sabnzbd
install -D -m755 $startdir/sabnzbd.desktop $startdir/pkg/usr/share/applications/sabnzbd.desktop
install -D -m755 $startdir/nzb-2.png $startdir/pkg/opt/sabnzbd/nzb-2.png
install -D -m755 $startdir/sab2_64.png $startdir/pkg/opt/sabnzbd/sab2_64.png
install -D -m755 $startdir/addnzb.sh $startdir/pkg/opt/sabnzbd/addnzb.sh
install -D -m770 $startdir/x-nzb.xml $startdir/pkg/opt/sabnzbd/x-nzb.xml
# Fix for issues with Python 3
find "${pkgdir}/opt/${pkgname}" -type f -exec sed -i 's/python/python2/g' {} \;
find "${pkgdir}/opt/${pkgname}" -type d -exec chmod 755 {} \;
find "${pkgdir}/opt/${pkgname}" -type f -exec chmod 644 {} \;
chmod 755 "${pkgdir}/opt/${pkgname}/${_pkgname}.py"
chmod 755 "${pkgdir}/opt/${pkgname}/Sample-PostProc.sh"
# Fix for issues with Python 3
find $startdir/pkg/opt/sabnzbd -type f -exec sed -i 's/python/python2/g' {} \;
install -Dm755 "${srcdir}/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
install -Dm755 "${srcdir}/${pkgname}.init" "${pkgdir}/etc/rc.d/${pkgname}"
install -Dm644 "${srcdir}/${pkgname}.confd" "${pkgdir}/etc/conf.d/${pkgname}"
install -Dm755 "${srcdir}/${pkgname}.desktop" \
"${pkgdir}/usr/share/applications/${pkgname}.desktop"
install -Dm755 "${srcdir}/addnzb.sh" "${pkgdir}/opt/${pkgname}/addnzb.sh"
install -Dm644 "${srcdir}/nzb-2.png" "${pkgdir}/opt/${pkgname}/nzb-2.png"
install -Dm644 "${srcdir}/sab2_64.png" "${pkgdir}/opt/${pkgname}/sab2_64.png"
install -Dm770 "${srcdir}/x-nzb.xml" "${pkgdir}/opt/${pkgname}/x-nzb.xml"
}
md5sums=('4ade5eef10fa652bb96cb53e6864063c'
'f45907d98a19052eaeb7ad98ff13b16d'
'2cd5c68bedc609dcff49871e0c94df54'
'dc5fdcc132033b38e2f34d2355d573be'
'503f31869e13ed19288175596e8114c9'
'11fb2cd1451e3725b08bfc2bd045be54'
'2a49c07b1e3e6448eabe92644315f983'
'fdc878dd0f6f25617e627b04409abbbd'
'65d60b1b2209138e0825a8e7b1abdcdd')

View file

@ -1,13 +1,14 @@
#!/bin/bash
set -a # export all variables
. /etc/conf.d/sabnzbd
# SABnzbd must be able to read the file, so we copy it to a directory where it
# certainly has rights.
nzbname=`basename "$1"`
nzbname=$(basename "$1")
TEMP_NZB="/var/tmp/$nzbname"
cp "$1" $TEMP_NZB
curl -f "$SABNZBD_PROTOCOL://$SABNZBD_USPW$SABNZBD_IP:$SABNZBD_PORT/sabnzbd/api?mode=addlocalfile&name=$TEMP_NZB&pp=1&priority=-1&apikey=$SABNZBD_KEY"
rm $TEMP_NZB
curl -s $(python2 -c 'import urlparse,urllib,sys; print sys.argv[1] if urlparse.urlparse(sys.argv[1]).scheme else urlparse.urlparse(urllib.pathname2url(sys.argv[1]),"file").geturl()' "$1") -o "$TEMP_NZB"
curl -f $(python2 -c 'import urllib,os; print os.environ["SABNZBD_PROTOCOL"]+"://"+urllib.quote(os.environ["SABNZBD_USPW"]+os.environ["SABNZBD_IP"])+":"+os.environ["SABNZBD_PORT"]+"/sabnzbd/api?mode=addlocalfile&name="+urllib.quote(os.environ["TEMP_NZB"])+"&apikey="+urllib.quote(os.environ["NZB_KEY"])')
rm "$TEMP_NZB"
exit 0

View file

@ -1,3 +1,3 @@
#!/bin/sh
python /opt/sabnzbd/SABnzbd.py -f $HOME/.sabnzbd.ini "$@"
python2 /opt/sabnzbd/SABnzbd.py -f ${HOME}/.sabnzbd.ini "${@}"

View file

@ -1,16 +1,18 @@
SABNZBD_USER="sabnzbd"
SABNZBD_CONF="/opt/sabnzbd/sabnzbd.ini"
# Put the session key from Config > General here
SABNZBD_KEY=""
# Set to the protocol, IP and port
SABNZBD_PROTOCOL="http"
SABNZBD_IP="127.0.0.1"
SABNZBD_PORT="8080"
# Set your default user/group, startarguments and your configfile
SABNZBD_USER="sabnzbd"
SABNZBD_GROUP="sabnzbd"
SABNZBD_CONF="/opt/sabnzbd/sabnzbd.ini"
SABNZBD_ARGS="-f ${SABNZBD_CONF} -s ${SABNZBD_IP}:${SABNZBD_PORT} -d"
# Put the session keys from Config > General here
SABNZBD_KEY=""
NZB_KEY=""
# If you use a username and password, change the following variable to
# "user:pass@"
SABNZBD_USPW=""

View file

@ -4,7 +4,7 @@ Version=1.0
Name=SABnzbd+
GenericName=Binary Newsreader
Icon=/opt/sabnzbd/sab2_64.png
Exec=sh /opt/sabnzbd/addnzb.sh "%u"
Exec=sh /opt/sabnzbd/addnzb.sh %u
Terminal=false
Categories=Network
MimeType=application/x-nzb

View file

@ -4,40 +4,40 @@
. /etc/rc.d/functions
. /etc/conf.d/sabnzbd
case "$1" in
case "${1}" in
start)
stat_busy "Starting SABnzbd"
if [ -f /var/run/daemons/sabnzbd ]; then
echo -n "Sabnzbd is already running as a daemon! If you are certain it is not running, remove /var/run/daemons/sabnzbd."
stat_fail
echo -n "Sabnzbd is already running as a daemon! If you are certain it is not running, remove /var/run/daemons/sabnzbd."
stat_fail
else
su - $SABNZBD_USER -c "python2 /opt/sabnzbd/SABnzbd.py -f $SABNZBD_CONF -s $SABNZBD_IP:$SABNZBD_PORT -d" -s /bin/sh
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon sabnzbd
stat_done
fi
su - "${SABNZBD_USER}" -c "python2 /opt/sabnzbd/SABnzbd.py ${SABNZBD_ARGS}" -s /bin/sh
if [ "${?}" -gt 0 ]; then
stat_fail
else
add_daemon sabnzbd
stat_done
fi
fi
;;
stop)
stat_busy "Stopping SABnzbd"
curl -f "$SABNZBD_PROTOCOL://$SABNZBD_USPW$SABNZBD_IP:$SABNZBD_PORT/sabnzbd/api?mode=shutdown&apikey=$SABNZBD_KEY" &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
curl -f "${SABNZBD_PROTOCOL}://${SABNZBD_USPW}${SABNZBD_IP}:${SABNZBD_PORT}/sabnzbd/api?mode=shutdown&apikey=${SABNZBD_KEY}" &> /dev/null
if [ "${?}" -gt 0 ]; then
stat_fail
else
rm_daemon sabnzbd
stat_done
rm_daemon sabnzbd
stat_done
fi
;;
restart)
$0 stop
"${0}" stop
sleep 1
$0 start
"${0}" start
;;
*)
echo "usage: $0 {start|stop|restart}"
echo "usage: ${0} {start|stop|restart}"
esac
exit 0

View file

@ -1,25 +1,41 @@
## arg 1: the new package version
post_install() {
post_install() {
# add x-nzb mimetype
xdg-mime install --mode system /opt/sabnzbd/x-nzb.xml
xdg-icon-resource install --context mimetypes --size 64 /opt/sabnzbd/nzb-2.png application-x-nzb
groupadd sabnzbd &> /dev/null
useradd -g sabnzbd -d /opt/sabnzbd -s /bin/false sabnzbd &> /dev/null
chown -R sabnzbd:sabnzbd /opt/sabnzbd
echo " >> Don't forget to edit /etc/conf.d/sabnzbd!"
echo " >> Add your Session key and if necessary your username and password to ensure a proper shutdown."
echo " >> "
echo " >> If you want to associate .nzb-files with SABnzbd, run 'xdg-mime default sabnzbd.desktop applications/x-nzb'"
}
## arg 1: the new package version
## arg 2: the old package version
post_upgrade() {
chown -R sabnzbd:sabnzbd /opt/sabnzbd
. /etc/conf.d/sabnzbd
grep -q "SABNZBD_GROUP" /etc/conf.d/sabnzbd || echo 'SABNZBD_GROUP="sabnzbd"' >> /etc/conf.d/sabnzbd
grep -q "SABNZBD_ARGS" /etc/conf.d/sabnzbd || echo 'SABNZBD_ARGS="-f ${SABNZBD_CONF} -s ${SABNZBD_IP}:${SABNZBD_PORT} -d"' >> /etc/conf.d/sabnzbd
chown -R "${SABNZBD_USER}:${SABNZBD_GROUP}" /opt/sabnzbd
}
## arg 1: the old package version
pre_remove() {
SABNZBD_PID="$(ps aux | grep "python2 /opt/sabnzbd/SABnzbd.py" | sort | uniq -c | tail -n 1 | awk '{ print $3 }')"
[ -f /run/daemons/sabnzbd ]; /etc/rc.d/sabnzbd stop # kill the daemon
[ -n ${SABNZBD_PID} ]; kill -9 "${SABNZBD_PID}" # kill the daemon finaly
xdg-mime uninstall --mode system /opt/sabnzbd/x-nzb.xml
xdg-icon-resource uninstall --context mimetypes --size 64 application-x-nzb
}
post_remove() {
userdel sabnzbd &> /dev/null
}
groupdel sabnzbd &> /dev/null
echo " >> There may be some files left in /opt/sabnzbd."
}