-
Notifications
You must be signed in to change notification settings - Fork 8
/
build_all.sh
executable file
·385 lines (353 loc) · 12.2 KB
/
build_all.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-3.0
#
# This file is a part of the Avaota Build Framework
# https://github.com/AvaotaSBC/AvaotaOS/
__usage="
Usage: build_all [OPTIONS]
Build bootable image.
The target sdcard.img will be generated in the build folder of the directory where the build_all.sh script is located.
Options:
-b, --board BOARD The board name.
-m, --mirror MIRROR_ADDR The URL/path of debian/ubuntu mirror address.
-v, --version UBUNTU_VER The version of ubuntu.
-a, --arch ARCH The arch of ubuntu.
-t, --type ROOTFS_TYPE The type of rootfs: cli, xfce, gnome, kde.
-k, --kernelmenuconfig If run kernel menuconfig.
-g, --kerneltarget The kernel target.
-u, --user SYS_USER The normal user of rootfs.
-p, --password SYS_PASSWORD The password of user.
-s, --supassword ROOT_PASSWORD The password of root.
-l, --local LOCAL_SOURCES Use local kernel,u-boot,syterkit
-i, --githubmirror GITHUB_MIRROR Use GitHub mirror.
-o, --kernelonly Only build kernel package.
-e, --ccache If use ccache.
-h, --help Show command help.
"
help()
{
echo "$__usage"
exit $1
}
default_param() {
BOARD=none
VERSION=none
TYPE=none
SYS_USER=avaota
SYS_PASSWORD=avaota
ROOT_PASSWORD=avaota
KERNEL_MENUCONFIG=none
KERNEL_TARGET=none
MIRROR=none
GITHUB_MIRROR=none
LOCAL=no
KERNEL_ONLY=none
USE_CCACHE=no
}
parseargs()
{
if [ "x$#" == "x0" ]; then
EXTRA_ARGS=yes
return 0
fi
while [ "x$#" != "x0" ];
do
if [ "x$1" == "x-h" -o "x$1" == "x--help" ]; then
return 1
elif [ "x$1" == "x" ]; then
shift
elif [ "x$1" == "x-b" -o "x$1" == "x--board" ]; then
BOARD=`echo $2`
shift
shift
elif [ "x$1" == "x-m" -o "x$1" == "x--mirror" ]; then
MIRROR=`echo $2`
shift
shift
elif [ "x$1" == "x-v" -o "x$1" == "x--version" ]; then
VERSION=`echo $2`
shift
shift
elif [ "x$1" == "x-t" -o "x$1" == "x--type" ]; then
TYPE=`echo $2`
shift
shift
elif [ "x$1" == "x-u" -o "x$1" == "x--user" ]; then
SYS_USER=`echo $2`
shift
shift
elif [ "x$1" == "x-p" -o "x$1" == "x--password" ]; then
SYS_PASSWORD=`echo $2`
shift
shift
elif [ "x$1" == "x-s" -o "x$1" == "x--supassword" ]; then
ROOT_PASSWORD=`echo $2`
shift
shift
elif [ "x$1" == "x-k" -o "x$1" == "x--kernelmenuconfig" ]; then
KERNEL_MENUCONFIG=`echo $2`
shift
shift
elif [ "x$1" == "x-g" -o "x$1" == "x--kerneltarget" ]; then
KERNEL_TARGET=`echo $2`
shift
shift
elif [ "x$1" == "x-l" -o "x$1" == "x--local" ]; then
LOCAL=`echo $2`
shift
shift
elif [ "x$1" == "x-i" -o "x$1" == "x--githubmirror" ]; then
GITHUB_MIRROR=`echo $2`
shift
shift
elif [ "x$1" == "x-o" -o "x$1" == "x--kernelonly" ]; then
KERNEL_ONLY=`echo $2`
shift
shift
elif [ "x$1" == "x-e" -o "x$1" == "x--ccache" ]; then
USE_CCACHE=`echo $2`
shift
shift
else
echo `date` - ERROR, UNKNOWN params "$@"
return 2
fi
done
}
input_box(){
if [ "${BOARD}" == "none" ];then
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" --title "Boards" --menu "select board" 15 60 2 \
avaota-a1 "Avaota A1" \
avaota-c1 "Avaota C1" \
2> $temp
if [ $? == 1 ];then
exit 2
fi
BOARD=$(cat $temp)
clear
rm $temp
fi
source boards/${BOARD}.conf
if [ "${VERSION}" == "none" ];then
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" --title "System Distro" --menu "select distro" 15 60 2 \
focal "Ubuntu 20.04" \
jammy "Ubuntu 22.04" \
noble "Ubuntu 24.04" \
bullseye "Debian 11" \
bookworm "Debian 12" \
trixie "Debian 13" \
2> $temp
if [ $? == 1 ];then
exit 2
fi
VERSION=$(cat $temp)
clear
rm $temp
fi
if [ "${TYPE}" == "none" ];then
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" --title "System Type" --menu "select desktop" 15 60 2 \
cli "Console Version" \
gnome "Gnome Desktop" \
xfce "XFCE Desktop" \
kde "Kde Desktop" \
lxqt "LXQT Desktop" \
2> $temp
if [ $? == 1 ];then
exit 2
fi
TYPE=$(cat $temp)
clear
rm $temp
fi
if [ "${KERNEL_MENUCONFIG}" == "none" ];then
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" --title "Kernel Configure" --menu "select configure" 15 60 2 \
no "Dont't run kernel menuconfig" \
yes "Run kernel menuconfig" \
2> $temp
if [ $? == 1 ];then
exit 2
fi
KERNEL_MENUCONFIG=$(cat $temp)
clear
rm $temp
fi
if [ "${KERNEL_TARGET}" == "none" ];then
IFS=',' read -ra PRNT_BRCHS <<< "${KERNEL_BRANCH}"
PRNT_BNH=$(for PRNT_BRCH in "${PRNT_BRCHS[@]}"; do
echo -n "${PRNT_BRCH} Kernel-Branch "
done)
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" --title "Kernel Target" --menu "select target" 15 60 2 \
${PRNT_BNH} \
2> $temp
if [ $? == 1 ];then
exit 2
fi
KERNEL_TARGET=$(cat $temp)
clear
rm $temp
fi
source boards/${BOARD}.conf
if [ "${KERNEL_ONLY}" == "none" ];then
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" --title "Only Build Kernel" --menu "only kernel" 15 60 2 \
no "Build all" \
yes "Only build kernel packages." \
2> $temp
if [ $? == 1 ];then
exit 2
fi
KERNEL_ONLY=$(cat $temp)
clear
rm $temp
fi
if [ "${MIRROR}" == "none" ];then
if [[ "${VERSION}" == "jammy" || "${VERSION}" == "noble" || "${VERSION}" == "focal" ]];then
MIRROR=http://ports.ubuntu.com
elif [[ "${VERSION}" == "bookworm" || "${VERSION}" == "trixie" ]];then
MIRROR=http://deb.debian.org/debian
fi
fi
if [ "${EXTRA_ARGS}" == "yes" ];then
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" \
--title "Create System Normal User" \
--inputbox "User Name:" 15 60 "${SYS_USER}" 2> $temp
if [ $? == 1 ];then
exit 2
fi
SYS_USER=$(cat $temp)
rm $temp
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" \
--title "Create System Normal User Password" \
--inputbox "User Password:" 15 60 "${SYS_PASSWORD}" 2> $temp
if [ $? == 1 ];then
exit 2
fi
SYS_PASSWORD=$(cat $temp)
rm $temp
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" \
--title "Change ROOT Password" \
--inputbox "ROOT Password:" 15 60 "${ROOT_PASSWORD}" 2> $temp
if [ $? == 1 ];then
exit 2
fi
ROOT_PASSWORD=$(cat $temp)
rm $temp
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" \
--title "Change DEB Mirror" \
--inputbox "Mirror URL:" 15 60 "${MIRROR}" 2> $temp
if [ $? == 1 ];then
exit 2
fi
MIRROR=$(cat $temp)
rm $temp
if [ "${GITHUB_MIRROR}" == "none" ];then
temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" --title "Use GitHub Mirror" --menu "github mirror" 15 60 2 \
no "Dont't use Github Proxy" \
yes "Use Github Proxy" \
2> $temp
if [ $? == 1 ];then
exit 2
fi
IF_GITHUB_MIRROR=$(cat $temp)
if [ ${IF_GITHUB_MIRROR} == "yes" ];then
in_temp=`mktemp -t test.XXXXXX`
dialog --clear --shadow --backtitle "AvaotaOS Build Framework" \
--title "Setup GitHub Mirror" \
--inputbox "Github Mirror URL:" 15 60 "https://mirror.ghproxy.com" 2> $in_temp
if [ $? == 1 ];then
exit 2
fi
GITHUB_MIRROR=$(cat $in_temp)
rm $in_temp
elif [ ${IF_GITHUB_MIRROR} == "no" ];then
GITHUB_MIRROR="no"
fi
clear
rm $temp
fi
fi
clear
}
print_args(){
echo "+-------[ Config Info ]--------"
echo "| BOARD=${BOARD}"
echo "| VERSION=${VERSION}"
echo "| ARCH=${ARCH}"
echo "| TYPE=${TYPE}"
echo "| SYS_USER=${SYS_USER}"
echo "| SYS_PASSWORD=${SYS_PASSWORD}"
echo "| ROOT_PASSWORD=${ROOT_PASSWORD}"
echo "| MIRROR=${MIRROR}"
echo "| KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG}"
echo "| KERNEL_TARGET=${KERNEL_TARGET}"
echo "| LOCAL=${LOCAL}"
echo "| GITHUB_MIRROR=${GITHUB_MIRROR}"
echo "| KERNEL_ONLY=${KERNEL_ONLY}"
echo "| USE_CCACHE=${USE_CCACHE}"
echo "| LINUX_REPO=${LINUX_REPO}"
echo "| LINUX_BRANCH=${LINUX_BRANCH}"
echo "| LINUX_CONFIG=${LINUX_CONFIG}"
echo "+-------------------------------"
echo "You can run the following command at the next time:"
echo "sudo bash build_all.sh -b ${BOARD} -m ${MIRROR} -v ${VERSION} -t ${TYPE} -u ${SYS_USER} -p ${SYS_PASSWORD} -s ${ROOT_PASSWORD} -k ${KERNEL_MENUCONFIG} -g ${KERNEL_TARGET} -l ${LOCAL} -i ${GITHUB_MIRROR} -o ${KERNEL_ONLY} -e ${USE_CCACHE}"
echo "--------------------------------"
}
sudo apt-get install gcc-arm-none-eabi cmake build-essential gcc-aarch64-linux-gnu mtools qemu-user-static bc pkg-config dialog -y
sudo apt install debootstrap ubuntu-keyring debian-keyring automake autoconf gcc make pixz libconfuse2 libconfuse-common libconfuse-dev -y
EXTRA_ARGS=no
default_param
parseargs "$@" || help $?
input_box
print_args
if [ ! -d build_dir ];then
mkdir build_dir
fi
cd build_dir
workspace=$(pwd)
cd ${workspace}
ROOTFS=${workspace}/rootfs
source ../boards/${BOARD}.conf
if [ ${LOCAL} == "no" ];then
sudo bash ../scripts/fetch.sh -b ${BOARD} -i ${GITHUB_MIRROR} -g ${KERNEL_TARGET}
fi
if [[ -f ${workspace}/bootloader-${BOARD}/.done && \
$(cat ${workspace}/bootloader-${BOARD}/.done) == "${BOARD}" ]];then
echo "found bootloader file, skip build bootloader."
else
sudo bash ../scripts/mkbootloader.sh -b ${BOARD}
fi
if [[ -f ${workspace}/${BOARD}-kernel-pkgs/.done && \
$(cat ${workspace}/${BOARD}-kernel-pkgs/.done) == "${LINUX_CONFIG}" ]];then
echo "found kernel packages, skip build kernel."
else
sudo bash ../scripts/mklinux.sh -b ${BOARD} -k ${KERNEL_MENUCONFIG} -g ${KERNEL_TARGET} -e ${USE_CCACHE}
fi
if [ ${KERNEL_ONLY} == "yes" ];then
echo "Only build kernel packages."
exit 0
fi
if [ -f ${workspace}/ubuntu-${VERSION}-${TYPE}/THIS-IS-NOT-YOUR-ROOT ];then
echo "found rootfs, skip build rootfs."
else
sudo mkdir ${ROOTFS} && sudo bash ../scripts/mkrootfs.sh -m ${MIRROR} -r ${ROOTFS} -v ${VERSION} -b ${BOARD} -t ${TYPE} -u ${SYS_USER} -p ${SYS_PASSWORD} -s ${ROOT_PASSWORD}
fi
sudo bash ../scripts/pack.sh -b ${BOARD} -t ${TYPE} -v ${VERSION}
AVA_VERSION=$(cat ../VERSION)
if [ -f sdcard.img.xz ];then
mv sdcard.img.xz AvaotaOS-${AVA_VERSION}-${VERSION}-${TYPE}-${ARCH}-${BOARD}.img.xz
echo "build success."
else
echo "sdcard.img.xz not found, build sdcard image failed!"
exit 2
fi