#!/bin/sh DAEMON=downloader DAEMON_CHECK=downloader . /etc/init.d/modlibrc ERRFILE=/var/tmp/downerr if [ "$DOWNLOADER_DEBUG" = "yes" ]; then LOGFILE=/var/log/downloader.log else LOGFILE=/dev/null fi start() { echo "Starting $DAEMON ..." [ -e $ERRFILE ] && rm -f $ERRFILE > /dev/null 2>&1 echo "$DOWNLOADER_FILES" | grep -v "^#" | while read -r downfile; do [ -n "$downfile" ] echo -n "Download: $downfile ... " downloader $downfile >> $LOGFILE 2>&1 errors=$? if [ "$errors" -eq 0 ]; then echo 'done.' else echo 'failed.' echo $ERRORVAL > $ERRFILE fi done if [ -e $ERRFILE ]; then rm $ERRFILE > /dev/null 2>&1 echo "Download failed." exit $ERRORVAL else echo "Download completed." fi } stop() { killall $DAEMON > /dev/null 2>&1 } remove() { [ -e $ERRFILE ] && rm -f $ERRFILE > /dev/null 2>&1 echo "$DAEMON: Remove all downloaded files ..." echo "$DOWNLOADER_FILES" | grep -v "^#" | while read -r downfile; do [ -n "$downfile" ] echo -n "Delete $downfile ... " downremover $downfile >> $LOGFILE 2>&1 errors=$? if [ "$errors" -eq 0 ]; then echo 'done.' else echo 'failed.' echo $ERRORVAL > $ERRFILE fi done if [ -e $ERRFILE ]; then rm $ERRFILE > /dev/null 2>&1 echo "Remove failed." exit $ERRORVAL else echo "Removing all downloaded files completed." fi } case $1 in ""|load) modreg cgi $DAEMON 'Downloader' modreg daemon $DAEMON modreg extra $DAEMON '$(lang de:"Heruntergeladene Dateien löschen" en:"Remove downloaded files")' 1 'downremover' modreg extra $DAEMON '$(lang de:"Protokoll ansehen" en:"View log file")' 1 'downlog' modlib_start $DOWNLOADER_ENABLED ;; unload) modunreg daemon $DAEMON modunreg cgi 'downloader' modunreg extra $DAEMON 'downremover' modunreg extra $DAEMON 'downlog' modlib_stop ;; start) modlib_start ;; stop) modlib_stop ;; restart) modlib_restart ;; remove) remove ;; status) modlib_status ;; *) echo "Usage: $0 [load|unload|start|stop|restart|remove|status]" 1>&2 exit 1 ;; esac exit 0