qubes-salt-stuff/Makefile
2025-10-28 00:19:22 +01:00

92 lines
2.5 KiB
Makefile

SHELL = /bin/bash
.POSIX_SHELL:
ifneq (,$(wildcard .bundle-env))
include .bundle-env
endif
ifeq (root,$(shell whoami))
check-root = @true
else
check-root = $(error this target requires root)
endif
ifeq (dom0,$(shell hostname))
check-dom0 = @true
check-domu = $(error this target must be run in the guest qube)
else
check-dom0 = $(error this target must be run in dom0)
check-domu = @true
endif
BUNDLEIN := .bundles/qubes-mgmt-salt
ifeq (apply, $(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "run"
APPLY_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(APPLY_ARGS):;@:)
endif
clean-workdir = git init -q -b $* && git diff --quiet && git diff --cached --quiet || (echo 'dirty tree; check git status' && false)
.PHONY: guard-domu
guard-domu:
@ if [ "`hostname`" != "`qubesdb-read /name`" ]; then \
echo "This task must be run in a guest domain"; \
exit 1; \
fi
.PHONY: create-bundle
create-bundle: guard-domu
mkdir -p .bundles
git bundle create - --all > .bundles/qubes-mgmt-salt
# cures common weird states (thanks xyhhx for the tip)
# also try `sudo rm -rf /var/cache/salt /srv/salt/_tops/*`
.PHONY: cure
cure:
sudo rm -rf /var/cache/salt
sudo rm -rf /srv/salt/_tops/user
qubesctl saltutil.clear_cache
qubesctl saltutil.sync_all
.PHONY: pull pull/%
pull: pull/$(shell git branch --show-current)
pull/%:
echo "check dom0"
$(check-dom0)
echo "clean workdir"
$(clean-workdir)
echo "creating bundle"
qvm-run -p $(GUEST) "cd $(GUEST_REPO) && make create-bundle" </dev/null
qvm-run -p $(GUEST) "cat $(GUEST_REPO)/.bundles/qubes-mgmt-salt" </dev/null >$(BUNDLEIN)
git remote add $(GUEST) $(BUNDLEIN) || true
git pull $(GUEST) $*:$*
qvm-run -p $(GUEST) "cd $(GUEST_REPO) && git update-ref refs/remotes/dom0/$* $*" </dev/null
@echo "updated branch $* from $(GUEST)"
install:
install -D -oroot -groot -m0644 conf/z_user.conf /etc/salt/minion.d/z_user.conf
install -D -oroot -groot -m0644 conf/overrides.conf /usr/local/etc/salt/minion.d/overrides.conf
mkdir -p /srv/user
ln -s $(CURDIR)/salt /srv/user/salt
.PHONY: apply
apply:
install -D -oroot -groot -m0644 conf/z_user.conf /etc/salt/minion.d/z_user.conf
install -D -oroot -groot -m0644 conf/overrides.conf /usr/local/etc/salt/minion.d/overrides.conf
qubesctl top.enable topd
qubesctl top.enable $(APPLY_ARGS)
qubesctl --show-output --force-color --skip-dom0 --targets templates state.apply $(APPLY_ARGS)
qubesctl top.disable $(APPLY_ARGS)