#! /bin/csh -f
######################################################################
# This script updates the zip archive of the entire website.
#
# See the comments in 'makeweb' for details about the environment variables
# $FTP_DIR and $HTML_DIR.
#
# Usage:
#
#	% makebulk
#
# The makefile "BULKMAKE" contains all the details for updating the
# zipfile. Here's what it looks like:
#
# -------- start of BULKMAKE --------
#
#	SHELL = /bin/sh
#	DESTDIR = $(FTP_DIR)/bulk
#	
#	ZIP = bulk.zip
#
#	EXCLUDE = pariyatti.html\
#		patipatti.html\
#	... (other files to exclude) ...
#		pali/fonts.html
#
#	INCLUDE = *.html\
#		tech/*\
#		cdrom/*html\
#		pali/*.html\
#	... (a bunch of other directories) ...
#		canon/khuddaka/therigatha/*.html\
#		canon/khuddaka/udana/*.html
#
#	$(ZIP): $(INCLUDE)
#		@ echo "Updating $(ZIP)"
#		zip -u -b /tmp $(DESTDIR)/$(ZIP) $(INCLUDE) -x $(EXCLUDE)
#		chmod a+r $(DESTDIR)/$(ZIP)
#		cd $(DESTDIR) ;\
#		unzip -p $(ZIP) index.html | sed -e "/BASE HREF/d" > index.html ;\
#		zip -u -b /tmp $(ZIP) index.html ; rm index.html
#		echo done.
#
#	all:
#		make -f BULKMAKE $(ZIP)
#
#	kill:
#		rm $(DESTDIR)/$(ZIP)
#
# -------- end of BULKMAKE --------
#
######################################################################

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


cd $HTML_DIR
#The following is a cheap kludge. What if the subsequent 'make'
#fails? -- we're still left with an updated bulk.html date.
htmlstamp -t _REV_DATE_START_ _REV_DATE_END_ $HTML_DIR/lib/bulk.html

make -f $HTML_DIR/BULKMAKE all

# jtb 000503: added bulklist stuff
# Now update the list of new arrivals
bulklist

# Add the modified 'bulklist' back into the zip file
cd $HTML_DIR
zip -u -b /tmp $FTP_DIR/bulk/bulk.zip lib/newfiles.html lib/allfiles.html

# jtb 010617 
# Now filter certain files in bulk.zip. Some files refer to online-only
# features of the website (e.g., the search engine). This cleans up
# those files.
make -f $HTML_DIR/BULKMAKE bulkfix

echo makebulk done.

