#! /bin/csh -f
######################################################################
# To update the website, I first upload html files to a "staging" 
# directory, which has the same directory structure as the website. This
# allows me to upload files and double-check that I've put them in the right
# dirs before actually moving them onto the website. Next, I run this 
# script, which moves the files to the appropriate website dirs, time-stamps
# them, etc.
# 
# Usage:
#	
#	% makeweb
#
# (no arguments).
#
# It assumes that the files have been uploaded into the correct dirs in
# the staging dir. It moves the files to their corresponding dirs in
# the website directory (creating dirs and sub-dirs there, as needed).
#
# The actual moving of each file is handled by _install-html.
#
# The paths to the staging dir and the website dir are stored in the environment
# variables $STAGE_DIR and $HTML_DIR. Some of the makefiles also need the 
# path to the ftp file area; this is stored in the env variable $FTP_DIR.
# It's convenient to set these variables in your .login file, like this:
#
#	setenv HTML_DIR /foo/bar/website
#	setenv FTP_DIR /foo/bar/ftpdir
#	setenv STAGE_DIR ~/staging_area
#
######################################################################

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

# jtb 010915: kluge for a lite version -- if there's an arg, then
# we won't do all the makefiles
set IsLiteVersion=0
if (${#argv} > 0) then
        set IsLiteVersion=1
endif

#echo Installing into $HTML_DIR
logit ${me}

# Find any html files in the STAGE_DIR and run _install-html on each one
echo  Finding and installing files...
find $STAGE_DIR -name \*html -exec _install-html {} \;
echo

if ($IsLiteVersion) then
	echo "Done."
	exit
else
	echo "Onward to the makefiles..."
endif

# Some makefile file dependencies may have changed after installing the html
# files, so run all the makefiles now
do-makefiles


# Update the "tech" directory
maketech

# After a bunch of installs (say, at the end of a busy day), run makebulk
# to update the zip copy of the whole website
echo 
echo \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
echo \*\*\* Don\'t forget to run \'makebulk\' \*\*\*
echo \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
echo

