From 4c51ade750cdfbd589648199de770f0d0b606b32 Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Mon, 18 Nov 2024 18:03:49 +0100 Subject: [PATCH] PS: more Makefiles --- slides/makefiles/PS/general_make.md | 119 ++++++++++++++++++++++++ slides/makefiles/PS/omni_makefile | 34 +++++++ slides/makefiles/examples/omni_makefile | 1 + 3 files changed, 154 insertions(+) create mode 100644 slides/makefiles/PS/general_make.md create mode 100644 slides/makefiles/PS/omni_makefile create mode 120000 slides/makefiles/examples/omni_makefile diff --git a/slides/makefiles/PS/general_make.md b/slides/makefiles/PS/general_make.md new file mode 100644 index 0000000..a15ec96 --- /dev/null +++ b/slides/makefiles/PS/general_make.md @@ -0,0 +1,119 @@ +# Generalizing Makefiles for All Occasions + +- Rules are bad, +- standards are good, +- habits are better. + +*** + +# General Standards + +- `make help` +- `make check` +- `sudo make install` + +**NB:** we separate `make` from `make install` so that the files are not build with the user `root` as the owner. + +*** + +# Service Standards + +- `make backup.tgz` +- `make install` + +## Service Backups in Two Files + +- `configs`: configuration files, all tracked in git. +- `store`: passwords and binary files, not tracked in git. + +## New Abilities Unlocked + +- Open Access Administration. +- Sharing admin configs with hacker spaces. + +*** + +## BEHOLD: The Everything Makefile + +*** + +```make +CONFIGS = $(patsubst /%,%,$(shell cat configs)) +STORE = $(patsubst /%,%,$(shell cat store)) +CP = mkdir -p $(dir $@) && cp -a +IGNORE_FILE = $(shell test -d .git/info && echo .git/info/exclude || echo .gitignore) +GIT_COMMIT = git commit -m"add $@" --no-gpg-sign --no-signoff +SELECTOR != command -v sk || command -v fzy || command -f fzf +.PHONY: all +all: init backup.tgz $(IGNORE_FILE) +backup.tgz: $(CONFIGS) $(STORE) + tar czf $@ $^ +$(IGNORE_FILE): store + echo $(STORE) backup.tgz | tr ' ' '\n' > $@ +.PHONY: init +init: configs store +configs store: + while con="$$(find /var /etc/ /sys/ -maxdepth 2 -mindepth 1 -type f 2>/dev/null | $(SELECTOR) -p "Select files for $@\nPress Ctrl+d once done")"; do \ + echo "$$con"; \ + done > $@ +$(CONFIGS): %: /% + $(CP) $< $@ + git add $@ + $(GIT_COMMIT) + $(info made git commit for $@) +$(STORE): %: /% + $(CP) $< $@ +clean: + $(RM) -r $(CONFIGS) $(STORE) backup.tgz +``` + +*** + +## Example: Soft Serve Makefile + +
+The `configs` file: + +``` +/etc/soft-serve.conf +/var/lib/soft-serve/data/config.yaml +/var/lib/soft-serve/data/file +/etc/nginx/sites-enabled/soft.dmz.rs +/etc/nginx/sites-available/soft.dmz.rs +``` + +
+The `store` file: + +``` +/var/lib/soft-serve/data/lfs +/var/lib/soft-serve/data/repo +/var/lib/soft-serve/data/soft +/etc/letsencrypt/archive/soft +/etc/letsencrypt/live/soft.dm +/var/lib/soft-serve/data/ssh/ +``` + +*** + +# Other Build Systems + +> "*What if I want to use this other thing, instead of a makefile?" + +*** + +# Other Build Systems (Sans Heresy) + +> "*What if I want to use this other thing, instead of a makefile?" + +- Easy: just use a Makefile. + + +```make + +[ ... ] + +public/: src/ + python build_pages.py +``` + diff --git a/slides/makefiles/PS/omni_makefile b/slides/makefiles/PS/omni_makefile new file mode 100644 index 0000000..623949c --- /dev/null +++ b/slides/makefiles/PS/omni_makefile @@ -0,0 +1,34 @@ +CONFIGS = $(patsubst /%,%,$(shell cat configs)) +STORE = $(patsubst /%,%,$(shell cat store)) +CP = mkdir -p $(dir $@) && cp -a +IGNORE_FILE = $(shell test -d .git/info && echo .git/info/exclude || echo .gitignore) +GIT_COMMIT = git commit -m"add $@" --no-gpg-sign --no-signoff +SELECTOR != command -v sk || command -v fzy || command -f fzf + +.PHONY: all +all: init backup.tgz $(IGNORE_FILE) + +backup.tgz: $(CONFIGS) $(STORE) + tar czf $@ $^ + +$(IGNORE_FILE): store + echo $(STORE) backup.tgz | tr ' ' '\n' > $@ + +.PHONY: init +init: configs store + +configs store: + while con="$$(find /var /etc/ /sys/ -maxdepth 2 -mindepth 1 -type f 2>/dev/null | $(SELECTOR) -p "Select files for $@\nPress Ctrl+d once done")"; do \ + echo "$$con"; \ + done > $@ + +$(CONFIGS): %: /% + $(CP) $< $@ + git add $@ + $(GIT_COMMIT) + $(info made git commit for $@) +$(STORE): %: /% + $(CP) $< $@ + +clean: + $(RM) -r $(CONFIGS) $(STORE) backup.tgz diff --git a/slides/makefiles/examples/omni_makefile b/slides/makefiles/examples/omni_makefile new file mode 120000 index 0000000..16537f8 --- /dev/null +++ b/slides/makefiles/examples/omni_makefile @@ -0,0 +1 @@ +../PS/omni_makefile \ No newline at end of file