#!/bin/ash
#
#
#
 case "$1" in
 'add')
 echo "21 dgram udp nowait root fsp-server fsp-server -i -T /tmp -d /srv/fsp" > /etc/inetd/fsp.conf
 ;;
 'start')
 fspd add
 inetd
 ;;
 'remove')
 rm /etc/inetd/fsp.conf 2>/dev/null
 ;;
 'stop')
 fspd remove
 inetd
 ;;
 'restart')
 fspd start
 ;;
 'test')
 if [ ! -e /var/run/fspd.pid ]; then
   echo "Your FSP Server seems to be down."
   read -p "Do you wish to start it now (y/n)?: " CHOICE
   CHOICE=y$CHOICE
   if [ $CHOICE = yy ]; then
     fspd start
   fi
 fi
 echo "Testing port 21 at localhost:"
 fspscan -i 127.0.0.1 -p 21 -e 21
 echo ""
 echo "Trying to get a test file from localhost to the /tmp directory:"
 cd /tmp
 rm -f test.file
 gftp-text -d fsp://localhost/test.file
 echo ""
 if [ -s /tmp/test.file ]; then
   echo "It works :)"
   else
   echo "It doesn't work :("
 fi
 ;;
 'help')
 echo "fspd start --> start FSP server"
 echo "fspd stop --> stop FSP server"
 echo "fspd restart --> restart FSP server"
 echo "fspd test --> test FSP server"
 ;;
 *)
 echo "Usage:"
 fspd help
 ;;
 esac