summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile67
1 files changed, 23 insertions, 44 deletions
diff --git a/Makefile b/Makefile
index 35586da..35294b4 100644
--- a/Makefile
+++ b/Makefile
@@ -140,16 +140,26 @@ update-submodules:
140install-submodules: cmd=install 140install-submodules: cmd=install
141install-submodules: update-submodules $(INSTALL_SUBMODULES) 141install-submodules: update-submodules $(INSTALL_SUBMODULES)
142 142
143rootfs = samizdat 143rootfs = samizdat.btrfs
144export rootfs 144patchfs = $(patsubst %.btrfs,%.patch.btrfs,$(rootfs))
145rootfs_verity = rootfs/$(rootfs).verity
145 146
146.PHONY: rootfs 147.PHONY: rootfs rootfs-deps
147rootfs: 148rootfs-deps:
148 [ -e install-submodules-stamp ] || make install-submodules-stamp 149 [ -e install-submodules-stamp ] || make install-submodules-stamp
149 [ -e install-stamp ] || $(SUDO_MAKE) install-stamp 150 [ -e install-stamp ] || $(SUDO_MAKE) install-stamp
150 $(MAKE) -C rootfs 151
152btrfs_images = $(addprefix rootfs/, $(rootfs) $(patchfs))
153rootfs: rootfs-deps $(btrfs_images) $(rootfs_verity)
151 sudo mkdir -p /srv/nbd 154 sudo mkdir -p /srv/nbd
152 sudo ln -sf "$$PWD"/rootfs/$(rootfs).btrfs /srv/nbd/samizdat.btrfs 155 sudo ln -sf "$$PWD"/rootfs/$(rootfs) /srv/nbd/samizdat.btrfs
156ifneq (,$(patchfs))
157 sudo ln -sf "$$PWD"/rootfs/$(patchfs) /srv/nbd/samizdat.patch.btrfs
158endif
159
160FORCE:
161$(btrfs_images): FORCE
162 $(MAKE) -C rootfs $(notdir $@)
153 163
154boot: rootfs 164boot: rootfs
155 sudo SLOW_BOOT=y qemu.sh 165 sudo SLOW_BOOT=y qemu.sh
@@ -193,12 +203,14 @@ get_loop_dev="$$(sudo losetup -n -O name -j $@~tmp)"
193get_backing_file="$$(sudo losetup -n -O back-file -j $@~tmp)" 203get_backing_file="$$(sudo losetup -n -O back-file -j $@~tmp)"
194get_min_size="$$(btrfs inspect-internal min-dev-size --id 1 $@.mnt | (read b _; echo $$b))" 204get_min_size="$$(btrfs inspect-internal min-dev-size --id 1 $@.mnt | (read b _; echo $$b))"
195 205
196%.btrfs.verity: %.btrfs 206%.verity: %
197 sudo veritysetup format $< $@ > $@.log 207 sudo veritysetup format $< $@~tmp > $@.log~tmp
208 mv $@.log~tmp $@.log
209 mv $@~tmp $@
198 sudo chmod 644 $@ 210 sudo chmod 644 $@
199 h=$$(sed -ne 's/^Root hash:[ \t]*//p' $@.log) && [ "$$h" ] 211 h=$$(sed -ne 's/^Root hash:[ \t]*//p' $@.log) && [ "$$h" ]
200 212
201%.btrfs.verity.log.asc: %.btrfs.verity.log 213%.verity.log.asc: %.verity.log
202 sudo gpg --armor --detach-sign $^ 214 sudo gpg --armor --detach-sign $^
203 215
204rootfs/samizdat.seed.btrfs: rootfs/samizdat.btrfs 216rootfs/samizdat.seed.btrfs: rootfs/samizdat.btrfs
@@ -218,8 +230,6 @@ else
218 mv $@~tmp $@ 230 mv $@~tmp $@
219endif 231endif
220 232
221FORCE:
222
223debian_dist := $(shell lsb_release -cs) 233debian_dist := $(shell lsb_release -cs)
224 234
225apt_list_files = $(addprefix /./var/lib/apt/lists/, \ 235apt_list_files = $(addprefix /./var/lib/apt/lists/, \
@@ -231,37 +241,10 @@ apt_list_files = $(addprefix /./var/lib/apt/lists/, \
231 241
232stale = [ ! -e $@ ] || [ $$(( $$(date +%s) - $$(date -r $@ +%s) )) -gt 36000 ] 242stale = [ ! -e $@ ] || [ $$(( $$(date +%s) - $$(date -r $@ +%s) )) -gt 36000 ]
233 243
234apt-get-update-stamp: FORCE 244.PHONY: apt-get-update-stamp
245apt-get-update-stamp:
235 @if $(stale); then set -x; sudo apt-get update && touch $@; fi 246 @if $(stale); then set -x; sudo apt-get update && touch $@; fi
236 247
237rootfs/samizdat.patch.btrfs: rootfs/samizdat.seed.btrfs \
238 $(if $(INTERACTIVE_CHROOT),FORCE,rootfs/patchroot.sh)
239ifneq ($(shell id -u),0)
240 $(SUDO_MAKE) $@
241else
242 rm -f $@~tmp
243 touch $@~tmp
244 fallocate -l $(samizdat_btrfs_patch_size) $@~tmp
245 test -d $@.mnt || mkdir $@.mnt
246 ! mountpoint -q $@.mnt || umount $@.mnt
247 mount -o compress,ro -t btrfs $< $@.mnt
248 a=$(get_loop_dev); [ -z "$$a" ] || losetup -d $$a
249 losetup -f $@~tmp
250 btrfs device add $(get_loop_dev) $@.mnt
251 mount -o compress,rw,remount $@.mnt
252 $(SUDO_MAKE) apt-get-update-stamp
253 rsync -Ra $(apt_list_files) $@.mnt/
254ifdef INTERACTIVE_CHROOT
255 chroot $@.mnt bash -i
256else
257 chroot $@.mnt sh < rootfs/patchroot.sh
258endif
259 umount $@.mnt
260 losetup -f $<
261 btrfstune -S1 $@~tmp
262 mv $@~tmp $@
263endif
264
265samizdat.iso: patched.iso 248samizdat.iso: patched.iso
266 cp --reflink $< $@ 249 cp --reflink $< $@
267 250
@@ -326,10 +309,6 @@ rootfs/seed.iso: $(addprefix rootfs/samizdat.seed.btrf, s \
326 -follow default 309 -follow default
327 mv $@~tmp $@ 310 mv $@~tmp $@
328 311
329rootfs/samizdat.btrfs:
330 make -C rootfs
331
332
333.PHONY: install 312.PHONY: install
334install: 313install:
335 [ -e install-submodules-stamp ] || make install-submodules-stamp 314 [ -e install-submodules-stamp ] || make install-submodules-stamp