From 2a0b23c9a8170d6c3befeb42104e6e3ac02c0645 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 16 Sep 2023 08:09:04 -0500 Subject: [PATCH] meta: Add Makefile When developing Butane/Ignition files, I frequently forget to update the parent files after making a change to an included file. This causes a lot of wasted time re-provisioning, only to discover that my change did not take effect. To alleviate this, we'll use `make` with some macro magic to scan the Butane files for their dependencies, and let it generate whatever Ignition files need updating any time a dependant file changes. I've also added a "publish" step to the Makefile, since I also frequently forget to upload the regenerated Ignition files to the server, causing the same headaches. --- Makefile | 22 ++++++++++++++++++++++ butane-watch.sh | 7 ++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a6c7693 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +.PHONY: \ + all \ + clean \ + publish + +.DEFAULT_GOAL := all + +clean: + rm -f *.ign + +define genrules +$(patsubst %.yaml,%.ign,$(1)): $(1) $$(shell sed -rn 's/.*local: (.*)/\1/p' $(1)) + butane -d . $$< > $$@ + +all: $(patsubst %.yaml,%.ign,$(1)) +endef + +$(foreach t,$(wildcard *.yaml),$(eval $(call genrules,$(t)))) + +publish: \ + nvr1.ign + rsync -rti $^ files.pyrocufflink.blue:public_html/ diff --git a/butane-watch.sh b/butane-watch.sh index 56e1a55..f5440c7 100644 --- a/butane-watch.sh +++ b/butane-watch.sh @@ -2,8 +2,9 @@ # vim: set sw=4 ts=4 sts=4 et : inotifywait -e CLOSE_WRITE -m . \ - | stdbuf -o 0 grep -F .yaml \ + | stdbuf -o 0 grep -v .ign \ | while read _ _ f; do - printf 'Regenerating %s from %s ...\n' "${f%.yaml}.ign" "${f}" - butane -d . ${f} > ${f%.yaml}.ign + [ -f "${f}" ] || continue + printf '%s changed, running make ...\n' "${f}" + make && make publish done