Host changeover.
[firewall] / Makefile
index 242bbfd..7596df7 100644 (file)
--- a/Makefile
+++ b/Makefile
 MAIN_M4_SOURCES                 =
 HOSTS                   =
 
+## Where to install the scripts.
+FIREWALL                = /etc/init.d/firewall
+
+## How to achieve root privileges.
+ROOT                    = sudo
+
+## Throw additional scripts in here to have them installed.
 SCRIPTS                         =
+sbindir                         = /usr/local/sbin
 
+## Establish the default target early, so that targets in `local.mk' don't
+## override it.
 default: all
 .PHONY: default
 
@@ -88,6 +98,18 @@ M4_SOURCES           += $(MAIN_M4_SOURCES)
 TARGETS                         = $(addsuffix .sh,$(HOSTS))
 
 ###--------------------------------------------------------------------------
+### Prologue testing.
+
+TARGETS                        += dummy.sh
+dummy.sh: base.m4 prologue.m4 dummy-payload.m4
+       $(V_M4) $^ >$@.new && chmod +x $@.new && mv $@.new $@
+
+TARGETS                        += dummy-inst.sh
+dummy-inst.sh: dummy.sh
+       $(V_GEN)sed '/dummy_action=/s/lose/win/' $< >$@.new
+       $(V_AT)chmod +x $@.new && mv $@.new $@
+
+###--------------------------------------------------------------------------
 ### Building.
 
 all: $(TARGETS)
@@ -100,4 +122,38 @@ all: $(TARGETS)
 clean:; rm -f $(TARGETS) *.new
 .PHONY: clean
 
+###--------------------------------------------------------------------------
+### Installation.
+
+## The local machine doesn't want the complicated SSH stuff.
+THISHOST                = $(shell hostname)
+
+## Testing.
+check: $(THISHOST).sh
+       $(ROOT) ./$(THISHOST).sh test
+
+## Installation on a local host,
+install/$(THISHOST): $(THISHOST).sh
+       [ "x$(SCRIPTS)" = x ] || $(ROOT) install -m755 $(SCRIPTS) $(sbindir)
+       $(ROOT) ./$(THISHOST).sh replace
+
+## Installation on a remote host.
+install/%: %.sh
+       if [ "x$(SCRIPTS)" != x ]; then \
+         for i in $(SCRIPTS); do \
+           $(ROOT) scp $$i root@$*:$(sbindir)/$$i.new && \
+           $(ROOT) ssh root@$* \
+               'cd $(sbindir) && chmod 755 $$i.new && mv $$i.new $i' || \
+           exit 1; \
+         done; \
+       fi
+       $(ROOT) scp $*.sh root@$*:$(FIREWALL).new
+       $(ROOT) ssh root@$* $(FIREWALL) remote-prepare
+       $(ROOT) ssh root@$* $(FIREWALL) remote-commit
+       $(ROOT) ssh root@$* rm -f $(FIREWALL).new
+
+## General installation target.
+install: all install/$(THISHOST) $(addprefix install/,$(HOSTS))
+.PHONY: install install/$(THISHOST)
+
 ###----- That's all, folks --------------------------------------------------