#!/bin/sh
umask 0000
#################################################################################
#
# Copyright (C) 2008 Christian Schmitz (itzy)
#
# Starts or stops the webtransmission daemons.
#
#
#################################################################################
#
# Set BASEDIR to match your setup
# Where is trandmissiondcgi etc.?
# if you start transmission via autostart, you must set the absolute path here (NOT $(pwd))
BASEDIR="$(pwd)"
# The file webtransmission log its output into
# this is internally set to webtransmission.log regardless what you change here
# but it might be something is outputed by the system, so the best is to leave this unchanged
LOG="$BASEDIR/webtransmission.log"
# -v0 : only log errors
# -v1 : show also some info-msg
# -v2 : display some more debug-output
# -v3 : display every possible output (if crashes happen, set to -v3 and post logoutput)
DEBUGLEVEL="-v3"
# Set to 0 have webtransmission available via the AVM webserber (default port: 80)
# Set to 1 have webtransmission available via the FREETZ webserber (default port: 81)
# Set to 2 to have both
ENABLE_FREETZ=0
# Some misc conf options below here, generally you do not need to change them
##### PROXY #####
# change to '--proxyaddress ADDRESS', e.g. '--proxyaddress 127.0.0.1'
# must be set for proxy to work. to see whether proxy is enabled, check log for 'proxy enabled'
PROXYADDRESS=""
# change to '--proxyport PORT', e.g. '--proxyport 80'
# optional, default port 80
PROXYPORT=""
# change to '--proxytype [http:socks4:socks5]', e.g. '--proxytype socks4'
# optional, default http
PROXYTYPE=""
#################################################################################
init(){
# Create needed directories, files and links if not existent
DIRS="$BASEDIR/upload/_completed
$BASEDIR/config"
for DIR in $DIRS; do
mkdir -p "$DIR"
done
[ ! -d /var/tmp/webtransmission ] && mkdir /var/tmp/webtransmission
ln -sf "$BASEDIR/upload" /var/tmp/webtransmission/
#mkdir -p $(dirname "$LOG")
if [ $ENABLE_FREETZ -ge 1 ]; then
/mod/etc/init.d/rc.webcfg stop
DOCROOT=/usr/mww
# Remove old mounts
while mount | grep -q $DOCROOT; do
umount $DOCROOT > /dev/null 2>&1;
if [ ! $? -eq 0 ]; then echo "Could not umount $DOCROOT, this won't work!"; break; fi
done
# Clean target wwwdir
rm -rf /var/tmp/wwwdir
# Copy / Link existing wwwroot into new location
cp -rf $DOCROOT /var/tmp/wwwdir
# Add webtransmission's additional CGIs and site templates
ln -sf "$BASEDIR/wwwroot" /var/tmp/wwwdir/webtransmission
ln -sf "$BASEDIR/transmissiondcgi" /var/tmp/wwwdir/cgi-bin/
ln -sf ../webtransmission/tmpl /var/tmp/wwwdir/cgi-bin/tmpl
mount -o bind /var/tmp/wwwdir $DOCROOT/
ln -fs /usr/share /var/tmp
/mod/etc/init.d/rc.webcfg start
fi
if [ $ENABLE_FREETZ -eq 0 ] || [ $ENABLE_FREETZ -gt 1 ]; then
# Copy / Link existing wwwroot into new location
DOCROOT=/usr/www/1und1
# Remove old mounts
while mount | grep -q $DOCROOT; do
umount $DOCROOT > /dev/null 2>&1;
if [ ! $? -eq 0 ]; then echo "Could not umount $DOCROOT, this won't work!"; break; fi
done
# Clean target wwwdir
rm -rf /var/tmp/wwwdir_avm
# Copy / Link existing wwwroot into new location
cp -rf $DOCROOT /var/tmp/wwwdir_avm
# Add webtransmission's additional CGIs and site templates
ln -sf "$BASEDIR/wwwroot" /var/tmp/wwwdir_avm/webtransmission
ln -sf "$BASEDIR/transmissiondcgi" /var/tmp/wwwdir_avm/cgi-bin/
[ -f "$BASEDIR/wwwroot/css/freetz_style.css" ] &&
ln -sf "$BASEDIR/wwwroot/css/freetz_style.css" /var/tmp/wwwdir_avm/style.css
ln -sf /var/tmp/wwwdir_avm/webtransmission/tmpl /var/tmp/wwwdir_avm/cgi-bin/tmpl
mount -o bind /var/tmp/wwwdir_avm $DOCROOT/
fi
}
case "$1" in
start)
if "$0" status > /dev/null; then
echo "Webtransmission is already running"
exit 1
else
if [ ! -d "$BASEDIR" ]; then
echo "BASEDIR is not properly set. Please edit $0 to match your setup"
exit 1
fi
echo "Starting webtransmission..."
init
OLDDIR="$(pwd)"
NICE="$(which nice)"
cd "$BASEDIR" # transmissiond must be adapted in order to skip this
HOME="$BASEDIR" "$BASEDIR/transmissiond" $DEBUGLEVEL $PROXYADDRESS $PROXYPORT $PROXYTYPE >> "$LOG" 2>&1 &
exitval=$?
cd "$OLDDIR"
if [ "$exitval" -eq 0 ]; then
echo "Webtransmission started."
else
echo "Webtransmission failed."
exit $exitval
fi
fi
;;
stop)
if "$0" status > /dev/null; then
echo -n "Stopping webtransmission..."
"$BASEDIR/transmissiondc" die >> "$LOG" 2>&1
exitval=$?
if [ "$exitval" -eq 0 ]; then
echo 'done.'
else
killall -9 transmissiond > /dev/null 2>&1
echo "failed."
exit $exitval
fi
# Remove old mounts
while mount | grep -q /usr/mww; do
/mod/etc/init.d/rc.webcfg status | grep -q running &&
/mod/etc/init.d/rc.webcfg stop
umount /usr/mww > /dev/null 2>&1;
if [ ! $? -eq 0 ]; then echo "Could not umount /usr/mww"; break; fi
/mod/etc/init.d/rc.webcfg status | grep -q stopped &&
/mod/etc/init.d/rc.webcfg start
done
while mount | grep -q /usr/www/all; do
umount /usr/www/all > /dev/null 2>&1;
if [ ! $? -eq 0 ]; then echo "Could not umount /usr/www/all"; break; fi
done
else
echo "Webtransmission is not running"
exit 1
fi
;;
status)
"$BASEDIR/transmissiondc" status > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
echo "Webtransmission is running"
exit 0
else
echo "Webtransmission is not running"
exit 1
fi
;;
init)
init
;;
*)
echo "Usage: $0 {start|stop|status}" >&2
exit 1
;;
esac
exit 0