This repository has been archived by the owner on Dec 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
01_build.sh
executable file
·106 lines (89 loc) · 3.04 KB
/
01_build.sh
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
102
103
104
105
106
#!/bin/bash
. GPiBE.conf
set -e
cd $(dirname $(readlink -f $0))
[ -e GPiBE_branch ] && GPI_BRANCH="`cat GPiBE_branch`" || GPI_BRANCH="master"
FAILED=false
MNT="tools/mnt-pi-img.sh"
BUILDNAME="`date +%y%m%d%H%M`rpi"
[[ "${GPI_BRANCH}" != "master" ]] && BUILDNAME="${BUILDNAME}-${GPI_BRANCH}"
FILENAME="${GDFDL_FILE_PREFIX}_${BUILDNAME}"
GPI_IMAGE="images/${FILENAME}.img"
GPI_IMAGE_TMPL="cache/gs5-rpi-tmpl.img"
# Create image clone
if [ ! -e "${GPI_IMAGE_TMPL}" ]; then
echo -e "FATAL ERROR: No image template prepared yet. Please run 00_prepare.sh first."
exit 1
fi
echo -e "GPiBE: Cloning RaspberryPi image ..."
if [ ! -d "${GPI_IMAGE%%/*}" ]; then
mkdir -p "${GPI_IMAGE%%/*}"
else
rm -f "${GPI_IMAGE%%/*}/"*
fi
cp -f "${GPI_IMAGE_TMPL}" "${GPI_IMAGE}"
# Mount
echo -e "GPiBE: Mounting image ..."
sudo ${MNT} "${GPI_IMAGE}" chroot
# Check for existing upstream projects
if [ ! -d upstream/GBE ]; then
echo -e "GPiBE: Cloning GBE ..."
git clone -b master ${GBE_GIT_URL} upstream/GBE
fi
if [ -d upstream/GSE ]; then
echo -e "GPiBE: GSE upstream found, copy to image ..."
sudo mkdir -p chroot/opt/GSE
sudo cp -rfv upstream/GSE chroot/opt
fi
if [ -d upstream/GS5 ]; then
echo -e "GPiBE: GS5 upstream found, copy to image ..."
sudo mkdir -p chroot/opt/GS5
sudo cp -rfv upstream/GS5 chroot/opt
fi
# Compatibility with GBE
sudo ln -s be/GPiBE.conf chroot/gdfdl.conf
sudo sh -c "echo \"${BUILDNAME}\" > chroot/etc/gdfdl_build"
[ "${GIT_BRANCH}" != "" ] && sudo sh -c "echo \"${GIT_BRANCH}\" > chroot/etc/gemeinschaft_branch" || sudo sh -c "echo master > chroot/etc/gemeinschaft_branch"
echo -e "GPiBE: Running hooks ..."
for FILE in `find hooks -name "*.sh.chroot" | sort`; do
sudo chroot chroot /be/${FILE}
if [ "$?" != "0" ]; then
echo "$FILE aborted with error, aborting execution..."
FAILED=true
break
fi
done
# cleanup
sudo rm -fv chroot/usr/lib/qemu-arm-static
# umount
echo -e "GPiBE: Unmounting image ..."
sudo ${MNT} -u chroot
if [ "${FAILED}" == "false" ]; then
# Compress image
echo -e "GPiBE: Compressing image ..."
(cd images; p7zip "${GPI_IMAGE#*/}")
# generate checksums
echo -n "Generating checksum files ... "
rm -rf images/*.sign images/MD5SUMS images/SHA1SUMS images/SHA256SUMS
md5deep -b images/*.img* > images/MD5SUMS
sha1deep -b images/*.img* > images/SHA1SUMS
sha256deep -b images/*.img* > images/SHA256SUMS
echo "ok"
# sign checksums if .gnupg files are present
if [ -d ~/.gnupg ]; then
echo -n "Signing checksum files ... "
if [ -f ~/.gnupg/passphrase ]; then
gpg --batch --passphrase-file ~/.gnupg/passphrase -sat images/MD5SUMS --output images/MD5SUMS.sign
gpg --batch --passphrase-file ~/.gnupg/passphrase -sat images/SHA1SUMS --output images/SHA1SUMS.sign
gpg --batch --passphrase-file ~/.gnupg/passphrase -sat images/SHA256SUMS --output images/SHA256SUMS.sign
else
gpg --batch -sat images/MD5SUMS --output images/MD5SUMS.sign
gpg --batch -sat images/SHA1SUMS --output images/SHA1SUMS.sign
gpg --batch -sat images/SHA256SUMS --output images/SHA256SUMS.sign
fi
echo "ok"
fi
else
exit 1
fi
cd - 2>&1>/dev/null