Makefile 5.2 KB
Newer Older
Francesco Bonanno's avatar
Francesco Bonanno committed
1 2 3 4
#!/bin/sh

# (C) 2012-2015 Fathi Boudra <fathi.boudra@linaro.org>

Francesco Bonanno's avatar
Francesco Bonanno committed
5
# (C) 2015-2018 Francesco Bonanno <mibofra@parrotsec.org> , little changes for parrot arm rootfs tarballs.
Francesco Bonanno's avatar
Francesco Bonanno committed
6 7 8 9 10 11

# Calls all necessary live-build programs in the correct order to complete
# the bootstrap, chroot, binary, and source stage.

# You need live-build package installed and superuser privileges.

12
BUILDTYPE=$$(cat buildtype)
13
BUILD_NUMBER_DATE=$$(date +'%Y%m%d')
14
BUILD_NUMBER=$$(cat build_num)
15
BASEIMG=parrotsec-$(BUILDTYPE)-armhf-rpi
Francesco Bonanno's avatar
Francesco Bonanno committed
16 17
IMAGEPREFIX=$(BASEIMG)-$(BUILD_NUMBER)
LOGFILE=$(IMAGEPREFIX).build-log.txt
Francesco Bonanno's avatar
Francesco Bonanno committed
18
LOGFILEIMG=$(IMAGEPREFIX).build-log-img.txt
Francesco Bonanno's avatar
Francesco Bonanno committed
19 20 21 22
CONFIGFILE=$(IMAGEPREFIX).config.tar.bz2
LISTFILE=$(IMAGEPREFIX).contents
CHROOTFILE=$(IMAGEPREFIX).files
PKGSFILE=$(IMAGEPREFIX).packages
23
TARFILE=$(IMAGEPREFIX).tar
Francesco Bonanno's avatar
Francesco Bonanno committed
24 25 26 27 28 29 30 31
MD5SUMSFILE=$(IMAGEPREFIX).md5sums.txt
SHA1SUMSFILE=$(IMAGEPREFIX).sha1sums.txt
IMAGENAME=$(IMAGEPREFIX).img
MD5SUMIMG=$(IMAGENAME).md5sum.txt
SHA1SUMIMG=$(IMAGENAME).sha1sum.txt
TARXZFILE=$(IMAGENAME).tar.xz
MD5SUMTARXZFILE=$(TARXZFILE).md5sum.txt
SHA1SUMTARXZFILE=$(TARXZFILE).sha1sum.txt
32
LOOPDEVICE=$$(losetup -O name -j $(IMAGENAME) | tail -1)
Francesco Bonanno's avatar
Francesco Bonanno committed
33 34 35
BLOCKDEVICE=

all:
36
	echo $(BUILD_NUMBER_DATE) > build_num
37
	./keyring-updater.sh
38
	set -e; taskset 0x1 sudo lb build 2>&1 | tee $(LOGFILE)
39
	if [ -f live-image-armhf.tar.tar ]; then \
Francesco Bonanno's avatar
Francesco Bonanno committed
40 41 42 43
		tar -jcf $(CONFIGFILE) auto/ config/ configure; \
		sudo mv live-image-armhf.contents $(LISTFILE); \
		sudo mv chroot.files $(CHROOTFILE); \
		sudo mv chroot.packages.install $(PKGSFILE); \
44 45 46
		sudo mv live-image-armhf.tar.tar $(TARFILE); \
		md5sum $(LOGFILE) $(CONFIGFILE) $(LISTFILE) $(CHROOTFILE) $(PKGSFILE) $(TARFILE) > $(MD5SUMSFILE); \
		sha1sum $(LOGFILE) $(CONFIGFILE) $(LISTFILE) $(CHROOTFILE) $(PKGSFILE) $(TARFILE) > $(SHA1SUMSFILE); \
Francesco Bonanno's avatar
Francesco Bonanno committed
47
		set -e; sudo ./build_parrotsec_image.sh 2>&1 | tee $(LOGFILEIMG); \
48
	fi
Francesco Bonanno's avatar
Francesco Bonanno committed
49 50 51 52 53 54

	if [ -f parrotsec-rpi/parrot-armhf-image.img ]; then \
		sudo mv parrotsec-rpi/parrot-armhf-image.img $(IMAGENAME); \
		sudo mv parrotsec-rpi/parrot-armhf-image.img.md5sum.txt $(MD5SUMIMG); \
		sudo mv parrotsec-rpi/parrot-armhf-image.img.sha1sum.txt $(SHA1SUMIMG); \
		sleep 1; \
55
		XZ_OPT=-9 tar cfJ $(TARXZFILE) $(IMAGENAME) $(MD5SUMIMG) $(SHA1SUMIMG) $(LOGFILEIMG); \
Francesco Bonanno's avatar
Francesco Bonanno committed
56
		sudo rm -rf $(IMAGENAME) $(MD5SUMIMG) $(SHA1SUMIMG) $(LOGFILEIMG); \
Francesco Bonanno's avatar
Francesco Bonanno committed
57 58
		md5sum $(TARXZFILE) > $(MD5SUMTARXZFILE); \
		sha1sum $(TARXZFILE) > $(SHA1SUMTARXZFILE); \
Francesco Bonanno's avatar
Francesco Bonanno committed
59 60 61 62 63
	fi

	if [ ! -f $(TARXZFILE) ]; then \
		echo "Error!!! Something went wrong, check the logs please"; \
		exit 1; \
64
	fi
Francesco Bonanno's avatar
Francesco Bonanno committed
65

66
# Used in gitlab CI Debian container
67
all_gitlabci:
68
	sudo losetup -D
69
	echo $(BUILD_NUMBER_DATE) > build_num
70
	./keyring-updater.sh
71
	set -e; taskset 0x1 sudo lb build 2>&1 | tee $(LOGFILE)
72
	if [ -f live-image-armhf.tar.tar ]; then \
73
		tar -jcf $(CONFIGFILE) auto/ config/ configure; \
74 75 76
		sudo mv live-image-armhf.contents $(LISTFILE); \
		sudo mv chroot.files $(CHROOTFILE); \
		sudo mv chroot.packages.install $(PKGSFILE); \
77 78 79
		sudo mv live-image-armhf.tar.tar $(TARFILE); \
		md5sum $(LOGFILE) $(CONFIGFILE) $(LISTFILE) $(CHROOTFILE) $(PKGSFILE) $(TARFILE) > $(MD5SUMSFILE); \
		sha1sum $(LOGFILE) $(CONFIGFILE) $(LISTFILE) $(CHROOTFILE) $(PKGSFILE) $(TARFILE) > $(SHA1SUMSFILE); \
80
		set -e; sudo ./build_parrotsec_image_CI.sh 2>&1 | tee $(LOGFILEIMG); \
81
	fi
82

83 84 85 86 87 88 89 90 91
	if [ -f parrotsec-rpi/parrot-armhf-image.img ]; then \
		sudo mv parrotsec-rpi/parrot-armhf-image.img $(IMAGENAME); \
		sudo mv parrotsec-rpi/parrot-armhf-image.img.md5sum.txt $(MD5SUMIMG); \
		sudo mv parrotsec-rpi/parrot-armhf-image.img.sha1sum.txt $(SHA1SUMIMG); \
		sleep 1; \
		XZ_OPT=-9 tar cfJ $(TARXZFILE) $(IMAGENAME) $(MD5SUMIMG) $(SHA1SUMIMG) $(LOGFILEIMG); \
		sudo rm -rf $(IMAGENAME) $(MD5SUMIMG) $(SHA1SUMIMG) $(LOGFILEIMG); \
		md5sum $(TARXZFILE) > $(MD5SUMTARXZFILE); \
		sha1sum $(TARXZFILE) > $(SHA1SUMTARXZFILE); \
Francesco Bonanno's avatar
Francesco Bonanno committed
92 93 94 95 96
	fi

	if [ ! -f $(TARXZFILE) ]; then \
		echo "Error!!! Something went wrong, check the logs please"; \
		exit 1; \
97
	fi
98

Francesco Bonanno's avatar
Francesco Bonanno committed
99
finalize:
100
	if [ -f live-image-armhf.tar.tar ]; then \
Francesco Bonanno's avatar
Francesco Bonanno committed
101 102 103 104
		tar -jcf $(CONFIGFILE) auto/ config/ configure; \
		sudo mv live-image-armhf.contents $(LISTFILE); \
		sudo mv chroot.files $(CHROOTFILE); \
		sudo mv chroot.packages.install $(PKGSFILE); \
105 106 107
		sudo mv live-image-armhf.tar.tar $(TARFILE); \
		md5sum $(LOGFILE) $(CONFIGFILE) $(LISTFILE) $(CHROOTFILE) $(PKGSFILE) $(TARFILE) > $(MD5SUMSFILE); \
		sha1sum $(LOGFILE) $(CONFIGFILE) $(LISTFILE) $(CHROOTFILE) $(PKGSFILE) $(TARFILE) > $(SHA1SUMSFILE); \
Francesco Bonanno's avatar
Francesco Bonanno committed
108 109
	fi

110
	if [ ! -f $(TARFILE) ]; then \
Francesco Bonanno's avatar
Francesco Bonanno committed
111 112
		echo "Error!!! Something went wrong, check the logs please"; \
		exit 1; \
113
        fi
Francesco Bonanno's avatar
Francesco Bonanno committed
114 115

clean:
Francesco Bonanno's avatar
Francesco Bonanno committed
116 117 118 119 120
	if [ -f $(BUILD_NUMBER_FILE) ]; then \
		$(MAKE) clean1; \
	fi

clean1:
121 122 123 124
	if [ ! -z $(LOOPDEVICE) ]; then \
	sudo losetup -d $(LOOPDEVICE); true; \
	fi

Francesco Bonanno's avatar
Francesco Bonanno committed
125
	sudo lb clean --purge
126 127 128 129 130
	rm -f $(BASEIMG)-*; true
	rm -rf config; true
	rm -rf .build; true
	rm -f buildnum.txt; true
	rm -rf ~/tools; true
Francesco Bonanno's avatar
Francesco Bonanno committed
131 132

	if [ -d parrotsec-rpi ]; then \
133
		sudo umount -l parrotsec-rpi/*; true; \
Francesco Bonanno's avatar
Francesco Bonanno committed
134 135
		sudo dmsetup remove_all; \
		sudo rm -rf parrotsec-rpi; \
136
		sudo rm -rf rpi-firmware; true; \
Francesco Bonanno's avatar
Francesco Bonanno committed
137 138 139
	fi

	if [ -f $(IMAGENAME) ]; then \
Francesco Bonanno's avatar
Francesco Bonanno committed
140
		rm -f $(IMAGENAME)*; \
141
		sudo umount -l parrotsec-rpi/*; true; \
Francesco Bonanno's avatar
Francesco Bonanno committed
142
		sudo dmsetup remove_all; \
143
		sudo rm -rf parrotsec-rpi rpi-firmware; \
Francesco Bonanno's avatar
Francesco Bonanno committed
144 145 146 147
	fi

write-image:
	sudo ./build_parrotsec_image.sh $(BLOCKDEVICE)
148 149

write-and-resize:
Francesco Bonanno's avatar
Francesco Bonanno committed
150
	sudo ./image-writer-resizer.sh $(BLOCKDEVICE)
Francesco Bonanno's avatar
Francesco Bonanno committed
151