#!/bin/ksh
#Copy a file to the ~/public_html directory so it can be seen
#on the web. Sample use: post filename.html
if [[ $# -ne 1 ]]
then
echo $0: requires exactly one argument
exit
fi
if [[ ! -f $1 ]]
then
echo $0: there is no file named $1
exit
fi
if [[ ! -r $1 ]]
then
echo $0: you must have r permission for the file $1
exit
fi
if [[ ! -d ~/public_html ]]
then
echo $0: there is no directory named ~/public_html
exit
fi
#$newfilename is the full pathname of the copy we will create in ~/public_html.
newfilename=~/public_html/${1##*/} #Handout 4, pp. 3-4 for ##
if [[ -e $newfilename ]]
then
echo $0: $newfilename already exists and I will not harm it
exit
fi
chmod u+w ~/public_html #Give cp permission to copy the file into ~/public_html.
cp $1 $newfilename
chmod 444 $newfilename #r--r--r--
chmod a+rx ~ ~/public_html #Turn on all three r's and all three x's.