# Description
#   This script was written to simplify the process of creating an ftp
#   'guest' user on Debian Linux running wu-ftp. The process is not entirely
#   straightforward because the 'guest' has to be locked into his or her
#   home directory, and also has to have certain utilities (such as 'ls') in
#   that home directory in order to be able to do directory listings. 
#
#   In addition the system utilities such as 'ls' need to be of a certain type.
#   This is called something like 'static linked library'. The reason for this
#   appears to be that the utility is not allowed to use any library files outside
#   of the guests home directory (since that would be breaking the ftp 'jail' or
#   'chroot').
#
#   However, now that we are using Redhat Linux and proftpd this script is no
#   longer particularly relevant (except for the 'barcelona' server). Making a 
#   'guest' account for proftpd is much easier. All you have to do is create the 
#   user (using a command such as 'adduser' or 'useradd') and then modify the 
#   main proftpd configuration file (I forget what its called) in order to 
#   keep the guests in their home directories.
#
#   I have added an 'exit' line below in order to stop this script being 
#   accidentally used.

if [ "$1" = "" ]
then
  echo "
    usage make-ftp-guest username
  
    This script performs the operations necesssary to set up a
    guest ftp account. However, it is still necessary at the moment
    to set the password for the guest ftp user with the 
    passwd command, after this script has run

    It probably also should make a change to the /etc/wu-ftpd/ftpaccess
    file, by adding some line such as:
      Class	ftpext	guest	vanessa,	nick
    although I believe that the syntax of this line is not correct.
    In addition, the 'guest ftp' HOWTO document which is located at
      http://www.wu-ftpd.org/
    mentioned alternative ways of setting up 'guest ftp access'
     "
  exit 1;
fi

# Comment out the line below to use this script
# (This should only be used with wu-ftpd not proftpd)
exit 1;

newUserName=$1
#-- newUserName=$1 && (echo "usage: ./make-ftp-guest.sh username"; exit 1)
adduser --shell /etc/ftponly --ingroup lusers --gecos $newUserName --disabled-login $newUserName
cp /etc/passwd /etc/passwd.old
cat /etc/passwd.old | sed "s/home\/$newUserName/&\/\.\//g" > /etc/passwd
cp -r -p /var/guest-ftp-setup/* /home/$newUserName/
echo "
  Now you can set the password manually with the command:

  passwd $newUserName 

  Once you have set the password for this user, you (or the user)
  will be able to login to the ftp server at
    www.ella-associates.org
  using the user-name and password which have just been established.

  If you would like to remove the user who has been created with this
  script, you can type the command

  deluser --remove-home $newUserName "

