-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.sh
102 lines (83 loc) · 2.25 KB
/
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
#!/bin/bash
if [[ $# -ne 5 ]]; then
echo "usage: $0 <output> <variant> <mode> <suite> <arch>"
exit 1
fi
BUILD_OUTPUT="$1"
BUILD_VARIANT="$2"
BUILD_MODE="$3"
BUILD_SUITE="$4"
BUILD_ARCH="$5"
BUILD_OUTPUT="$(readlink -f "$1")"
ROOT_DIR="$(pwd)"
set -ex
if [[ ! -d "configs/$BUILD_VARIANT" ]]; then
echo "Invalid BUILD_VARIANT: $BUILD_VARIANT (missing configs/$BUILD_VARIANT)"
exit 1
fi
mkdir -p out/
TEMP=$(mktemp -d $(readlink -f out)/build.XXXXX)
cleanup() {
sudo rm -rf "$TEMP"
}
trap cleanup EXIT
failure() {
echo "Build failure happened:"
echo "> debootstrap.log:"
cat "$TEMP/chroot/debootstrap/debootstrap.log" || true
if [[ -n "$DEBUG" ]]; then
echo "> failure shell"
bash
fi
}
trap failure ERR
pushd $TEMP
if [[ "$BUILD_ARCH" == "arm64" ]]; then
QEMU_BUILD_ARCH=aarch64
elif [[ "$BUILD_ARCH" == "armhf" ]]; then
QEMU_BUILD_ARCH=arm
else
echo "Unsupported BUILD_ARCH: $BUILD_ARCH."
exit 1
fi
SECURITY=true
if [[ "$BUILD_MODE" == "debian" ]]; then
ARCHIVE_AREAS="main contrib non-free"
if [[ "$BUILD_SUITE" == "bullseye" ]]; then
# there is no security yet for bullseye
SECURITY=false
fi
elif [[ "$BUILD_MODE" == "ubuntu" ]]; then
ARCHIVE_AREAS="main restricted universe multiverse"
else
echo "Unsupported BUILD_MODE: $BUILD_MODE."
exit 1
fi
lb config \
--apt-indices false \
--apt-recommends false \
--apt-secure true \
--architectures "$BUILD_ARCH" \
--archive-areas "$ARCHIVE_AREAS" \
--backports false \
--binary-filesystem ext4 \
--binary-images tar \
--bootstrap-qemu-arch "$BUILD_ARCH" \
--bootstrap-qemu-static "/usr/bin/qemu-$QEMU_BUILD_ARCH-static" \
--chroot-filesystem none \
--compression none \
--distribution "$BUILD_SUITE" \
--image-name rootfs-image \
--linux-flavours none \
--linux-packages none \
--mode "$BUILD_MODE" \
--security "$SECURITY" \
--system normal
for path in $BUILD_MODE $BUILD_MODE-$BUILD_SUITE $BUILD_VARIANT; do
if [[ -d "$ROOT_DIR/configs/$path" ]]; then
cp -av "$ROOT_DIR/configs/$path/." config/
fi
done
sudo lb build
sudo chown "$(id -u)" "rootfs-image-${BUILD_ARCH}.tar.tar"
mv "rootfs-image-${BUILD_ARCH}.tar.tar" "$BUILD_OUTPUT"