forked from Maccraft123/Cadmium
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build-all
executable file
·149 lines (121 loc) · 3.05 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
CADMIUMROOT="$(dirname $(realpath $0))"
if [ "$ARCHITECTURE" == "" ];
then
echo "Which architecture would you like to build for?"
echo "1: arm"
echo "2: arm64"
arc=inv
until [ "$arc" != "inv" ]; do
read -p ": " arc
done
case $arc in
1) ARCHITECTURE="arm";;
2) ARCHITECTURE="arm64";;
esac
fi
case $ARCHITECTURE in
arm)
export ARCH="arm";
export FLAV="arm32-chromebook"
;;
arm64)
export ARCH="arm64";
export FLAV="arm64-chromebook"
;;
esac
source "$CADMIUMROOT/flavor/$FLAV"
if [ "$RFILESYSTEM" == "" ]
then
# Choose the filesystem
echo "Which RootFS would you like to build?"
echo "1: Alpine"
echo "2: Arch"
echo "3: Debian"
echo "4: Gentoo"
echo "5: Void"
echo "6: Void-Musl"
rfs=inv
until [ "$rfs" != "inv" ]; do
read -p ": " rfs
done
case $rfs in
1) RFILESYSTEM="alpine";;
2) RFILESYSTEM="arch";;
3) RFILESYSTEM="debian";;
4) RFILESYSTEM="gentoo";;
5) RFILESYSTEM="void";;
6) RFILESYSTEM="void-musl";;
esac
fi
case $RFILESYSTEM in
alpine)
source $CADMIUMROOT/cadmium-configs/$ARCH/config-alpine;
export RFILESYSTEM="alpine"
;;
arch)
source $CADMIUMROOT/cadmium-configs/$ARCH/config-arch;
export RFILESYSTEM="arch"
;;
debian)
source $CADMIUMROOT/cadmium-configs/$ARCH/config-debian;
export RFILESYSTEM="debian"
;;
gentoo)
source $CADMIUMROOT/cadmium-configs/$ARCH/config-gentoo;
export RFILESYSTEM="gentoo"
;;
void)
source $CADMIUMROOT/cadmium-configs/$ARCH/config-void;
export RFILESYSTEM="void"
;;
void-musl)
source $CADMIUMROOT/cadmium-configs/$ARCH/config-void-musl;
export RFILESYSTEM="void-musl"
;;
esac
set -x
set -e
sleep 1 # let's give user time if they commit a typo
# Usage:
# build-all <device>
# build-all <file> <size>
[ -z "$1" ] && exit 1
[ $IN_RAM = true -a -z "$2" ] && exit 2
# This script is usually tested with a physical pendrive
if [ -n "$2" ]; then
echo "Warning,"
echo "Running $0 like that is not recommended"
echo "Consider $0 /dev/sdX"
sleep 2
fi
# Just in case we got lingering mounts
umount "$CADMIUMROOT/tmp" 2>/dev/null || true
if [ "$IN_RAM" = true ]; then
mount -t tmpfs tmpfs "$CADMIUMROOT/tmp"
fi
# it deals with env vars, TODO: make it not
source "$CADMIUMROOT/bootfw/$BOOTFW/prepare_parts"
"$CADMIUMROOT/kernel/build"
function umount_root() {
echo "Cleaning up..."
umount -R "$CADMIUMROOT/tmp/root"
}
mkdir -p "$CADMIUMROOT/tmp/root"
mount "$ROOTPART" "$CADMIUMROOT/tmp/root"
trap umount_root EXIT
# write filesystem
"$CADMIUMROOT/fs/build" "$CADMIUMROOT/tmp/root"
"$CADMIUMROOT/bootfw/$BOOTFW/package" "$DEVICE" "$ROOTPART"
# TODO: move to bootfw/$BOOTFW/install
if [ "$BOOTFW" = depthcharge ]; then
dd if="$CADMIUMROOT/tmp/linux-$ARCH/vmlinux.kpart" of="$KERNPART"
cp "$CADMIUMROOT/tmp/oxide.kpart" "$CADMIUMROOT/tmp/root/"
fi
# 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
[ "$IN_RAM" = true ] && echo "Don't forget to umount $CADMIUMROOT/tmp"
echo "Done!"