Makefile 2.06 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
Santiago Torres's avatar
Santiago Torres committed
11
	fakechroot -- fakeroot -- pacman -Sy -r $(BUILDDIR) \
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
12
13
		--noconfirm --dbpath $(BUILDDIR)/var/lib/pacman \
		--config $(BUILDDIR)/etc/pacman.conf \
14
		--noscriptlet \
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
15
		--hookdir $(BUILDDIR)/alpm-hooks/usr/share/libalpm/hooks/ $(2)
16
	cp --recursive --preserve=timestamps --backup --suffix=.pacnew rootfs/* $(BUILDDIR)/
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
17

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

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

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

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
28
29
30
31
32
33
define dockerfile
	sed -e "s|TEMPLATE_ROOTFS_FILE|$(1).tar.xz|" \
	    -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
34

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
35
36
37
.PHONY: clean
clean:
	rm -rf $(BUILDDIR) $(OUTPUTDIR)
Pierre Schmitz's avatar
Pierre Schmitz committed
38

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
39
40
$(OUTPUTDIR)/base.tar.xz:
	$(call rootfs,base,base)
41

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
42
$(OUTPUTDIR)/base-devel.tar.xz:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
43
	$(call rootfs,base-devel,base base-devel)
44

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
45
46
$(OUTPUTDIR)/Dockerfile.base:
	$(call dockerfile,base)
47

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
48
49
$(OUTPUTDIR)/Dockerfile.base-devel:
	$(call dockerfile,base-devel)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
50
51

.PHONY: docker-image-base
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
52
53
image-base: $(OUTPUTDIR)/base.tar.xz $(OUTPUTDIR)/Dockerfile.base
	docker build -f $(OUTPUTDIR)/Dockerfile.base -t archlinux/archlinux:base $(OUTPUTDIR)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
54
55

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