#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib:/mod/usr/lib DAEMON=bftpd case "$1" in ""|load|start|restart) if [ ! -r "/mod/etc/conf/$DAEMON.cfg" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi . /mod/etc/conf/$DAEMON.cfg ;; esac start() { if [ ! -d "/var/run/bftpd" ]; then mkdir /var/run/bftpd fi echo -n "Looking for user 'ftp'..." if cat /var/tmp/passwd | grep '^ftp:' > /dev/null; then echo 'ok.' else /usr/bin/modpasswd save echo 'ftp:*' >> /tmp/flash/shadow.save /usr/bin/modpasswd load echo 'added.' fi ( if [ -x "/tmp/flash/${DAEMON}_conf" ]; then /tmp/flash/${DAEMON}_conf else /mod/etc/default.$DAEMON/${DAEMON}_conf fi if [ -r "/tmp/flash/${DAEMON}.extra" ]; then cat /tmp/flash/${DAEMON}.extra fi ) > /mod/etc/$DAEMON.conf if [ ! -e "/var/tmp/ftp" ]; then ln -sf /mod/home/ftp /var/tmp/ftp fi echo -n 'Starting ftp server...' $DAEMON -d $BFTPD_OPTIONS exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop () { echo -n 'Stopping ftp server...' killall $DAEMON > /dev/null 2>&1 exitval=$? rm -f /mod/etc/$DAEMON.conf if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } case "$1" in ""|load) modreg cgi 'bftpd' 'Bftpd' if [ "$BFTPD_ENABLED" != "yes" ]; then echo "$DAEMON is disabled" 1>&2 exit 1; fi start ;; unload) stop modunreg cgi 'bftpd' ;; start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) if [ -z "$(pidof "$DAEMON")" ]; then echo 'stopped' else echo 'running' fi ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0