forked from TheSin-/rpi-img-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrootfs.mak
101 lines (93 loc) · 4.71 KB
/
rootfs.mak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
include common.mk
.PHONY: all
all: build
.PHONY: clean
clean: delete-rootfs
umount mnt || true
rm -rf $(IMAGE_FILE)*.img *.img.tmp mnt multistrap.list *.example plugins.txt
.PHONY: distclean
distclean: delete-rootfs
rm -rf $(wildcard $(ROOTFS_DIR).base $(ROOTFS_DIR).base.tmp)
.PHONY: delete-rootfs
delete-rootfs:
if mountpoint -q $(ROOTFS_DIR)/proc ; then umount $(ROOTFS_DIR)/proc ; fi
if mountpoint -q $(ROOTFS_DIR)/sys ; then umount $(ROOTFS_DIR)/sys ; fi
if mountpoint -q $(ROOTFS_DIR)/dev ; then umount $(ROOTFS_DIR)/dev ; fi
rm -rf $(wildcard $(ROOTFS_DIR) uInitrd)
.PHONY: build
build: $(IMAGE_FILE)
$(ROOTFS_DIR).base:
rm -f plugins.txt
for i in plugins/*; do if [ -f $$i/packages -o -f $$i/preinst -o -f $$i/postinst -o -d $$i/files -o -d $$i/patches ]; then echo $$i >> plugins.txt; fi; done
for i in plugins/$(DIST)/*; do if [ -f $$i/packages -o -f $$i/preinst -o -f $$i/postinst -o -d $$i/files -o -d $$i/patches ]; then echo $$i >> plugins.txt; fi; done
for j in $(REPOS); do for i in plugins/$$j/*; do if [ -f $$i/baseonly -a $$j != $(REPOBASE) ]; then continue; fi; if [ -f $$i/packages -o -f $$i/preinst -o -f $$i/postinst -o -d $$i/files -o -d $$i/patches ]; then echo $$i >> plugins.txt; fi; done; done
@echo
@echo "Building $(IMAGE_FILE)_$(TIMESTAMP).img"
@echo "Repositories: $(REPOS)"
@echo "Base repositories: $(REPOBASE)"
@echo "Distribution: $(DIST)"
@echo "Repository architecture: $(DIST_ARCH)"
@echo "System architecture: $(ARCH)"
@echo "Plugins: $$(cat plugins.txt | xargs | sed -e 's;plugins/;;g' -e 's; ;, ;g')"
@echo
@echo -n "5..."
@sleep 1
@echo -n "4..."
@sleep 1
@echo -n "3..."
@sleep 1
@echo -n "2..."
@sleep 1
@echo -n "1..."
@sleep 1
@echo "OK"
if test -d "[email protected]"; then rm -rf "[email protected]" ; fi
mkdir -p [email protected]
cat $(shell echo multistrap.list.in; for i in $(REPOS); do echo repos/$$i/multistrap.list.in; done | xargs) | sed -e 's,__REPOSITORIES__,$(REPOS),g' -e 's,__SUITE__,$(DIST),g' -e 's,__ARCH__,$(ARCH),g' > multistrap.list
multistrap --arch $(DIST_ARCH) --file multistrap.list --dir [email protected]
cp `which $(QEMU)` [email protected]/usr/bin
mkdir -p [email protected]/usr/share/fatboothack/overlays
if test ! -f [email protected]/etc/resolv.conf; then cp /etc/resolv.conf [email protected]/etc/; fi
# No idea why multistrap does this
rm -f [email protected]/lib64
ln -s /proc/mounts [email protected]/etc/mtab
mv [email protected] $@
touch $@
$(ROOTFS_DIR): $(ROOTFS_DIR).base
rsync --quiet --archive --devices --specials --hard-links --acls --xattrs --sparse $(ROOTFS_DIR).base/* $@
mkdir $@/postinst
touch $@/packages.txt
for i in $$(cat plugins.txt | xargs); do echo "Processing $$i..."; if [ -d $$i/files ]; then echo " - found files ... adding"; cd $$i/files && find . -type f ! -name '*~' -exec cp --preserve=mode,timestamps --parents \{\} $@ \;; cd $(BASE_DIR); fi; if [ -f $$i/packages ]; then echo " - found packages ... adding"; echo -n "$$(cat $$i/packages | sed -e "s,__ARCH__,$(ARCH),g" | xargs) " >> $@/packages.txt; fi; if [ -f $$i/preinst ]; then chmod +x $$i/preinst; echo " - found preinst ... running"; ./$$i/preinst; fi; if [ -f $$i/postinst ]; then echo " - found postinst ... adding"; cp $$i/postinst $@/postinst/$$(dirname $$i/postinst | rev | cut -d/ -f1 | rev)-$$(cat /dev/urandom | LC_CTYPE=C tr -dc "a-zA-Z0-9" | head -c 5); fi; done
chmod +x $@/postinst/*
cp postinstall $@
mount -o bind /proc $@/proc
mount -o bind /sys $@/sys
mount -o bind /dev $@/dev
chroot $@ /bin/bash -c "/postinstall $(DIST) $(ARCH) $(LOCALE) $(UNAME) $(UPASS) $(RPASS) $(INC_REC) $(UBOOT_DIR)"
for i in $$(cat plugins.txt | xargs); do if [ -d $$i/patches ]; then for j in $$i/patches/*; do patch -p0 -d $@ < $$j; done; fi; done
if ls plugins/*/files/etc/hostname 1> /dev/null 2>&1; then cp plugins/*/files/etc/hostname $@/etc/hostname; fi
if ls plugins/$(DIST)/*/files/etc/hostname 1> /dev/null 2>&1; then cp plugins/$(DIST)/*/files/etc/hostname $@/etc/hostname; fi
if [ -f $@/etc/hostname ]; then if ! grep "^127.0.0.1\s*$$(cat $@/etc/hostname)\s*" $@/etc/hosts > /dev/null ; then sed -i "1i 127.0.0.1\\t$$(cat $@/etc/hostname)" $@/etc/hosts; fi; fi
umount $@/proc
umount $@/sys
umount $@/dev
rm -f $@/packages.txt
rm -f $@/postinstall
rm -rf $@/postinst/
rm -f $@/usr/bin/$(QEMU)
rm -f $@/etc/resolv.conf
touch $@
$(IMAGE_FILE): $(ROOTFS_DIR)
if test -f "[email protected]"; then rm "[email protected]" ; fi
./createimg [email protected] $(BOOT_MB) $(ROOT_MB) $(BOOT_DIR) $(ROOTFS_DIR) "$(ROOT_DEV)"
mv [email protected] $@_$(TIMESTAMP).img
@echo
@echo "Built $(IMAGE_FILE)_$(TIMESTAMP).img"
@echo "Repositories: $(REPOS)"
@echo "Base repositories: $(REPOBASE)"
@echo "Distribution: $(DIST)"
@echo "Repository architecture: $(DIST_ARCH)"
@echo "System architecture: $(ARCH)"
@echo "Plugins: $$(cat plugins.txt | xargs | sed -e 's;plugins/;;g' -e 's; ;, ;g')"
@echo
touch $@_$(TIMESTAMP).img