150 lines
5.6 KiB
Makefile
150 lines
5.6 KiB
Makefile
# Copyright (C) 2023-2024 Umorpha Systems
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# Entrypoint/config ############################################################
|
|
|
|
SHELL = bash -euE -o pipefail
|
|
osi-tools = $(CURDIR)/osi-tools
|
|
PATH := $(osi-tools)/bin:$(PATH)
|
|
|
|
all: images/eggman.bootstrap.iso
|
|
all: images/luigi.bootstrap.iso
|
|
all: images/mario.bootstrap.iso
|
|
all: images/sonic.bootstrap.iso
|
|
all: images/thwomp.bootstrap.iso
|
|
all: images/orangepi.sh # gpt.img
|
|
test -z '$(filter-out $(addsuffix .sh,$(subst ., ,$^)) images/bootstrap.sh %.secrets.sh,$(wildcard images/*.sh))'
|
|
.PHONY: all
|
|
|
|
.NOTINTERMEDIATE:
|
|
.DELETE_ON_ERROR:
|
|
|
|
MAKEFLAGS += --no-builtin-rules
|
|
|
|
# Nothing here is parallel-unsafe, but it just makes the output (and
|
|
# especially `sudo` prompts) hard to read.
|
|
.NOTPARALLEL:
|
|
|
|
define NL
|
|
|
|
|
|
endef
|
|
|
|
# Dependency magic #############################################################
|
|
|
|
# Files that modules depend on
|
|
|
|
build-deps/modules/umorpha-bootstrap.sh = bin/umorpha-install
|
|
build-deps/modules/umorpha-bootstrap.sh += bin/umorpha-mount
|
|
|
|
secret-deps/modules/service-gitea.sh = secrets/gitea-infomaniak-clientid.txt
|
|
secret-deps/modules/service-gitea.sh += secrets/gitea-infomaniak-clientsecret.txt
|
|
|
|
build-deps/modules/service-bookstack.sh = modules/0001-Oidc-Properly-query-the-UserInfo-Endpoint.patch
|
|
secret-deps/modules/service-bookstack.sh = secrets/bookstack-app-key.txt
|
|
secret-deps/modules/service-bookstack.sh += secrets/bookstack-infomaniak-mailaddr.txt
|
|
secret-deps/modules/service-bookstack.sh += secrets/bookstack-infomaniak-mailpassword.txt
|
|
secret-deps/modules/service-bookstack.sh += secrets/bookstack-infomaniak-clientid.txt
|
|
secret-deps/modules/service-bookstack.sh += secrets/bookstack-infomaniak-clientsecret.txt
|
|
|
|
secret-deps/modules/base-eclipse-creds.sh = secrets/eclipse-sshkey.priv
|
|
secret-deps/modules/service-eclipse-leader.sh = secrets/htpasswd.txt
|
|
|
|
secret-deps/modules/service-avatard.sh += secrets/avatard-apikey.txt
|
|
|
|
# Group that should own the secret
|
|
|
|
group/gitea-infomaniak-clientid.txt = gitea
|
|
group/gitea-infomaniak-clientsecret.txt = gitea
|
|
|
|
group/bookstack-app-key.txt = bookstack
|
|
group/bookstack-infomaniak-mailaddr.txt = bookstack
|
|
group/bookstack-infomaniak-mailpassword.txt = bookstack
|
|
group/bookstack-infomaniak-clientid.txt = bookstack
|
|
group/bookstack-infomaniak-clientsecret.txt = bookstack
|
|
|
|
group/eclipse-sshkey.priv = eclipse
|
|
group/htpasswd.txt = http
|
|
|
|
group/avatard-apikey.txt = avatard
|
|
|
|
# Automatic dependencies
|
|
pkg/%/.SRCINFO: pkg/%/PKGBUILD
|
|
cd $(<D) && makepkg --printsrcinfo >.SRCINFO
|
|
deps.mk: images $(filter-out %.secrets.sh,$(wildcard images/*.sh))
|
|
deps.mk: modules $(wildcard modules/*.sh)
|
|
deps.mk: pkg $(patsubst %/PKGBUILD,%/.SRCINFO,$(wildcard pkg/*/PKGBUILD))
|
|
deps.mk: bin/pkgbuild-deps Makefile
|
|
{ \
|
|
echo '# variables: module -> module'; \
|
|
grep -H load_module modules/*.sh|sed -E 's,(.*):.*/(.*)"$$,build-deps/\1 += modules/\2 $$(build-deps/modules/\2),'; \
|
|
echo '# variables: image -> module'; \
|
|
grep -H -o -e '--module=\S*' -- images/*.sh | sed -E 's,images/([^:]*).sh:--module=(.*),build-deps/images/\1.rootfs.img += \2 $$(build-deps/\2),'; \
|
|
echo '# concrete: image -> build-deps'; \
|
|
$(foreach f,$(patsubst %.sh,%.rootfs.img,$(filter images/%.sh,$^)),echo '$f: $$(build-deps/$f)'; \$(NL) ) \
|
|
echo '# concrete: secrets -> secret-deps'; \
|
|
$(foreach f,$(patsubst %.sh,%.rootfs.img,$(filter images/%.sh,$^)),echo '$(patsubst %.rootfs.img,%.secrets.sh,$f): $$(foreach d,$$(build-deps/$f),$$(secret-deps/$$d))'; \$(NL) ) \
|
|
echo '# concrete: image -> package'; \
|
|
grep -H -o -e '--package-file=\S*' -- images/*.sh | sed -E 's,images/([^:]*).sh:--package-file=(.*),images/\1.rootfs.img: \2,'; \
|
|
echo '# concrete: packages'; \
|
|
$(foreach srcinfo,$(filter %/.SRCINFO,$^),bin/pkgbuild-deps $(srcinfo); \$(NL) ) \
|
|
} >$@
|
|
-include deps.mk
|
|
|
|
# Generic pattern rules ########################################################
|
|
|
|
gpt-size/orangepi = 3G
|
|
gpt-type/orangepi = uboot-sunxi
|
|
|
|
images/%.rootfs.img: images/%.sh $(osi-tools)/bin/osi-mk
|
|
rm -f $@
|
|
$< $@
|
|
chmod 444 $@
|
|
|
|
images/%.gpt.img: images/%.rootfs.img bin/umorpha-install bin/umorpha-mount
|
|
rm -f $@
|
|
truncate --size=$(or $(gpt-size/$*),3G) $@
|
|
sudo env PATH=$(CURDIR)/bin:$(PATH) umorpha-install $(or $(gpt-type/$*),bios) images/$*.rootfs.img $@
|
|
chmod 444 $@
|
|
|
|
images/%.bootstrap.iso: images/%.rootfs.img images/bootstrap.rootfs.img bin/mkbootstrapiso
|
|
bin/mkbootstrapiso $< $@
|
|
|
|
images/%.secrets.sh: Makefile deps.mk
|
|
{ \
|
|
echo '#!/bin/sh'; \
|
|
echo 'install -m755 -d /etc/umorpha-secrets'; \
|
|
$(foreach f,$(sort $(filter secrets/%,$^)),val=$$(cat $f); echo "install -m640 --group=$(group/$(notdir $f)) /dev/stdin /etc/umorpha-secrets/$(notdir $f) <<<$${val@Q}"; \$(NL) ) \
|
|
} >$@
|
|
|
|
qemu-bios = qemu-system-x86_64
|
|
qemu-bios += -accel kvm
|
|
qemu-bios += -m 2G
|
|
qemu-bios += -net user,hostfwd=tcp::8022-:22,hostfwd=tcp::8080-:80 -net nic
|
|
|
|
qemu-uefi = $(qemu-bios) -drive if=pflash,format=raw,readonly=on,file=/usr/share/ovmf/x64/OVMF.fd
|
|
|
|
run-bios/%.img: images/%.img
|
|
cp --reflink -- $< $<.tmp
|
|
chmod 644 $<.tmp
|
|
$(qemu-bios) -drive media=disk,if=virtio,format=raw,file=$<.tmp
|
|
run-bios/%.iso: images/%.iso
|
|
truncate --size=3G $<.tmp
|
|
$(qemu-bios) -drive media=disk,if=virtio,format=raw,file=$<.tmp -cdrom $<
|
|
.PHONY: run-bios/%
|
|
|
|
run-uefi/%.img: images/%.img
|
|
cp --reflink -- $< $<.tmp
|
|
chmod 644 $<.tmp
|
|
$(qemu-uefi) -drive media=disk,if=virtio,format=raw,file=$<.tmp
|
|
.PHONY: run-ueif/%
|
|
|
|
deploy/%: images/%.bootstrap.iso images/%.secrets.sh vultr/%.sh
|
|
vultr/$*.sh
|
|
.PHONY: deploy/%
|
|
|
|
# Specific rules ###############################################################
|
|
|
|
osi-tools/bin/osi-mk:
|
|
git submodule update --init $(@D)
|