#! /bin/csh -f
######################################################################
# This csh script takes exactly one argument -- a file somewhere in 
# the staging dir -- and moves it to the HTML_DIR directory. The paths 
# to these dirs are set in the environment. 
# See the comments in 'makeweb' for details.
#
# Usage:
#	
#	% _install-html /fullpath/somefile.html
#
# where /fullpath/somefile.html is the full path name of an html file in 
# the staging area. You'd rarely run this script at the command level.
# Usually it's invoked only by 'makeweb'.
######################################################################

# Abort if the STAGE_DIR and HTML_DIR env variables aren't set 
set me=${0}
if (${?STAGE_DIR} && ${?HTML_DIR}) then
	set srcdir=$STAGE_DIR
	set destdir=$HTML_DIR
else
	echo ${me}: STAGE_DIR or HTML_DIR environment variable not set\!
	exit
endif

# Abort if this script isn't invoked with exactly one argument
if (${#argv} != 1) then
	echo ${me}: Expected 1 argument, got ${#argv}\!
	exit
endif

# Construct the destination (website) pathname for this .html file.
# For example, change
#		~/staging_area/somedir/anotherdir/somefile.html
# to
#		/foo/bar/website/somedir/anotherdir/somefile.html
set src=$1
set dest=`echo $src | sed "s%$srcdir%$destdir%"`

# Apply a time-stamp (revision date) to the file before moving it
htmlstamp -t _REV_DATE_START_ _REV_DATE_END_ $src

# If the file is in a new directory that doesn't exist yet in the 
# website directory, then create that directory.
if (! -e $dest:h) then
	echo "\t" Creating new directory: $dest:h
	mkdir -p $dest:h
	chmod a+rx $dest:h
endif
echo "\t" installing ${dest}.
touch $src   	# to give it today's date
mv $src $dest	# at last, the move!



