Makefile 2.59 KB
Newer Older
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
1
2
BUILDDIR=$(shell pwd)/build
OUTPUTDIR=$(shell pwd)/output
Pierre Schmitz's avatar
Pierre Schmitz committed
3

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
4
5
6
define rootfs
	mkdir -vp $(BUILDDIR)/alpm-hooks/usr/share/libalpm/hooks
	find /usr/share/libalpm/hooks -exec ln -sf /dev/null $(BUILDDIR)/alpm-hooks{} \;
Santiago Torres's avatar
Santiago Torres committed
7

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
8
9
10
	mkdir -vp $(BUILDDIR)/var/lib/pacman/ $(OUTPUTDIR)
	install -Dm644 /usr/share/devtools/pacman-extra.conf $(BUILDDIR)/etc/pacman.conf
	cat pacman-conf.d-noextract.conf >> $(BUILDDIR)/etc/pacman.conf
11

Santiago Torres's avatar
Santiago Torres committed
12
	fakechroot -- fakeroot -- pacman -Sy -r $(BUILDDIR) \
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
13
14
		--noconfirm --dbpath $(BUILDDIR)/var/lib/pacman \
		--config $(BUILDDIR)/etc/pacman.conf \
15
		--noscriptlet \
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
16
		--hookdir $(BUILDDIR)/alpm-hooks/usr/share/libalpm/hooks/ $(2)
17
18
19
20

	cp --recursive --preserve=timestamps --backup --suffix=.pacnew rootfs/* $(BUILDDIR)/

fakechroot -- fakeroot -- chroot $(BUILDDIR) update-ca-trust
21
22
23
24
25
	fakechroot -- fakeroot -- chroot $(BUILDDIR) locale-gen
	fakechroot -- fakeroot -- chroot $(BUILDDIR) sh -c 'pacman-key --init && pacman-key --populate archlinux && bash -c "rm -rf etc/pacman.d/gnupg/{openpgp-revocs.d/,private-keys-v1.d/,pubring.gpg~,gnupg.S.}*"'

	ln -fs /usr/lib/os-release $(BUILDDIR)/etc/os-release

26
27
28
	# add system users
	fakechroot -- fakeroot -- chroot $(BUILDDIR) /usr/bin/systemd-sysusers --root "/"

29
30
31
	# remove passwordless login for root (see CVE-2019-5021 for reference)
	sed -i -e 's/^root::/root:!:/' "$(BUILDDIR)/etc/shadow"

32
33
	# fakeroot to map the gid/uid of the builder process to root
	# fixes #22
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
34
	fakeroot -- tar --numeric-owner --xattrs --acls --exclude-from=exclude -C $(BUILDDIR) -c . -f $(OUTPUTDIR)/$(1).tar
Pierre Schmitz's avatar
Pierre Schmitz committed
35

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
36
37
	cd $(OUTPUTDIR); xz -9 -T0 -f $(1).tar; sha256sum $(1).tar.xz > $(1).tar.xz.SHA256
endef
38

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
39
40
define dockerfile
	sed -e "s|TEMPLATE_ROOTFS_FILE|$(1).tar.xz|" \
41
	    -e "s|TEMPLATE_ROOTFS_RELEASE_URL|Local build|" \
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
42
43
44
45
	    -e "s|TEMPLATE_ROOTFS_URL|file:///$(1).tar.xz|" \
	    -e "s|TEMPLATE_ROOTFS_HASH|$$(cat $(OUTPUTDIR)/$(1).tar.xz.SHA256)|" \
	    Dockerfile.template > $(OUTPUTDIR)/Dockerfile.$(1)
endef
46

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
47
48
49
.PHONY: clean
clean:
	rm -rf $(BUILDDIR) $(OUTPUTDIR)
Pierre Schmitz's avatar
Pierre Schmitz committed
50

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
51
52
$(OUTPUTDIR)/base.tar.xz:
	$(call rootfs,base,base)
53

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
54
$(OUTPUTDIR)/base-devel.tar.xz:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
55
	$(call rootfs,base-devel,base base-devel)
56

57
$(OUTPUTDIR)/Dockerfile.base: $(OUTPUTDIR)/base.tar.xz
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
58
	$(call dockerfile,base)
59

60
$(OUTPUTDIR)/Dockerfile.base-devel: $(OUTPUTDIR)/base-devel.tar.xz
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
61
	$(call dockerfile,base-devel)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
62
63

.PHONY: docker-image-base
64
image-base: $(OUTPUTDIR)/Dockerfile.base
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
65
	docker build -f $(OUTPUTDIR)/Dockerfile.base -t archlinux/archlinux:base $(OUTPUTDIR)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
66
67

.PHONY: docker-image-base-devel
68
image-base-devel: $(OUTPUTDIR)/Dockerfile.base-devel
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
69
	docker build -f $(OUTPUTDIR)/Dockerfile.base-devel -t archlinux/archlinux:base-devel $(OUTPUTDIR)