-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·339 lines (283 loc) · 10.7 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
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
#!/bin/bash
#---------------------------------------------
# environment
#---------------------------------------------
set -e
CWD=$(pwd)
[[ $EUID != 0 ]] && echo -e "\nThis script must be run with root privileges\n" && exit 1
TTY_X=$(($(stty size | cut -f2 -d " ")-10)) # determine terminal width
TTY_Y=$(($(stty size | cut -f1 -d " ")-10)) # determine terminal height
#---------------------------------------------
# board configuration
#---------------------------------------------
source $CWD/overall.sh || exit 1
#---------------------------------------------
# set global architecture
#---------------------------------------------
set_architecture
#---------------------------------------------
# get boards
#---------------------------------------------
for board in $CWD/config/boards/*/*.conf ;do
if [[ $(grep -oP "(?<=DISTRIBUTION_ARCHITECTURE=[\"\']).*(?=[\'\"]$)" $board) =~ $ARCH ]]; then
BOARDS+=( $(echo $board | rev | cut -d '/' -f1 | cut -d '.' -f2 | rev) "$(sed -n '/^#/{3p}' $board | sed 's:#\s::')" "off")
fi
done
if [[ -z $BOARD_NAME ]]; then
# no menu
NO_MENU=yes
# Duplicate file descriptor 1 on descriptor 3
exec 3>&1
while true; do
BOARD_NAME=$(dialog --title " build a distribution image of $ARCH architecture " \
--radiolist "selected your board" $TTY_Y $TTY_X $(($TTY_Y - 8)) \
"${BOARDS[@]}" \
2>&1 1>&3)
[ ! -e $BOARD_NAME ] && break
done
# Close file descriptor 3
exec 3>&-
fi
#---------------------------------------------
# get linux distributions
#---------------------------------------------
for _distr in $(grep -oP "(?<=DISTRS=[\"\']).*(?=[\'\"]$)" $CWD/config/environment/environment.conf); do
_selected="off"
_distribution_architecture=$(grep -oP "(?<=DISTRIBUTION_ARCHITECTURE=[\"\']).*(?=[\'\"]$)" $CWD/config/boards/${BOARD_NAME}/${BOARD_NAME}.conf)
if [[ ${_distr} == slarm64 && ${_distribution_architecture} =~ (aarch|riscv)64 ]]; then
DISTRS+=(${_distr} "linux" ${_selected})
elif [[ ${_distr} == slackwarearm* && ${_distribution_architecture} =~ arm ]]; then
DISTRS+=(${_distr} "linux" ${_selected})
elif [[ ${_distr} == crux* && ${_distribution_architecture} =~ (arm|aarch64) ]]; then
DISTRS+=(${_distr} "linux" ${_selected})
fi
done
if [[ -z $DISTR ]]; then
# no menu
NO_MENU=yes
# Duplicate file descriptor 1 on descriptor 3
exec 3>&1
while true; do
DISTR=$(dialog --title " build for board ${BOARD_NAME/_/-} " \
--radiolist "select distribution" $TTY_Y $TTY_X $(($TTY_Y - 8)) \
"${DISTRS[@]}" \
2>&1 1>&3)
[ ! -e $DISTR ] && break
done
# Close file descriptor 3
exec 3>&-
fi
#---------------------------------------------
# get kernel source type
#---------------------------------------------
if [[ $NO_MENU == yes ]]; then
# Duplicate file descriptor 1 on descriptor 3
exec 3>&1
KERNEL_SOURCES=$(grep -oP "(?<=_SOURCES=).*$" $CWD/config/boards/$BOARD_NAME/${BOARD_NAME}.conf | sed 's:\"::g')
[ ! -z ${KERNEL_SOURCES%%:*} ] && kernel_sources_options+=("${KERNEL_SOURCES%%:*}" "legacy kernel source" "off")
[ ! -z ${KERNEL_SOURCES##*:} ] && kernel_sources_options+=("${KERNEL_SOURCES##*:}" "mainline kernel source" "off")
while true; do
# kernel source
KERNEL_SOURCE=$(dialog --title " build kernel for ${BOARD_NAME/_/-} " \
--radiolist "select kernel source" $TTY_Y $TTY_X $(($TTY_Y - 8)) \
"${kernel_sources_options[@]}" \
2>&1 1>&3)
[ ! -e $KERNEL_SOURCE ] && break
done
# Close file descriptor 3
exec 3>&-
fi
DESKTOP=$(grep -oP "(?<=DESKTOP\=).*$" $CWD/config/boards/$BOARD_NAME/${BOARD_NAME}.conf || echo "no")
DISTR_IMAGES=$(grep -oP "(?<=DISTR_IMAGES=).*(?=$)" $CWD/config/environment/environment.conf)
options+=("clean" "clean sources, remove binaries and image" "off")
options+=("download" "download source and use pre-built binaries" "on")
options+=("compile" "build binaries locally" "on")
options+=($DISTR_IMAGES "create default image" "on")
[[ $DESKTOP == yes && $DISTR != crux* ]] && options+=("desktop" "create an image with a desktop (optional)" "on")
unset DISTR_IMAGES
if [[ $NO_MENU == yes ]]; then
# Duplicate file descriptor 1 on descriptor 3
exec 3>&1
while true; do
result=$(dialog --title " build $KERNEL_SOURCE for ${BOARD_NAME/_/-} " \
--checklist "select build options" $TTY_Y $TTY_X $(($TTY_Y - 8)) \
"${options[@]}" \
2>&1 1>&3)
[ ! -z "$result" ] && break
done
exit_status=$?
# Close file descriptor 3
exec 3>&-
for arg in ${result[*]}; do
case "$arg" in
download)
DOWNLOAD_SOURCE_BINARIES=yes
;;
clean)
CLEAN=yes
;;
compile)
COMPILE_BINARIES=yes
;;
desktop)
DESKTOP_SELECTED=yes
;;
server)
DISTR_IMAGES="server"
;;
esac
done
fi
#---------------------------------------------
# select build arch on x86_64
#---------------------------------------------
if [[ $(uname -m) == "x86_64" ]]; then
# Duplicate file descriptor 1 on descriptor 3
exec 3>&1
while true; do
result=$(dialog --title " build $KERNEL_SOURCE for ${BOARD_NAME/_/-} " \
--radiolist "select build architecture" $TTY_Y $TTY_X $(($TTY_Y - 8)) \
"arm" "ARM-v7 32-bit architecture" "off" \
"aarch64" "ARM-v8 64-bit architecture" "off" \
"riscv64" "RISC-V 64-bit architecture" "off" \
2>&1 1>&3)
if [[ ! -z $result ]]; then break; fi
done
exit_status=$?
# Close file descriptor 3
exec 3>&-
for arg in $result; do
if [ "$arg" == "arm" ]; then
ARCH=$arg
elif [ "$arg" == "aarch64" ]; then
ARCH=$arg
elif [ "$arg" == "riscv64" ]; then
ARCH=$arg
fi
done
fi
#---------------------------------------------
# clean terminal
#---------------------------------------------
reset
#---------------------------------------------
# configuration
#---------------------------------------------
source $CWD/downloads.sh || exit 1
source $CWD/compilation.sh || exit 1
source $CWD/build_packages.sh || exit 1
source $CWD/build_images.sh || exit 1
source $CWD/configuration.sh || exit 1
#---------------------------------------------
# main script
#---------------------------------------------
if [[ $CLEAN == yes ]]; then
clean_sources
fi
if [[ ! -e $BOARD_NAME ]]; then
prepare_dest
fi
if [[ $DOWNLOAD_SOURCE_BINARIES == yes ]]; then
download
fi
#---------------------------------------------
# start build
#---------------------------------------------
message "" "start" "build $DISTR ARCH $ARCH images: ${DISTR_IMAGES[*]}"
if [[ $COMPILE_BINARIES == yes ]]; then
# aarch64 change interpreter path
[[ $MARCH == aarch64 ]] && change_interpreter_path "${XTOOLS[@]}"
clear_boot_tools
# if [[ ! -z $ATF && $SOCFAMILY == rk33* ]] || [[ $SOCFAMILY == meson* ]]; then
if [[ ! -z $ATF && $SOCFAMILY == rk33* ]]; then
[[ $DOWNLOAD_SOURCE_BINARIES == yes ]] && patching_source "u-boot-tools"
compile_boot_tools
fi
[[ ! -z $BOOT_PACKER_LOADER_DIR ]] && compile_boot_packer_loader
if [[ ! -z $ATF ]]; then
[[ $DOWNLOAD_SOURCE_BINARIES == yes ]] && patching_source "atf"
compile_atf
fi
if [[ ! -z $DDRINIT_DIR ]]; then
[[ $DOWNLOAD_SOURCE_BINARIES == yes ]] && patching_source "ddrinit"
compile_ddrinit
fi
if [[ ! -z $SECOND_BOOT_DIR ]]; then
[[ $DOWNLOAD_SOURCE_BINARIES == yes ]] && patching_source "second-boot"
compile_second_boot
fi
if [[ ! -z $OPENSBI ]]; then
[[ $DOWNLOAD_SOURCE_BINARIES == yes ]] && patching_source "opensbi"
compile_opensbi
fi
[[ $DOWNLOAD_SOURCE_BINARIES == yes ]] && patching_source "u-boot"
compile_boot_loader
if [[ $DOWNLOAD_SOURCE_BINARIES == yes ]]; then
external_patching_source
patching_source "kernel"
fi
compile_kernel
build_kernel_pkg
fi
for image_type in ${DISTR_IMAGES[@]}; do
get_name_rootfs ${image_type}
clean_rootfs ${image_type}
if [[ ${image_type} =~ server|core || ( $DESKTOP_SELECTED == yes && ! ${DISTR_IMAGES[@]} =~ server|core ) ]]; then
prepare_rootfs
create_archive_bootloader
download_pkg $DISTR_URL "${image_type}"
install_pkg "${image_type}"
if [[ ${DISTR} == crux* ]]; then
download_pkg "${DISTR_URL}-update" "${image_type}-update"
install_pkg "${image_type}-update"
download_pkg "${DISTR_URL}" "opt"
install_pkg "opt"
fi
install_kernel
setting_system
setting_bootloader
setting_overlays
setting_hostname
setting_fstab
setting_debug
setting_motd
setting_datetime
setting_ssh
setting_dhcp
create_initrd
if [[ ${DISTR} != crux* ]]; then
setting_wifi
setting_governor
fi
[[ $NTP == yes ]] && setting_ntp
setting_modules
setting_bootloader_move_to_disk
create_img "$ROOTFS"
build_img "$ROOTFS"
[[ $IMAGE_COMPRESSION == yes ]] && image_compression "$ROOTFS"
fi
if [[ ! ${image_type} =~ server|core || ( $DESKTOP_SELECTED == yes && ${#DISTR_IMAGES[@]} == 1 ) ]]; then
message "" "create" "$ROOTFS_DESKTOP"
mv $SOURCE/$ROOTFS $SOURCE/$ROOTFS_DESKTOP >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
# installing overall distribution desktop packages
download_pkg $DISTR_URL "desktop"
install_pkg "desktop"
# installing distribution desktop packages
download_pkg $DISTR_URL "desktop-${image_type}"
install_pkg "desktop-${image_type}"
# installing extra desktop packages
download_pkg $DISTR_EXTRA_URL "desktop-${image_type}-extra"
install_pkg "desktop-${image_type}-extra"
# installing extra board packages
download_pkg $DISTR_EXTRA_URL $SOCFAMILY
install_pkg $SOCFAMILY
[[ $NETWORKMANAGER == yes ]] && setting_networkmanager "$ROOTFS_DESKTOP"
setting_default_start_x ${image_type}
setting_for_desktop
setting_alsa "$ROOTFS_DESKTOP"
removed_default_xorg_conf "$ROOTFS_DESKTOP"
create_img "$ROOTFS_DESKTOP"
build_img "$ROOTFS_DESKTOP"
[[ $IMAGE_COMPRESSION == yes ]] && image_compression "$ROOTFS_DESKTOP"
fi
done