INTE_SEC_SERVERS=62.93.174.78
INFO_SEC_SERVERS=195.114.85.138  195.114.85.139  62.93.173.252
AFAA_SERVERS=192.168.144.144  192.168.144.152  192.168.144.168  10.0.0.131
AFAA_MASTER=192.168.144.144
AFAA_SLAVES=                  192.168.144.152  192.168.144.168  10.0.0.131
SSH_OPT=-q -t

all:
	case $$(hostname -f) in \
	*.intergruas.com) \
		$(MAKE) intergruas ;;\
	*.informatimago.com) \
		$(MAKE) informatimago ;;\
	*.afaa.asso.fr|*.culturesfrance.*|*cultures-france.*) \
		$(MAKE) afaa ;;\
	esac


intergruas:    clean generate-inte sync-info                 restart
informatimago: clean generate-info sync-info                 restart
afaa:          clean generate-afaa sync-afaa  rights  links  restart-all

help:
	@echo "make all           #  clean generate synchronize rights links restart-all"
	@echo "make clean         #  remove crub."
	@echo "make generate-inte #  generate dyn/* from intergruas.lisp."
	@echo "make generate-info #  generate dyn/* from informatimago.lisp."
	@echo "make generate-afaa #  generate dyn/* from afaa.lisp."
	@echo "make hup           #  signals named."
	@echo "make links         #  make symbolic links on the servers."
	@echo "make synchronize   #  copies files to the servers."
	@echo "make test          #  run some lookups."

clean:
	-rm -f *~ bin/*~ *.fas *.lib /var/lib/named/*~

generate-inte:
	umask 022 && clisp -ansi -norc -q -K full \
	    -x '(load (compile-file "dns")) (defparameter private nil) (load (compile-file "intergruas")) (generate)'
	umask 022 && clisp -ansi -norc -q -K full \
	    -x '(load (compile-file "dns")) (defparameter private t)   (load (compile-file "intergruas")) (generate)'


generate-info:
	umask 022 && clisp -ansi -norc -q -K full \
	    -x '(load (compile-file "dns")) (load (compile-file "informatimago")) (generate)'


generate-afaa:
	umask 022 && clisp -ansi -norc -q -K full \
	    -x '(load (compile-file "dns")) (defparameter private nil) (load (compile-file "afaa")) (generate)'
	umask 022 && clisp -ansi -norc -q -K full \
	    -x '(load (compile-file "dns")) (defparameter private t)   (load (compile-file "afaa")) (generate)'

sync-info: sync-info-remote
sync-info-remote:
	for h in $(INFO_SEC_SERVERS) ; do \
		echo "==== $$h" ;\
		scp /var/lib/named/zones-public-slave-informatimago.conf \
			$${h}:/var/lib/named ;\
	done

sync-afaa: sync-afaa-local sync-afaa-remote

sync-afaa-local:
	tar -C /var/lib -zcf /tmp/named.tar.gz --exclude=dev --exclude=etc --exclude=log --exclude=dyn --exclude=old --exclude=old-lisp --exclude=slave --exclude=public-slave --exclude=intra-slave --exclude=var  named
	for h in $(AFAA_SERVERS) ; do \
		if [ `hostname` = $$h ] ; then \
			true ;\
		else \
			echo ======================= ;\
			echo $$h ;\
			echo ======================= ;\
			cat /tmp/named.tar.gz | ssh $(SSH_OPT) $$h tar -zxvf - -C /var/lib/ ;\
		fi ;\
	done

sync-afaa-remote:
	ping -c 3  -q larissa.informatimago.com \
	&& scp /var/lib/named/zones-public-slave-afaa.conf \
		larissa.informatimago.com:/var/lib/named/

rights:
	for h in $(AFAA_SERVERS) ; do \
		echo ======================= ;\
		echo $$h ;\
		echo ======================= ;\
		ssh $(SSH_OPT) $$h 'chown -R root:root /var/lib/named ; chown -R named:named /var/lib/named/{log,dyn,{public,intra}-{master,slave},var/run} ; chown root:named /var/lib/named/*.conf ; chmod 0640 /var/lib/named/*.conf ; chown named:root /var/lib/named ; chmod 1755 /var/lib/named /var/lib/named/var/run' ;\
	done

links:
	for h in $(AFAA_MASTER) ; do \
		ssh $(SSH_OPT) $$h ln -sf ../var/lib/named/named-public-master.conf /etc/named-public.conf ;\
		ssh $(SSH_OPT) $$h ln -sf ../var/lib/named/named-intra-master.conf  /etc/named-intra.conf ;\
	done
	for h in $(AFAA_SLAVES) ; do \
		ssh $(SSH_OPT) $$h ln -sf ../var/lib/named/named-public-slave.conf /etc/named-public.conf ;\
		ssh $(SSH_OPT) $$h ln -sf ../var/lib/named/named-intra-slave.conf  /etc/named-intra.conf ;\
	done

restart:
	/etc/init.d/named restart

restart-all:
	hdo '/etc/init.d/named restart'
	jdo '/etc/init.d/named restart'

hup:
	kill -HUP `cat /var/lib/named/var/run/named-public.pid`
	kill -HUP `cat /var/lib/named/var/run/named-intra.pid`

hup-all:
	hdo 'kill -HUP `cat /var/lib/named/var/run/named-public.pid`'
	hdo 'kill -HUP `cat /var/lib/named/var/run/named-intra.pid`'
	jdo 'kill -HUP `cat /var/lib/named/var/run/named-public.pid`'
	jdo 'kill -HUP `cat /var/lib/named/var/run/named-intra.pid`'

test:
	@echo ---------------------------------------------------
	nslookup -query=A          afaa.asso.fr.
	@echo ---------------------------------------------------
	nslookup -query=A  galatea.afaa.asso.fr.
	@echo ---------------------------------------------------
	nslookup -query=MX         afaa.asso.fr.
	@echo ---------------------------------------------------
	nslookup -query=MX galatea.afaa.asso.fr.
	@echo ---------------------------------------------------


#### Makefile                         --                     --          ####
ViewGit