-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
build-all
executable file
·80 lines (59 loc) · 1.79 KB
/
build-all
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
#!/bin/bash
CADMIUMROOT="$(dirname $(realpath $0))"
unset CC
unset CXX
set -e
"$CADMIUMROOT/check"
if [ -z "$DROPTO" ]; then
if [ "$UID" != "0" ]; then
mkdir -p "$CADMIUMROOT/tmp"
exec sudo env DROPTO="$(whoami)" "$CADMIUMROOT/build-all" $@
else
echo "Running this script as root without setting DROPTO to your usual user is deprecated"
echo "The ability to do so will be removed in future"
fi
fi
function drop_perms() {
setpriv --reuid="$DROPTO" --regid="$DROPTO" --init-groups --inh-caps=-all $@
}
source "$CADMIUMROOT/config"
source "$CADMIUMROOT/flavor/$FLAV"
[ "$DEBUG" = "true" ] && set -x
if [ -z "$1" ]; then
echo "Usage:"
echo "To build Cadmium onto a block device: build-all <device>"
echo "To build Cadmium onto a file: build-all <file> <size>"
exit 1
fi
if [ -z "$2" -a ! -b "$1" ]; then
echo "$1 is not a block device"
exit 1
fi
drop_perms git -C "$CADMIUMROOT" submodule update 2>/dev/null # FIXME: complains about missing files
# it deals with env vars, TODO: make it not
source "$CADMIUMROOT/loader/$LOADER/prepare_parts"
drop_perms "$CADMIUMROOT/kernel/build"
# TODO: move to loader/prepare_parts
case "$FILESYSTEM" in
f2fs)
mkfs.f2fs -f "$ROOTPART" -O extra_attr,inode_checksum,sb_checksum
;;
ext4)
mkfs.ext4 -F "$ROOTPART"
tune2fs -o discard "$ROOTPART"
;;
esac
function umount_root() {
umount "$CADMIUMROOT/tmp/root"
}
mkdir -p "$CADMIUMROOT/tmp/root"
mount "$ROOTPART" "$CADMIUMROOT/tmp/root"
trap umount_root EXIT
"$CADMIUMROOT/fs/build" "$CADMIUMROOT/tmp/root"
"$CADMIUMROOT/loader/$LOADER/install" "$DEVICE" "$ROOTPART"
# install modules
make -C "$CADMIUMROOT/tmp/linux-$ARCH" INSTALL_MOD_PATH="$CADMIUMROOT/tmp/root" modules_install
# yes, this fails when device is pendrive or sth
losetup -d "$DEVICE" 2>/dev/null || true
sync # just to be sure
echo "Done!"