Makefile 2.49 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
	# remove passwordless login for root (see CVE-2019-5021 for reference)
	sed -i -e 's/^root::/root:!:/' "$(BUILDDIR)/etc/shadow"

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

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

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
36
37
define dockerfile
	sed -e "s|TEMPLATE_ROOTFS_FILE|$(1).tar.xz|" \
38
	    -e "s|TEMPLATE_ROOTFS_RELEASE_URL|Local build|" \
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
39
40
41
42
	    -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
43

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
44
45
46
.PHONY: clean
clean:
	rm -rf $(BUILDDIR) $(OUTPUTDIR)
Pierre Schmitz's avatar
Pierre Schmitz committed
47

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
48
49
$(OUTPUTDIR)/base.tar.xz:
	$(call rootfs,base,base)
50

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

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

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

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

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