network/qbittorrent: Added qbittorrent-nox + an rc init script.

Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
This commit is contained in:
David Woodfall 2015-11-25 18:12:26 +07:00 committed by Willy Sudiarto Raharjo
parent c70dba9b05
commit 930330f992
4 changed files with 130 additions and 1 deletions

View file

@ -0,0 +1,17 @@
An rc init script is provided and has the following features:
Runs qbittorrent-nox webui under user who started the script.
Usage:
/etc/rc.d/rc.qbittorrent-nox start [PORT]|stop|restart [PORT]|status
Port defaults to 8080 if not provided.
To run this script from rc.local you must run it as a non-root user.
Example:
/bin/su - david -c /etc/rc.d/rc.qbittorrent-nox start 9000
Program output is sent to /tmp/qbittorrent-nox-$USER
The status command can be run as root, in which case you should see
all process of qbittorrent-nox, otherwise you will just see $USER's.

View file

@ -1,3 +1,18 @@
config() {
NEW="$1"
OLD="$(dirname $NEW)/$(basename $NEW .new)"
# If there's no config file by that name, mv it over:
if [ ! -r $OLD ]; then
mv $NEW $OLD
elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
# toss the redundant copy
rm $NEW
fi
# Otherwise, we leave the .new copy for the admin to consider...
}
config etc/rc.d/rc.qbittorrent-nox.new
if [ -x /usr/bin/update-desktop-database ]; then
/usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
fi

View file

@ -24,7 +24,7 @@
PRGNAM=qbittorrent
VERSION=${VERSION:-3.1.12}
BUILD=${BUILD:-1}
BUILD=${BUILD:-2}
TAG=${TAG:-_SBo}
if [ -z "$ARCH" ]; then
@ -77,16 +77,31 @@ CXXFLAGS="$SLKCFLAGS" \
make
make install INSTALL_ROOT=$PKG
make clean
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
--prefix=/usr \
--disable-gui
make
mv src/qbittorrent-nox $PKG/usr/bin
find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
mv $PKG/usr/share/man $PKG/usr
find $PKG/usr/man -type f -exec gzip -9 {} \;
for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
mkdir -p $PKG/etc/rc.d
cp $CWD/rc.qbittorrent-nox.new $PKG/etc/rc.d/.
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a AUTHORS Changelog NEWS TODO COPYING INSTALL README.md \
$CWD/README.nox \
$PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

View file

@ -0,0 +1,82 @@
#!/bin/sh
# /etc/rc.d/rc.qbittorrent-nox
# Runs qbittorrent webui under user who started the script.
# Usage: /etc/rc.d/rc.qbittorrent-nox start <PORT>|stop|restart <PORT>|status
# Port defaults to 8080 if not provided.
#
# To run this script from rc.local you must run it as a non-root user.
#
# Example:
# /bin/su - david -c /etc/rc.d/rc.qbittorrent-nox start 9000
# Program output is sent to /tmp/qbittorrent-nox-$USER
# First some checks to see what's what.
if [ "$USER" = "root" ] && [ "$1" = "start" ]; then
echo "Do not start the daemon as root." >/dev/stderr
exit 1
fi
if [ -n "$2" ]; then
UIPORT="$2"
else
UIPORT="8080"
fi
LOG="/tmp/qbittorrent-nox-$USER"
APP="/usr/bin/qbittorrent-nox"
do_start()
{
if [ -n "$(/bin/netstat -nta | awk '{print $4}' \
| cut -d: -f2 | grep $UIPORT | grep 0.0.0.0)" ]; then
echo "Port $UIPORT is already in use." >/dev/stderr
exit 1
fi
$APP --webui-port=$UIPORT 1>$LOG 2>&1 &
}
do_stop()
{
PID="$(pgrep -u $USER qbittorrent-nox)"
if [ -n "$PID" ]; then
echo "Killing PID $PID"
kill $PID
else
echo "No process found." >/dev/stderr
fi
}
do_status()
{
echo "Local Address Foreign Address State PID/Program name"
/bin/netstat -pntl 2>&1 | grep qbittorrent-n \
| awk '{print $4 " " $5 " " $6 " " $7}'
}
case "$1" in
'start')
do_start
;;
'stop')
do_stop
;;
'restart')
do_stop
sleep 1
do_start
;;
'status')
do_status
;;
*)
echo "Usage: $0 {start <PORT>|stop|restart <PORT>|status}" >/dev/stderr
exit 1
;;
esac