#!/bin/ash
#
#
#
 . /etc/server/daemon.conf
 if [ $FTPD = vsftpd ]; then
   mkdir /usr/share/empty 2>/dev/null
   adduser -D -H nobody 2>/dev/null
   adduser -D -h /srv/ftp ftp 2>/dev/null
   chown root:root /srv/ftp
   chmod og-w /srv/ftp
   chown root:root /etc/vsftpd/vsftpd.conf
   INETD=vsftpd
   else
   INETD="/usr/share/busybox/busybox ftpd /srv/ftp"
 fi
#
#
#
 case "$1" in
 'add')
 echo "21 stream tcp nowait root $INETD" > /etc/inetd/ftp.conf
 ;;
 'start')
 ftpd add
 inetd
 ;;
 'remove')
 rm /etc/inetd/ftp.conf 2>/dev/null
 ;;
 'stop')
 ftpd remove
 inetd
 ;;
 'restart')
 ftpd start
 ;;
 'test')
 if [ ! -e /etc/inetd/ftp.conf ]; then
   echo "Your FTP Server seems to be down."
   read -p "Do you wish to start it now (y/n)?: " CHOICE
   CHOICE=y$CHOICE
   if [ $CHOICE = yy ]; then
     ftpd start
   fi
 fi
 links ftp://localhost
 ;;
 'help')
 echo "ftpd start --> start FTP server"
 echo "ftpd stop --> stop FTP server"
 echo "ftpd restart --> restart FTP server"
 echo "ftpd test --> test FTP server"
 ;;
 *)
 echo "Usage:"
 ftpd help
 ;;
 esac