update - a script to add content to a user's webpage

This is a script which takes several arguments. It is designed to copy a given file into a personal area on a website then update the user's own index file with a link to the newly added file. The script can handle plain text, html, PDF, office and various image file formats.

It relies on the structure of the SITE_ROOT directory to be in (something like) the following format:
SITE_ROOT ---+
             |
             |-- user1.html -- user1 --+
             |                         |--- htdocs 
             |                         |--- img
             |                         |--- office
             |                         |--- pdfs
             |
             |-- user2.html -- user2 --+
           ... etc ... etc ...

Then the script should be able to copy html files into the htdocs subdirectory; image files into img; Excel, Word, OpenOffice Writer (etc) documents into the office subdirectory; and PDFs into the pdfs directory (where else?)

#!/bin/ksh
#
# Update html list on the unix team website
#
# Check the server. Must be run on shadow
#
if [ `hostname` != "shadow" ]; then
   echo "Please run this script on shadow."
   exit
fi
#
# Set defaults for directories and paths
#
SITE_ROOT=/spare/home/unixweb/unix_site
CONTENT=content
PDF=pdfs
HTML=htdocs
IMG=img
OFFICE=office

#
# Usage note for the -h option and mistakes with other parameters
#
USAGE="This script can take lots of parameters. Sorry. \n \
Usage: $0: -h | -f filename [-u user] [-t type] [-l linkname] [-c comment] \n \
The only compulsory parameter is the -f filename option \n \
but you should consider including the -l linkname option to provide \n \
a descriptive title to the link. \n \
Defaults: user = \$LOGNAME \n \
          type(*) = text \n \
          linkname = Text File \n \
          comment = A UNIX Team document \n \
(*) type can be one of \n \
       pdf, html, text, txt, office, doc, xls, sxw, sxc or img \n \
If any parameters contain spaces, surround them with \"double quotes\""

#
# Set defaults for other parameters
#
user=$LOGNAME
type=text
linkname="Text File"
comment="A UNIX Team document"

#
# Parse the options
#
while getopts hu:t:f:l:c: r
do
    case $r in
       h) echo $USAGE; exit;;
       u) user=$OPTARG;;
       t) type=$OPTARG;;
       f) file=$OPTARG;;
       l) linkname=$OPTARG;;
       c) comment=$OPTARG;;
       *) echo $USAGE; exit;;
    esac
done

#echo username = $user
#echo file type = $type
#echo file name = $file
#echo comment = $comment
#echo link title = $linkname

#
# Ensure a filename has been specified
#
if [ ! $file ]; then
   echo "Please specify a file name"
   echo $USAGE
   exit
fi

#
# Determine target directory for copied file
# Content is arranged by file type in subdirectories of each user's 
# LOGNAME directory
case $type in
    pdf) copyto=${user}/${PDF};;
    html|text|txt) copyto=${user}/${HTML};;
    office|doc|xls|sxw|sxc) copyto=${user}/${OFFICE};;
    img) copyto=${user}/${IMG};;
esac

#
# Copy the file
#
echo copying file $file to $SITE_ROOT/$CONTENT/$copyto
cp $file $SITE_ROOT/$CONTENT/$copyto

#
# Edit the user's contents list
# USERLIST is the user's own $LOGNAME.html file
# NEWLINE is an item added to the list of documents they have already posted

USERLIST=${SITE_ROOT}/${CONTENT}/${user}.html
NEWLINE="< li > < a href=\"./${copyto}/${file}\">${linkname}</a> $comment ($type)"


echo adding $NEWLINE
echo to $USERLIST

ed $USERLIST < /dev/null
/<\/ol>
i
$NEWLINE
.
w
q
EOF