# 
# This file is used as the template to create the
# Makefile for the Solaris specific installation.
#
#  15 November 2001 -- Kern Sibbald
#
#  for Bacula release @VERSION@ (@DATE@) -- @DISTNAME@
#

VPATH = @srcdir@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
SED = /usr/bin/sed

nothing:

install: install-autostart

install-autostart: install-autostart-fd install-autostart-sd install-autostart-dir

	
install-autostart-fd:
	@echo "FreeBSD platform installation"
	$(INSTALL_PROGRAM) -m 744 bacula-fd /etc/rc.bacula-fd
	@-today="`date +%Y%m%d%H%M`"; \
	grep -q /etc/rc.bacula-fd /etc/rc.local; \
	if [ $$? -eq 0 ]; then \
	    echo "/etc/rc.local already patched"; \
	else \
	    rm -f /etc/rc.local.$$today; \
	    cp -p /etc/rc.local /etc/rc.local.$$today; \
	    ( echo "Start the Bacula File daemon. Do not remove the 'TAG_BACULA_FD' text"; \
	      echo "if [ -x /etc/rc.bacula-fd ]; then	  # TAG_BACULA_FD"; \
	      echo "	    /etc/rc.bacula-fd start	  # TAG_BACULA_FD"; \
	      echo "fi					  # TAG_BACULA_FD"; \
	    ) >> /etc/rc.local; \
	    echo ""; \
	fi


install-autostart-sd:
	@echo "FreeBSD platform installation"
	$(INSTALL_PROGRAM) -m 744 bacula-sd /etc/rc.bacula-sd
	@-today="`date +%Y%m%d%H%M`"; \
	grep -q /etc/rc.bacula-sd /etc/rc.local; \
	if [ $$? -eq 0 ]; then \
	    echo "/etc/rc.local already patched"; \
	else \
	    rm -f /etc/rc.local.$$today; \
	    cp -p /etc/rc.local /etc/rc.local.$$today; \
	    ( echo "Start the Bacula Storage daemon. Do not remove the 'TAG_BACULA_SD' text"; \
	      echo "if [ -x /etc/rc.bacula-fd ]; then	  # TAG_BACULA_SD"; \
	      echo "	    /etc/rc.bacula-fd start	  # TAG_BACULA_SD"; \
	      echo "fi					  # TAG_BACULA_SD"; \
	    ) >> /etc/rc.local; \
	    echo ""; \
	fi

install-autostart-dir:
	@echo "FreeBSD platform installation"
	$(INSTALL_PROGRAM) -m 744 bacula-dir /etc/rc.bacula-dir
	@-today="`date +%Y%m%d%H%M`"; \
	grep -q /etc/rc.bacula-dir /etc/rc.local; \
	if [ $$? -eq 0 ]; then \
	    echo "/etc/rc.local already patched"; \
	else \
	    rm -f /etc/rc.local.$$today; \
	    cp -p /etc/rc.local /etc/rc.local.$$today; \
	    ( echo "Start the Bacula Director. Do not remove the 'TAG_BACULA_DIR' text"; \
	      echo "if [ -x /etc/rc.bacula-dir ]; then	  # TAG_BACULA_DIR"; \
	      echo "	    /etc/rc.bacula-dir start	  # TAG_BACULA_DIR"; \
	      echo "fi					  # TAG_BACULA_DIR"; \
	    ) >> /etc/rc.local; \
	    echo ""; \
	fi


uninstall: uninstall-autostart

uninstall-autostart: uninstall-autostart-fd uninstall-autostart-sd uninstall-autostart-dir

uninstall-autostart-fd:
	@echo "FreeBSD platform uninstall"
	rm -f /etc/rc.bacula-fd
	@-today="`date +%Y%m%d%H%M`"; \
	for f in /etc/rc.local ; do \
	    grep -q '# TAG_BACULA_FD' $$f; \
	    if [ $$? -eq 0 ]; then \
		    echo "removing Bacula lines from $$f"; \
		    rm -f $$f.$$today; \
		    cp -p $$f $$f.$$today; \
		    $(SED) -e '/TAG_BACULA_FD/d;' \
			    < $$f.$$today > $$f; \
		    chmod 644 $$f; \
	    fi; \
	done


uninstall-autostart-sd:
	@echo "FreeBSD platform uninstall"
	rm -f /etc/rc.bacula-sd
	@-today="`date +%Y%m%d%H%M`"; \
	for f in /etc/rc.local ; do \
	    grep -q '# TAG_BACULA_SD' $$f; \
	    if [ $$? -eq 0 ]; then \
		    echo "removing Bacula lines from $$f"; \
		    rm -f $$f.$$today; \
		    cp -p $$f $$f.$$today; \
		    $(SED) -e '/TAG_BACULA_SD/d;' \
			    < $$f.$$today > $$f; \
		    chmod 644 $$f; \
	    fi; \
	done

uninstall-autostart-dir:
	@echo "FreeBSD platform uninstall"
	rm -f /etc/rc.bacula-dir
	@-today="`date +%Y%m%d%H%M`"; \
	for f in /etc/rc.local ; do \
	    grep -q '# TAG_BACULA_DIR' $$f; \
	    if [ $$? -eq 0 ]; then \
		    echo "removing Bacula lines from $$f"; \
		    rm -f $$f.$$today; \
		    cp -p $$f $$f.$$today; \
		    $(SED) -e '/TAG_BACULA_DIR/d;' \
			    < $$f.$$today > $$f; \
		    chmod 644 $$f; \
	    fi; \
	done

clean:
	@rm -f 1 2 3

distclean: clean
	@rm -f bacula-sd bacula-fd bacula-dir
	@rm -f Makefile bacula-*.spec

devclean: clean
	@rm -f bacula-sd bacula-fd bacula-dir
	@rm -f Makefile bacula-*.spec
