| 1 | #!/bin/sh
 | 
|---|
| 2 | # setup.anonftp - Anonymous FTP setup and maintenance.
 | 
|---|
| 3 | #
 | 
|---|
| 4 | # 01/22/96 Initial Release      Al Woodhul, <asw@hampshire.edu>
 | 
|---|
| 5 | # 01/25/96                      Michael Temari, <temari@ix.netcom.com>
 | 
|---|
| 6 | #
 | 
|---|
| 7 | 
 | 
|---|
| 8 | # What is needed for anon ftp
 | 
|---|
| 9 | 
 | 
|---|
| 10 | # ref: Hunt TCP/IP Net Admin pp. 338++
 | 
|---|
| 11 | # ref: Nemeth et al UNIX System Admin Handbook p. 295
 | 
|---|
| 12 | # ref: mail from M. Temari 18.01.96
 | 
|---|
| 13 | 
 | 
|---|
| 14 | # programs possibly used by ftpd
 | 
|---|
| 15 | PROGS="sh ls crc tar compress gzip"
 | 
|---|
| 16 | 
 | 
|---|
| 17 | echo Checking /etc/passwd
 | 
|---|
| 18 | if grep '^ftp:[^:]*:[1-9][0-9]*:[1-9][0-9]*:[^:]*:/[^:]*:[^:]*$' \
 | 
|---|
| 19 |                                                 /etc/passwd >/dev/null
 | 
|---|
| 20 | then
 | 
|---|
| 21 |   echo -n "OK, ftp entry found: "
 | 
|---|
| 22 |   grep '^ftp:' /etc/passwd
 | 
|---|
| 23 | else
 | 
|---|
| 24 |   echo "Found no entry for ftp in /etc/passwd, please add one with the"
 | 
|---|
| 25 |   echo "home directory pointing to the anonymous FTP directory"
 | 
|---|
| 26 |   exit 1
 | 
|---|
| 27 | fi
 | 
|---|
| 28 | 
 | 
|---|
| 29 | # ftp directory
 | 
|---|
| 30 | FTPDIR="`sed '/^ftp:/!d; s/^.*:\\([^:]*\\):[^:]*/\\1/' /etc/passwd`"
 | 
|---|
| 31 | 
 | 
|---|
| 32 | if [ `whoami` != root ]
 | 
|---|
| 33 | then
 | 
|---|
| 34 |   echo You must be root to do this
 | 
|---|
| 35 |   exit 1
 | 
|---|
| 36 | fi
 | 
|---|
| 37 | 
 | 
|---|
| 38 | echo Setting up for anonymous ftp
 | 
|---|
| 39 | 
 | 
|---|
| 40 | echo Making $FTPDIR and subdirectories
 | 
|---|
| 41 | install -d -m 755 -o root -g operator $FTPDIR
 | 
|---|
| 42 | install -d -m 751 -o root -g operator $FTPDIR/bin
 | 
|---|
| 43 | install -d -m 751 -o root -g operator $FTPDIR/dev
 | 
|---|
| 44 | install -d -m 751 -o root -g operator $FTPDIR/etc
 | 
|---|
| 45 | install -d -m 755 -o root -g operator $FTPDIR/pub
 | 
|---|
| 46 | incoming=
 | 
|---|
| 47 | if [ -d $FTPDIR/pub/incoming ]
 | 
|---|
| 48 | then
 | 
|---|
| 49 |         incoming=t
 | 
|---|
| 50 | elif [ -t 0 ]
 | 
|---|
| 51 | then
 | 
|---|
| 52 |         echo -n "Create \"incoming\" directory? [n] "; read yn
 | 
|---|
| 53 |         case "$yn" in
 | 
|---|
| 54 |         [yY]*|ok|sure)  incoming=t
 | 
|---|
| 55 |         esac
 | 
|---|
| 56 | fi
 | 
|---|
| 57 | test "$incoming" && install -d -m 777 -o root -g operator $FTPDIR/pub/incoming
 | 
|---|
| 58 | 
 | 
|---|
| 59 | echo Copying files
 | 
|---|
| 60 | for PROG in $PROGS
 | 
|---|
| 61 | do
 | 
|---|
| 62 |   test -f /usr/bin/$PROG && install -lcs /usr/bin/$PROG $FTPDIR/bin
 | 
|---|
| 63 | done
 | 
|---|
| 64 | cp -rp /dev/tcp $FTPDIR/dev/tcp
 | 
|---|
| 65 | install -lcs ftpdsh $FTPDIR/bin
 | 
|---|
| 66 | 
 | 
|---|
| 67 | echo Copying a minimum of the password and group files
 | 
|---|
| 68 | sed 's/^\([^:]*\):[^:]*:\([^:]*:[^:]*\):.*$/\1:*:\2:::/' \
 | 
|---|
| 69 |                                         /etc/passwd >$FTPDIR/etc/passwd
 | 
|---|
| 70 | sed 's/^\([^:]*\):[^:]*:\([^:]*\):.*$/\1:*:\2:/' \
 | 
|---|
| 71 |                                         /etc/group >$FTPDIR/etc/group
 | 
|---|
| 72 | chown root:operator $FTPDIR/etc/*
 | 
|---|
| 73 | chmod 444 $FTPDIR/etc/*
 | 
|---|
| 74 | 
 | 
|---|
| 75 | echo "Anonymous ftp setup complete"
 | 
|---|