#!/bin/ksh #Copy files to the ~/public_html directory so they can be seen on the web. #Sample use: post filename1 filename2 filename3 #If no arguments, store the standard input into a file named #~/public_html/junk, overwriting it if it already exists. chmod a+rx ~ #Turn on all of the home directory's r and x bits; Handout 3 p. 16 if [[ ! -d ~/public_html ]] #If there is no directory named ~/public_html, then if [[ -e ~/public_html ]] then echo $0: will not create the ~/public_html directory, 1>&2 echo because something with that name already exists 1>&2 exit 1 fi chmod u+w ~ #Turn on the home directory's leftmost w bit for the mkdir. mkdir ~/public_html fi #Now that we know that the ~/public_html directory exists, #make sure that it's chmod'd correctly. chmod a+rx ~/public_html #Turn on "all" three r's and x's. chmod u+w ~/public_html #Turn on the public_html directory's leftmost w bit. if [[ $# -eq 0 ]] then cd ~/public_html rm -f junk #-f for "force": remove it even if it's write protected cat > junk #Cat the shellscript's standard input into a file. chmod 444 junk #r--r--r-- else for filename in $* #The "in $*" is optional: pp. 144-145. do if [[ ! -f $filename ]] then echo $0: there is no file named $filename 1>&2 exit 2 fi if [[ ! -r $filename ]] then echo $0: have no permission to copy $filename 1>&2 exit 3 fi basename=${filename##*/} #Handout 4, p. 3. if [[ -e ~/public_html/$basename ]] then echo $0: ~/public_html/$basename already exists 1>&2 exit 4 fi cp $filename ~/public_html chmod 444 ~/public_html/$basename done fi exit 0