# ----------------------------------------------------------------------------
#                                   X-BONE
#
#                USC Information Sciences Institute (USC/ISI)
#                   Marina del Rey, California 90292, USA
#                          Copyright (c) 1998-2003
#
#			     $Revision: 1.130 $
#			$Date: 2005/04/08 23:52:36 $
# ----------------------------------------------------------------------------

#=> install paths
PREFIX?=	/usr/local
CONF?=		${PREFIX}/etc/xbone
CERT?=		${PREFIX}/etc/xbone/cert
WWW?=		${PREFIX}/www
MYCPAN?=	${PREFIX}/xbone/programs/modules/cpan
GUICPAN?=	${WWW}/xbone/cpan

#=> source paths
SRC?=		${CURDIR}/xbone
PGM?=		${SRC}/programs
CACERT?=	${SRC}/conf/cert
LCPAN?=		${CURDIR}/ports

#=> checking old stuff
OLD_CERT_DIR?=	${PREFIX}/xbone/conf/cert ${WWW}/server-cert ${WWW}/cert \
		/etc/xbone/cert
OLDIES?=	Xbone_daemon.conf Xbone_daemon.state

STATEDIR?=      /var/xbone/
APACHE_CONF?=	${PREFIX}/etc/apache
DNS?=		named-conf
RPMSRC?=	${CURDIR}/..
LOG?=		${CURDIR}/xbone-install.log
NAMED_PATH?=	/etc/namedb	/etc
ZONE_PATH?=	/etc/namedb	/var/named	/var/adm/domain
SETKEY?=	setkey
PERL5?=		`which perl`
TIME?=		`date "+%m%d%H%M"`
OS := 		$(shell uname -s)
DIALOG?=	/usr/bin/dialog
NONROOT?=	"*** You need to be root to configure/run X-Bone. ***"

NODECMD =       perl Makefile.PL PREFIX=${MYCPAN} INSTALLDIRS=perl \
                  INSTALLARCHLIB=${MYCPAN} INSTALLMAN1DIR=${MYCPAN} \
                  INSTALLMAN3DIR=${MYCPAN}

GUICMD =        perl Makefile.PL PREFIX=${GUICPAN} INSTALLDIRS=perl \
                  INSTALLARCHLIB=${GUICPAN} INSTALLMAN1DIR=${GUICPAN} \
                  INSTALLMAN3DIR=${GUICPAN}

MAN5-NODE?= 	XB_Params.pm.5 xbone.conf.5 
MAN8-NODE?= 	X-Bone.8 xb-node-control.8 xb-node-daemon.8 xbonectl.8 \
                xb-ldap-config.8 
MAN5-GUI?= 	xbone-gui.conf.5 
MAN8-GUI?= 	xb-gui-control.8 xb-apache-config.8


.SILENT: 	node gui \
		sys-check copyfile rpm-fix   www\
		xb-conf gui_msg rd_msg dns-server dns-client install\
		dns-forced http-forced\
		clean-www clean-xbone clean-etc clean-all \
		tarball mdir export trim tball cleanup port toweb

.PHONY:		node gui \
		sys-check copyfile rpm-fix   www\
		xb-conf gui_msg rd_msg dns-server dns-client install\
		dns-forced http-forced\
		clean-www clean-xbone clean-etc clean-all\
		tarball mdir export trim tball cleanup port toweb

ch-gmake:
	@echo ">>> Verify if \"gmake\" is used:"
	@if( test "${CURDIR}" = "") then { \
	  echo "    ! [Error]: You need to use \"gmake\", not \"make\"."; \
	  exit 1; \
	} else { \
	  echo "    - gmake checked ok."; \
	} fi


base:	ch-gmake
	date "+>>> XBone: %Y-%m-%d TIME: %H:%M:%S" | tee -a ${LOG}
	echo ">>> Installing X-Bone files into ${PREFIX}/xbone:"| tee -a ${LOG}
	if( test ! -d ${CERT} ) then { \
	  echo "    - make ${CERT}" | tee -a ${LOG}; \
	  mkdir -p ${CERT}; \
	} fi
	if ( test -d ${PREFIX}/xbone ) then { \
	  echo "    - move ${PREFIX}/xbone xbone-${TIME}" | tee -a ${LOG}; \
	  mv -f ${PREFIX}/xbone ${PREFIX}/xbone-${TIME}; \
	} fi
	for p in ${OLD_CERT_DIR}; do \
	  if ( test -d $$p ) then { \
	    echo "    - copy old certs/keys from $$p" | tee -a ${LOG}; \
	    cp -fR $$p/* ${CERT}/; \
	  } fi;\
	done
	for o in ${OLDIES}; do \
	  if( test -f ${CONF}/$$o ) then { \
	    echo "    ! old ${CONF}/$$o no longer in use"|tee -a ${LOG};\
	  } fi ;\
	done
	cp -Rf ${SRC} ${PREFIX}/xbone
	mkdir -p ${PREFIX}/man/man8
	for f in ${MAN8-NODE}; do \
	   cp ${SRC}/man/man8/$$f  ${PREFIX}/man/man8/; \
        done
	mkdir -p ${PREFIX}/man/man5
	for f in ${MAN5-NODE}; do \
	   cp ${SRC}/man/man5/$$f  ${PREFIX}/man/man5/; \
        done
	cp -Rf ${SRC}/conf/*sample ${CONF}
	cp -Rf ${SRC}/conf/openldap ${CONF}
	cp -Rf ${SRC}/conf/named ${CONF}
	cp -Rf ${SRC}/conf/routing ${CONF}
	cp -f ${CACERT}/CAcert* ${CERT}
	cp -f ${CACERT}/README ${CERT}
	cp -Rf ${CURDIR} ${PREFIX}/xbone/install
	rm -rf ${PREFIX}/xbone/install/xbone
	rm -f ${PREFIX}/xbone/install/xbone-install.log
	echo ">>> Build & install local Perl modules:" | tee -a ${LOG}
	for d in `ls ${LCPAN}`; do\
	  if(test -d ${LCPAN}/$$d) then {\
	    echo "    - install $$d" | tee -a ${LOG};\
	    cd ${LCPAN}/$$d ; ${NODECMD}; \
	    make pure_all pure_install;\
	    make clean;\
	    rm Makefile.old;\
	    rm -rf ${MYCPAN}/lib ; \
	  } fi;\
	done
	find ${PREFIX}/xbone -exec chmod ugo+r {} \;
	find ${PREFIX}/xbone -type f -name '*.pl' -exec chmod ugo+x {} \;
	find ${PREFIX}/xbone -type d -exec chmod ugo+x {} \;
	mkdir -p ${PREFIX}/bin


postinstall:	
	ln -fs ${PREFIX}/xbone/programs/xb-node-daemon.pl \
	      ${PREFIX}/bin/xb-node-daemon; 
	ln -fs ${PREFIX}/xbone/programs/xb-api-client.pl \
	      ${PREFIX}/bin/xb-api-client; 
	ln -fs ${PREFIX}/xbone/install/xb-node-control.pl \
	      ${PREFIX}/bin/xb-node-control; 
	ln -fs ${PREFIX}/xbone/programs/xbonectl.pl \
	      ${PREFIX}/bin/xbonectl; 
	ln -fs ${PREFIX}/etc/xbone/openldap/xb-ldap-config.pl \
	      ${PREFIX}/bin/xb-ldap-config; 
	@echo "<<< File installation completed."  | tee -a ${LOG}
	@echo "   +=========================================================+"
	@echo "     Run xb-node-control to configure the X-Bone Node Daemon  "
	@echo "   +=========================================================+"

#	echo ">>> Create an XBone node config file: " | tee -a ${LOG};\
#	  ${PREFIX}/xbone/install/xb-node-control.pl; \

node: ch-gmake base postinstall

node-rpm: ch-gmake base 

gui-postinstall: 
	ln -fs ${WWW}/xbone/lib/xb-gui-control.pl ${PREFIX}/bin/xb-gui-control
	ln -fs ${PREFIX}/etc/xbone/apache/xb-apache-config.pl \
	      ${PREFIX}/bin/xb-apache-config; 
	echo "<<< File installation completed."  | tee -a ${LOG}

#	echo ">>> Create an XBone GUI node config file: " | tee -a ${LOG};\
#	  ${PREFIX}/bin/xb-gui-control

gui-base: ch-gmake 
	echo ">>> Installing XBone GUI files into ${WWW}" | tee -a ${LOG}
	if (test ! -d ${WWW}) then {\
	   mkdir -p ${WWW}; \
	} fi 
	if (test -d ${WWW}/xbone) then {\
	  cp -R ${WWW}/xbone ${WWW}/xbone-`date "+%m%d%H%M"` && \
	  echo "    - ${WWW}/xbone is backed up to ${WWW}/xbone-`date "+%m%d%H%M"`" |\
	    tee -a ${LOG} ||\
	  echo "    - ${WWW}/xbone wasn't backed up." | tee -a ${LOG};\
	  rm -rf ${WWW}/xbone;\
	  echo "    - old ${WWW}/xbone removed." | tee -a ${LOG};\
	} fi
	if (test -d ${SRC}) then {\
	  cp -Rf ${SRC}/www ${WWW}/xbone;\
	  cp -Rf ${PGM}/modules/cpan ${WWW}/xbone;\
	} fi
	if( test ! -d ${WWW}/xbone/lib ) then { \
	  echo "    - make ${WWW}/xbone/lib" | tee -a ${LOG}; \
	  mkdir -p ${WWW}/xbone/lib; \
	} fi
	if( test ! -d ${CERT} ) then { \
	  echo "    - make ${CERT}" | tee -a ${LOG}; \
	  mkdir -p ${CERT}; \
	} fi
	cp -Rf ${SRC}/conf/apache            ${CONF}
	cp -Rf ${PGM}/XB_Params.pm           ${WWW}/xbone/lib
	cp -Rf ${PGM}/modules/XB_Common.pm   ${WWW}/xbone/lib
	cp -Rf ${PGM}/modules/XB_XML_GUI.pm  ${WWW}/xbone/lib
	cp -Rf ${PGM}/modules/XB_XML_scan.pm ${WWW}/xbone/lib
	cp -Rf ${PGM}/modules/api*.dtd       ${WWW}/xbone/lib
	mkdir -p ${PREFIX}/man/man8
	for f in ${MAN8-GUI}; do \
	   cp ${SRC}/man/man8/$$f  ${PREFIX}/man/man8/; \
        done
	mkdir -p ${PREFIX}/man/man5
	for f in ${MAN5-GUI}; do \
	   cp ${SRC}/man/man5/$$f  ${PREFIX}/man/man5/;\
        done
	cp -Rf ${CURDIR}/xb-gui-control.pl    ${WWW}/xbone/lib
	for c in `ls ${CACERT}`; do \
	  if( test ! -e ${CERT}/GUI-$$c ) then  {\
	      cp -f ${CACERT}/$$c ${CERT}/GUI-$$c; \
	  } fi; \
	done
	echo ">>> Build & install local Perl modules:" | tee -a ${LOG}
	for d in `ls ${LCPAN}`; do\
	  if(test -d ${LCPAN}/$$d) then {\
	    echo "    - install $$d" | tee -a ${LOG};\
	    cd ${LCPAN}/$$d ; ${GUICMD}; \
	    make pure_all pure_install;\
	    make clean;\
	    rm Makefile.old;\
	    rm -rf ${GUICPAN}/lib ; \
	  } fi;\
	done
	find ${WWW}/xbone -exec chmod ugo+r {} \;
	find ${WWW}/xbone -type f -name '*.pl' -exec chmod ugo+x {} \;
	find ${WWW} -type d -exec chmod ugo+x {} \;
	find ${WWW}/xbone -type f -name '*.ORIG' -exec rm -f {} \;
	@echo "<<< GUI files installed in ${WWW}/xbone" | tee -a ${LOG}
	@echo ""
	@echo ">>> Apache conf file: " | tee -a ${LOG}
	@echo "   +=========================================================+"
	@echo "         Run xb-gui-control to configure the X-Bone GUI."
	@echo "   +=========================================================+"
	mkdir -p ${PREFIX}/bin

gui: ch-gmake gui-base gui-postinstall

gui-rpm: ch-gmake gui-base 

xb-conf:	ch-gmake
	${PERL5} ${PREFIX}/xbone/install/xb-node-control.pl

gui_msg:
	echo ">>> X-Bone GUI installation completes." | tee -a ${LOG}
	echo ""
	echo ">>> Procedures to start the X-Bone OM/GUI"
	echo "(0) Obtain signed Host Certificate for the web server, overlay"
	echo "    manager, and the DNS resource daemon. (It's the same one"
	echo "    for all three by default.)"
	echo "    Copy them to ${CONF}/cert"
	echo "    ************************************************************"
	echo "    # WARNING - make sure your keys are sufficiently protected.#"
	echo "    #  *cert.* files are public keys, 644 is sufficient        #"
	echo "    #  *key.* files are private keys, 600 is recommended       #"
	echo "    #                                                          #"
	echo "    # These must be set when the keys are installed; they are  #"
	echo "    # NOT set by the X-Bone installation package.              #"
	echo "    ************************************************************"
	echo "(1) Check your httpsd.conf, named.conf & zone files."
	echo "(2) (Re)start the name server:      % named"
	echo "(3) (Re)start the web server:       % httpsdctl start"
	echo "(4) Start the DNS resource daemon:  % xb-daemon"
	echo "(5) Start the overlay manager:      % xb-overlay-manager"
	echo ""
	echo "    Email to <xbone@isi.edu> if you have any questions."
	echo "<<< Enjoy! "
	echo ""

rd_msg:
	echo ">>> X-Bone RD installation completes." | tee -a ${LOG}
	echo ""
	echo ">>> Procedures to start the X-Bone RD"
	echo "(0) Obtain signed Host Certificates for the resource daemon"
	echo "    and copy the cert-key pair to ${CONF}/cert/."
	echo "    ************************************************************"
	echo "    # WARNING - make sure your keys are sufficiently protected.#"
	echo "    #  *cert.* files are public keys, 644 is sufficient        #"
	echo "    #  *key.* files are private keys, 600 is recommended       #"
	echo "    #                                                          #"
	echo "    # These must be set when the keys are installed; they are  #" 
	echo "    # NOT set by the X-Bone installation package.              #"
	echo "    ************************************************************"
	echo "(1) Check your /etc/resolv.conf (refer to resolv.conf.xbone)."
	echo "(2) Start the resource daemon:     % xb-daemon "
	echo "(3) [User] open the web page: <http://your.web.server/xbone/>"
	echo ""
	echo "    Email to <xbone@isi.edu> if you have any questions."
	echo "<<< Enjoy!"
	echo ""

dns-server:	ch-gmake
	echo ">>> X-Bone DNS Server Setup:" | tee -a ${LOG}
	echo "    Examples of DNS server (named) configuration & zone files:"
	echo "      ${PREFIX}/etc/xbone/named-conf/named.conf"
	echo "      ${PREFIX}/etc/xbone/named-conf/xbone/xbone-forward.zone"
	echo "      ${PREFIX}/etc/xbone/named-conf/xbone/xbone-reverse.zone"
	echo "    Modify your named.conf according to the example, and copy"
	echo "    the zone file directory to the location indicated in your"
	echo "    named.conf."
	echo "    --------------------------------------"
	echo "    FreeBSD: named.conf    -> /etc/namedb"
	echo "             zone file dir -> /etc/namedb"
	echo "    RedHat:  named.conf    -> /etc"
	echo "             zone file dir -> /var/named"
	echo "    Solaris: named.conf    -> /etc"
	echo "             zone file dir -> /var/adm/domain"
	echo "<<< End DNS Server message" | tee -a ${LOG}

dns-client:	ch-gmake
	echo ">>> X-Bone DNS Client Setup:" | tee -a ${LOG}
	echo "    Add the following line to the beginning of \"nameserver\""
	echo "    section in /etc/resolv.conf:"
	echo -n "      " && cat ${PREFIX}/etc/xbone/named-conf/resolv.conf
	echo "<<< End DNS Client message" | tee -a ${LOG}

install:	ch-gmake
	echo "*** Error! Follow the instructions for each platform."
	exit 1

forced:		dns-forced http-forced

dns-forced:	ch-gmake
	echo "*** Force DNS server (named) configurations:" | tee -a ${LOG}
	${DIALOG} --yesno "** WARNING ** This will overwrite the existing\
	  named.conf and X-Bone forward/reverse zone files. Do you want to\
	  continue?" 10 60 && \
	  for d in ${NAMED_PATH}; do\
            if ( test -f $$d/named.conf ) then {\
	      echo "    - Found $$d/named.conf." | tee -a ${LOG};\
	      if ( test ! -f $$d/named.conf-ORIG ) then {\
	        mv -f $$d/named.conf $$d/named.conf-ORIG;\
		echo "    - $$d/named.conf -> $$d/named.conf-ORIG" |\
		tee -a ${LOG};\
	      } fi;\
	      cp -f ${CONF}/named-conf/named.conf $$d/named.conf;\
	      echo "    - ${CONF}/named-conf/named.conf -> $$d/named.conf" |\
	      tee -a ${LOG};\
	    } fi;\
	  done && \
	  for e in ${ZONE_PATH}; do\
	    if ( test -d $$e ) then {\
	      mkdir -p $$e/xbone;\
	      cp -f ${CONF}/named-conf/xbone/* $$e/xbone/;\
	      echo "    - ${CONF}/named-conf/xbone/* -> $$e/xbone/" |\
	      tee -a ${LOG};\
	    } fi;\
	  done || \
	  echo "<<< Did not alter named configurations." | tee -a ${LOG}

http-forced:	ch-gmake
	echo "*** Force Apache-SSL configuration:" | tee -a ${LOG}
	${DIALOG} --yesno "** WARNING ** This will overwrite the existing\
	  httpsd.conf. Do you want to continue?" 10 60 && \
	  if (test ! -f ${PREFIX}/etc/apache/httpsd.conf-ORIG) then {\
	    mv ${PREFIX}/etc/apache/httpsd.conf \
	       ${PREFIX}/etc/apache/httpsd.conf-ORIG;\
	    echo "    - ${PREFIX}/etc/apache/httpsd.conf -> httpsd.conf-ORIG"|\
	    tee -a ${LOG};\
	  } fi && \
	  ln -sf ${PREFIX}/etc/apache/httpsd.conf.xbone \
		 ${PREFIX}/etc/apache/httpsd.conf && \
	  echo "    - Symlink ${PREFIX}/etc/apache/httpsd.conf ->\
		      httpsd.conf.xbone" | tee -a ${LOG} || \
	  echo "    ! Did not alter httpsd.conf." | tee -a ${LOG}


#=============================================================================e
# [ISI-INTERNAL] Utility Targets
#==============================================================================
clean-www:
	if (test -d /usr/local/www) then { \
	  rm -r /usr/local/www; \
	  if (test -d /usr/local/www-OLD) then { \
	    mv /usr/local/www-OLD /usr/local/www; \
	  } fi; \
	} fi
	if (test -d /usr/local/etc/apache) then { \
	  rm -r /usr/local/etc/apache; \
	  if (test -d /usr/local/etc/apache-OLD) then { \
	    mv /usr/local/etc/apache-OLD /usr/local/etc/apache; \
	  } fi; \
	} fi

clean-xbone:
	if (test -d ${PREFIX}/xbone) then {\
	  rm -r ${PREFIX}/xbone; \
	  if (test -d ${PREFIX}/xbone-OLD) then { \
	    mv ${PREFIX}/xbone-OLD ${PREFIX}/xbone; \
	  } fi ;\
	} fi

clean-etc:
	if (test -d ${CONF}) then {\
	  rm -r ${CONF};\
	} fi

clean-all:	clean-www clean-xbone

#==============================================================================
# [ISI-INTERNAL] Section for generating X-Bone source & port tarballs
#==============================================================================

CVSROOT=	/home/xbone/CVSROOT
MODULE?=	xbone
PORT?=		xbone/install/xbone-port
GPORT?=		xbone/install/xbone-gui-port
APACHE-CONF?=	apache-conf
APACHE-DIR?=	apache_conf_sample
VERSION?=	3.2
DIR?=		XBone-${VERSION}
PORTDIR?=	xbone-${VERSION}-port
GPORTDIR?=	xbone-gui-${VERSION}-port
CVSOPTIONS?=	-n
TARBALL?=	XBone-${VERSION}

# add new things to prune to the list below (appending a * to a directory
# name will remove all files there but keep the directory)
TRIM-FILES?=	xbone/action-items xbone/install xbone/isi \
		.cvsignore release_checklist xbone-port xbone-rpm \
		xbone/conf/.cvsignore \
		xbone-gui-port ports/Socket6-devel-0.12 \
		xb-gui-config.pl xb-config.pl \

WEBBIN?=		/home/xbone/public_html/software/xbone/
WEBNOTES?=		/home/xbone/public_html/software/

tarball:	mdir export trim tball cleanup

mdir:		ch-gmake
	echo ">>> Check ${DIR}; make one if not exists."
	if ( test -d ${CURDIR}/${DIR} ) then { \
	  echo "    ! Temp dir ${CURDIR}/${DIR} exists!"; \
	  echo "    ! Remove it or use another directory name (DIR=...)."; \
	  exit 0; \
	} else { \
	  mkdir ${CURDIR}/${DIR}; \
	} fi

export:		ch-gmake
	echo ">>> Exporting a copy of the tree from CVSROOT:"
	echo "    - CVS export: xbone"; 
	if ( test -n "${DATE}" ) then { \
	  echo "      - Date =  ${DATE} "; \
	  cd ${CURDIR}/${DIR}; \
	  cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -D ${DATE} -d . \
	    ${MODULE}/install; \
	  cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -D ${DATE} ${MODULE}; \
	} elif ( test -n "${REV}" ) then { \
	  echo "      - Revision = ${REV} "; \
	  cd ${CURDIR}/${DIR}; \
	  cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -r ${REV} -d . \
	    ${MODULE}/install; \
	  cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -r ${REV} ${MODULE}; \
	} else { \
	  echo "      - Did not specify date or tag, use \"now\"."; \
	  cd ${CURDIR}/${DIR}; \
	  cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -D now -d . \
	    ${MODULE}/install; \
	  cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -D now ${MODULE}; \
	} fi;  \

trim:		ch-gmake
	echo ">>> Delete files for ISI internal use:"
	for d in ${TRIM-FILES}; do \
	  echo "    - Pruning $$d...";\
	  rm -r ${CURDIR}/${DIR}/$$d 2> /dev/null || \
	    echo "    ! Could not remove $$d from source tree."; \
	done

tball:		ch-gmake
	echo ">>> Make tarball:"
	tar cfz ${CURDIR}/${TARBALL}.tar.gz ${TARBALL} 2> /dev/null 

#update the port
md5: ${TARBALL}.tar.gz
	echo "Updating md5 checksums"
	( cd xbone-port; make makesum)
	( cd xbone-gui-port; make makesum)

cleanup:	ch-gmake 
	echo ">>> Clean up."
	if ( test -d ${CURDIR}/${DIR} ) then  {\
	  rm -rf ${CURDIR}/${DIR}; \
	} fi

gport:		ch-gmake
	echo "==> Exporting a copy of the tree from CVSROOT ..."
	echo "    - Check if ${MODULE} exists."
	if ( test -d ${CURDIR}/${GPORTDIR} ) then { \
	  echo "    ! Temp dir ./${GPORTDIR} exists! Remove it first"; \
	  exit 0; \
	} else {\
	  echo "    - CVS export: xbone-ports"; \
	  if ( test -n "${DATE}" ) then { \
	    echo "      - Date =  ${DATE} "; \
	    cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -D ${DATE} -d ${GPORTDIR}\
		${GPORT}; \
	  } elif ( test -n "${REV}" ) then { \
	    echo "      - Revision = ${REV} "; \
	    cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -r ${REV} -d ${GPORTDIR}\
		${GPORT}; \
	  } else { \
	    echo "      - Did not specify date or tag, use \"now\"."; \
	    cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -D now -d ${GPORTDIR} \
		${GPORT}; \
	  } fi;  \
	} fi
	echo "==> Packing ports:"
	tar cfz ${CURDIR}/${GPORTDIR}.tar.gz ${GPORTDIR}
	rm -rf ${GPORTDIR}

port:		ch-gmake
	echo "==> Exporting a copy of the tree from CVSROOT ..."
	echo "    - Check if ${MODULE} exists."
	if ( test -d ${CURDIR}/${PORTDIR} ) then { \
	  echo "    ! Temp dir ./${PORTDIR} exists! Remove it first"; \
	  exit 0; \
	} else {\
	  echo "    - CVS export: xbone-ports"; \
	  if ( test -n "${DATE}" ) then { \
	    echo "      - Date =  ${DATE} "; \
	    cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -D ${DATE} -d ${PORTDIR}\
		${PORT}; \
	  } elif ( test -n "${REV}" ) then { \
	    echo "      - Revision = ${REV} "; \
	    cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -r ${REV} -d ${PORTDIR}\
		${PORT}; \
	  } else { \
	    echo "      - Did not specify date or tag, use \"now\"."; \
	    cvs -Q -d ${CVSROOT} export ${CVSOPTIONS} -D now -d ${PORTDIR} \
		${PORT}; \
	  } fi;  \
	} fi
	echo "==> Packing ports:"
	tar cfz ${CURDIR}/${PORTDIR}.tar.gz ${PORTDIR}
	rm -rf ${PORTDIR}


toweb:
	echo "==> Copy the source & port tarballs to the web directory..."
	chmod g+w *.gz
	cp ${GPORTDIR}.tar.gz ${WEBBIN}
	cp ${PORTDIR}.tar.gz ${WEBBIN}
	cp ${TARBALL}.tar.gz ${WEBBIN}
	for d in README INSTALL CHANGES REQUIREMENTS perl-module-install.sh; \
	do \
		cp $$d ${WEBNOTES}/$$d-${VERSION}.txt; \
	done


installed-node: 
	@cd /usr/local; \
	find -d etc/xbone ! -type d ;\
	find -d xbone ! -type d ;\
	find bin/xb-* ;\
	find -d etc/xbone -type d | sed 's/^/\@dirrm /g' ;\
	find -d xbone -type d | sed 's/^/\@dirrm /g'; \

installed-gui: 
	@cd /usr/local; \
	find -d etc/xbone ! -type d ;\
	find -d www/xbone ! -type d ;\
	find bin/xb-* ;\
	find -d etc/xbone -type d | sed 's/^/\@dirrm /g' ;\
	find -d www/xbone -type d | sed 's/^/\@dirrm /g'; \

# the following is only for test runs before release
testtar:
	tar zcvf xbone-${VERSION}-port.tar.gz \
	    xbone-port/Makefile  xbone-port/distinfo  \
	    xbone-port/pkg-descr xbone-port/pkg-plist
	tar zcvf xbone-gui-${VERSION}-port.tar.gz \
	    xbone-gui-port/Makefile  xbone-gui-port/distinfo  \
	    xbone-gui-port/pkg-descr xbone-gui-port/pkg-plist

testrun: tarball md5 testtar toweb

# do the release. the md5 should be in place
release: tarball port gport toweb



syntax highlighted by Code2HTML, v. 0.9.1