Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong
GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/configuration.sh
15181 views
1
#!/bin/bash
2
#
3
# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com
4
#
5
# This file is licensed under the terms of the GNU General Public
6
# License version 2. This program is licensed "as is" without any
7
# warranty of any kind, whether express or implied.
8
9
10
[[ -z $VENDOR ]] && VENDOR="Orange Pi"
11
[[ -z $ROOTPWD ]] && ROOTPWD="orangepi" # Must be changed @first login
12
[[ -z $OPI_USERNAME ]] && OPI_USERNAME="orangepi"
13
[[ -z $OPI_PWD ]] && OPI_PWD="orangepi"
14
[[ -z $MAINTAINER ]] && MAINTAINER="Orange Pi" # deb signature
15
[[ -z $MAINTAINERMAIL ]] && MAINTAINERMAIL="[email protected]" # deb signature
16
[[ -z $DEB_COMPRESS ]] && DEB_COMPRESS="xz" # compress .debs with XZ by default. Use 'none' for faster/larger builds
17
TZDATA=$(cat /etc/timezone) # Timezone for target is taken from host or defined here.
18
USEALLCORES=yes # Use all CPU cores for compiling
19
HOSTRELEASE=$(cat /etc/os-release | grep VERSION_CODENAME | cut -d"=" -f2)
20
[[ -z $HOSTRELEASE ]] && HOSTRELEASE=$(cut -d'/' -f1 /etc/debian_version)
21
[[ -z $EXIT_PATCHING_ERROR ]] && EXIT_PATCHING_ERROR="" # exit patching if failed
22
[[ -z $HOST ]] && HOST="$BOARD" # set hostname to the board
23
[[ -z $CHINA_DOWNLOAD_MIRROR ]] && CHINA_DOWNLOAD_MIRROR=huawei
24
cd "${SRC}" || exit
25
[[ -z "${ROOTFSCACHE_VERSION}" ]] && ROOTFSCACHE_VERSION=11
26
[[ -z "${CHROOT_CACHE_VERSION}" ]] && CHROOT_CACHE_VERSION=7
27
[[ -z $PLYMOUTH ]] && PLYMOUTH="yes"
28
29
cd ${SRC}/scripts
30
BUILD_REPOSITORY_URL=$(improved_git remote get-url $(improved_git remote 2>/dev/null | grep origin) 2>/dev/null)
31
BUILD_REPOSITORY_COMMIT=$(improved_git describe --match=d_e_a_d_b_e_e_f --always --dirty 2>/dev/null)
32
ROOTFS_CACHE_MAX=200 # max number of rootfs cache, older ones will be cleaned up
33
34
DEB_STORAGE=$DEST/debs
35
DEB_ORANGEPI=$EXTER/cache/debs
36
37
# TODO: fixed name can't be used for parallel image building
38
ROOT_MAPPER="orangepi-root"
39
[[ -z $ROOTFS_TYPE ]] && ROOTFS_TYPE=ext4 # default rootfs type is ext4
40
[[ "ext4 f2fs btrfs xfs nfs fel" != *$ROOTFS_TYPE* ]] && exit_with_error "Unknown rootfs type" "$ROOTFS_TYPE"
41
42
[[ -z $BTRFS_COMPRESSION ]] && BTRFS_COMPRESSION=zlib # default btrfs filesystem compression method is zlib
43
[[ ! $BTRFS_COMPRESSION =~ zlib|lzo|zstd|none ]] && exit_with_error "Unknown btrfs compression method" "$BTRFS_COMPRESSION"
44
45
# Fixed image size is in 1M dd blocks (MiB)
46
# to get size of block device /dev/sdX execute as root:
47
# echo $(( $(blockdev --getsize64 /dev/sdX) / 1024 / 1024 ))
48
[[ "f2fs" == *$ROOTFS_TYPE* && -z $FIXED_IMAGE_SIZE ]] && exit_with_error "Please define FIXED_IMAGE_SIZE"
49
50
# a passphrase is mandatory if rootfs encryption is enabled
51
if [[ $CRYPTROOT_ENABLE == yes && -z $CRYPTROOT_PASSPHRASE ]]; then
52
exit_with_error "Root encryption is enabled but CRYPTROOT_PASSPHRASE is not set"
53
fi
54
55
# small SD card with kernel, boot script and .dtb/.bin files
56
[[ $ROOTFS_TYPE == nfs ]] && FIXED_IMAGE_SIZE=64
57
58
# Since we are having too many options for mirror management,
59
# then here is yet another mirror related option.
60
# Respecting user's override in case a mirror is unreachable.
61
case $REGIONAL_MIRROR in
62
china)
63
[[ -z $USE_MAINLINE_GOOGLE_MIRROR ]] && [[ -z $MAINLINE_MIRROR ]] && MAINLINE_MIRROR=tuna
64
[[ -z $USE_GITHUB_UBOOT_MIRROR ]] && [[ -z $UBOOT_MIRROR ]] && UBOOT_MIRROR=gitee
65
[[ -z $GITHUB_MIRROR ]] && GITHUB_MIRROR=gitclone
66
[[ -z $DOWNLOAD_MIRROR ]] && DOWNLOAD_MIRROR=china
67
;;
68
*)
69
;;
70
esac
71
72
# used by multiple sources - reduce code duplication
73
[[ $USE_MAINLINE_GOOGLE_MIRROR == yes ]] && MAINLINE_MIRROR=google
74
75
case $MAINLINE_MIRROR in
76
google)
77
MAINLINE_KERNEL_SOURCE='https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable'
78
MAINLINE_FIRMWARE_SOURCE='https://kernel.googlesource.com/pub/scm/linux/kernel/git/firmware/linux-firmware.git'
79
;;
80
tuna)
81
MAINLINE_KERNEL_SOURCE='https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git'
82
MAINLINE_FIRMWARE_SOURCE='https://mirrors.tuna.tsinghua.edu.cn/git/linux-firmware.git'
83
;;
84
bfsu)
85
MAINLINE_KERNEL_SOURCE='https://mirrors.bfsu.edu.cn/git/linux-stable.git'
86
MAINLINE_FIRMWARE_SOURCE='https://mirrors.bfsu.edu.cn/git/linux-firmware.git'
87
;;
88
*)
89
MAINLINE_KERNEL_SOURCE='git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git'
90
MAINLINE_FIRMWARE_SOURCE='git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git'
91
;;
92
esac
93
94
MAINLINE_KERNEL_DIR="$SRC/kernel"
95
96
[[ $USE_GITHUB_UBOOT_MIRROR == yes ]] && UBOOT_MIRROR=github
97
98
case $UBOOT_MIRROR in
99
gitee)
100
MAINLINE_UBOOT_SOURCE='https://github.com/orangepi-xunlong/u-boot-orangepi.git'
101
;;
102
github)
103
MAINLINE_UBOOT_SOURCE='https://github.com/orangepi-xunlong/u-boot-orangepi.git'
104
;;
105
*)
106
MAINLINE_UBOOT_SOURCE='https://source.denx.de/u-boot/u-boot.git'
107
;;
108
esac
109
110
MAINLINE_UBOOT_DIR="$SRC/u-boot"
111
112
case $GITHUB_MIRROR in
113
fastgit)
114
GITHUB_SOURCE='https://hub.fastgit.xyz'
115
;;
116
gitclone)
117
GITHUB_SOURCE='https://gitclone.com/github.com'
118
;;
119
*)
120
GITHUB_SOURCE='https://github.com'
121
;;
122
esac
123
124
# Let's set default data if not defined in board configuration above
125
[[ -z $OFFSET ]] && OFFSET=4 # offset to 1st partition (we use 4MiB boundaries by default)
126
ARCH=armhf
127
KERNEL_IMAGE_TYPE=zImage
128
CAN_BUILD_STRETCH=yes
129
ATF_COMPILE=yes
130
[[ -z $CRYPTROOT_SSH_UNLOCK ]] && CRYPTROOT_SSH_UNLOCK=yes
131
[[ -z $CRYPTROOT_SSH_UNLOCK_PORT ]] && CRYPTROOT_SSH_UNLOCK_PORT=2022
132
# Default to pdkdf2, this used to be the default with cryptroot <= 2.0, however
133
# cryptroot 2.1 changed that to Argon2i. Argon2i is a memory intensive
134
# algorithm which doesn't play well with SBCs (need 1GiB RAM by default !)
135
# https://gitlab.com/cryptsetup/cryptsetup/-/issues/372
136
[[ -z $CRYPTROOT_PARAMETERS ]] && CRYPTROOT_PARAMETERS="--pbkdf pbkdf2"
137
[[ -z $WIREGUARD ]] && WIREGUARD="no"
138
[[ -z $EXTRAWIFI ]] && EXTRAWIFI="yes"
139
[[ -z $SKIP_BOOTSPLASH ]] && SKIP_BOOTSPLASH="no"
140
[[ -z $AUFS ]] && AUFS="yes"
141
[[ -z $IMAGE_PARTITION_TABLE ]] && IMAGE_PARTITION_TABLE="msdos"
142
[[ -z $EXTRA_BSP_NAME ]] && EXTRA_BSP_NAME=""
143
[[ -z $EXTRA_ROOTFS_MIB_SIZE ]] && EXTRA_ROOTFS_MIB_SIZE=0
144
[[ -z $BUILD_KSRC ]] && BUILD_KSRC="no"
145
146
# single ext4 partition is the default and preferred configuration
147
#BOOTFS_TYPE=''
148
[[ ! -f ${EXTER}/config/sources/families/$LINUXFAMILY.conf ]] && \
149
exit_with_error "Sources configuration not found" "$LINUXFAMILY"
150
151
source "${EXTER}/config/sources/families/${LINUXFAMILY}.conf"
152
153
if [[ -f $USERPATCHES_PATH/sources/families/$LINUXFAMILY.conf ]]; then
154
display_alert "Adding user provided $LINUXFAMILY overrides"
155
source "$USERPATCHES_PATH/sources/families/${LINUXFAMILY}.conf"
156
fi
157
158
# load architecture defaults
159
source "${EXTER}/config/sources/${ARCH}.conf"
160
161
## Extensions: at this point we've sourced all the config files that will be used,
162
## and (hopefully) not yet invoked any extension methods. So this is the perfect
163
## place to initialize the extension manager. It will create functions
164
## like the 'post_family_config' that is invoked below.
165
initialize_extension_manager
166
167
call_extension_method "post_family_config" "config_tweaks_post_family_config" << 'POST_FAMILY_CONFIG'
168
*give the config a chance to override the family/arch defaults*
169
This hook is called after the family configuration (`sources/families/xxx.conf`) is sourced.
170
Since the family can override values from the user configuration and the board configuration,
171
it is often used to in turn override those.
172
POST_FAMILY_CONFIG
173
174
# Myy : Menu configuration for choosing desktop configurations
175
176
show_menu() {
177
provided_title=$1
178
provided_backtitle=$2
179
provided_menuname=$3
180
# Myy : I don't know why there's a TTY_Y - 8...
181
#echo "Provided title : $provided_title"
182
#echo "Provided backtitle : $provided_backtitle"
183
#echo "Provided menuname : $provided_menuname"
184
#echo "Provided options : " "${@:4}"
185
#echo "TTY X: $TTY_X Y: $TTY_Y"
186
whiptail --title "${provided_title}" --backtitle "${provided_backtitle}" --notags \
187
--menu "${provided_menuname}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
188
"${@:4}" \
189
3>&1 1>&2 2>&3
190
}
191
192
# Myy : FIXME Factorize
193
show_select_menu() {
194
provided_title=$1
195
provided_backtitle=$2
196
provided_menuname=$3
197
#dialog --stdout --title "${provided_title}" --backtitle "${provided_backtitle}" \
198
#--checklist "${provided_menuname}" $TTY_Y $TTY_X $((TTY_Y - 8)) "${@:4}"
199
200
#whiptail --separate-output --title "${provided_title}" --backtitle "${provided_backtitle}" \
201
# --checklist "${provided_menuname}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
202
# "${@:4}" \
203
# 3>&1 1>&2 2>&3
204
205
whiptail --title "${provided_title}" --backtitle "${provided_backtitle}" \
206
--checklist "${provided_menuname}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
207
"${@:4}" \
208
3>&1 1>&2 2>&3
209
}
210
211
# Myy : Once we got a list of selected groups, parse the PACKAGE_LIST inside configuration.sh
212
213
DESKTOP_ELEMENTS_DIR="${EXTER}/config/desktop/${RELEASE}"
214
DESKTOP_CONFIGS_DIR="${DESKTOP_ELEMENTS_DIR}/environments"
215
DESKTOP_CONFIG_PREFIX="config_"
216
DESKTOP_APPGROUPS_DIR="${DESKTOP_ELEMENTS_DIR}/appgroups"
217
218
desktop_element_available_for_arch() {
219
local desktop_element_path="${1}"
220
local targeted_arch="${2}"
221
222
local arch_limitation_file="${1}/only_for"
223
224
echo "Checking if ${desktop_element_path} is available for ${targeted_arch} in ${arch_limitation_file}" >> "${DEST}"/${LOG_SUBPATH}/output.log
225
if [[ -f "${arch_limitation_file}" ]]; then
226
grep -- "${targeted_arch}" "${arch_limitation_file}" > /dev/null
227
return $?
228
else
229
return 0
230
fi
231
}
232
233
desktop_element_supported() {
234
235
local desktop_element_path="${1}"
236
237
local support_level_filepath="${desktop_element_path}/support"
238
if [[ -f "${support_level_filepath}" ]]; then
239
local support_level="$(cat "${support_level_filepath}")"
240
if [[ "${support_level}" != "supported" && "${EXPERT}" != "yes" ]]; then
241
return 65
242
fi
243
244
desktop_element_available_for_arch "${desktop_element_path}" "${ARCH}"
245
if [[ $? -ne 0 ]]; then
246
return 66
247
fi
248
else
249
return 64
250
fi
251
252
return 0
253
254
}
255
256
if [[ $BUILD_DESKTOP == "yes" && -z $DESKTOP_ENVIRONMENT ]]; then
257
258
desktop_environments_prepare_menu() {
259
for desktop_env_dir in "${DESKTOP_CONFIGS_DIR}/"*; do
260
local desktop_env_name=$(basename ${desktop_env_dir})
261
local expert_infos=""
262
if [[ $BOARDFAMILY == "cix" && $desktop_env_name == xfce ]]; then
263
:
264
else
265
[[ "${EXPERT}" == "yes" ]] && expert_infos="[$(cat "${desktop_env_dir}/support" 2> /dev/null)]"
266
desktop_element_supported "${desktop_env_dir}" "${ARCH}" && options+=("${desktop_env_name}" "${desktop_env_name^} desktop environment ${expert_infos}")
267
fi
268
done
269
}
270
271
options=()
272
desktop_environments_prepare_menu
273
274
if [[ "${options[0]}" == "" ]]; then
275
exit_with_error "No desktop environment seems to be available for your board ${BOARD} (ARCH : ${ARCH} - EXPERT : ${EXPERT})"
276
fi
277
278
DESKTOP_ENVIRONMENT=$(show_menu "Choose a desktop environment" "$backtitle" "Select the default desktop environment to bundle with this image" "${options[@]}")
279
280
unset options
281
282
if [[ -z "${DESKTOP_ENVIRONMENT}" ]]; then
283
exit_with_error "No desktop environment selected..."
284
fi
285
286
fi
287
288
if [[ $BUILD_DESKTOP == "yes" ]]; then
289
# Expected environment variables :
290
# - options
291
# - ARCH
292
293
desktop_environment_check_if_valid() {
294
295
local error_msg=""
296
desktop_element_supported "${DESKTOP_ENVIRONMENT_DIRPATH}" "${ARCH}"
297
local retval=$?
298
299
if [[ ${retval} == 0 ]]; then
300
return
301
elif [[ ${retval} == 64 ]]; then
302
error_msg+="Either the desktop environment ${DESKTOP_ENVIRONMENT} does not exist "
303
error_msg+="or the file ${DESKTOP_ENVIRONMENT_DIRPATH}/support is missing"
304
elif [[ ${retval} == 65 ]]; then
305
error_msg+="Only experts can build an image with the desktop environment \"${DESKTOP_ENVIRONMENT}\", since the Armbian team won't offer any support for it (EXPERT=${EXPERT})"
306
elif [[ ${retval} == 66 ]]; then
307
error_msg+="The desktop environment \"${DESKTOP_ENVIRONMENT}\" has no packages for your targeted board architecture (BOARD=${BOARD} ARCH=${ARCH}). "
308
error_msg+="The supported boards architectures are : "
309
error_msg+="$(cat "${DESKTOP_ENVIRONMENT_DIRPATH}/only_for")"
310
fi
311
312
# supress error when cache is rebuilding
313
[[ -n "$ROOT_FS_CREATE_ONLY" ]] && exit 0
314
315
exit_with_error "${error_msg}"
316
}
317
318
DESKTOP_ENVIRONMENT_DIRPATH="${DESKTOP_CONFIGS_DIR}/${DESKTOP_ENVIRONMENT}"
319
320
desktop_environment_check_if_valid
321
fi
322
323
if [[ $BUILD_DESKTOP == "yes" && -z $DESKTOP_ENVIRONMENT_CONFIG_NAME ]]; then
324
# FIXME Check for empty folders, just in case the current maintainer
325
# messed up
326
# Note, we could also ignore it and don't show anything in the previous
327
# menu, but that hides information and make debugging harder, which I
328
# don't like. Adding desktop environments as a maintainer is not a
329
# trivial nor common task.
330
331
options=()
332
for configuration in "${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_CONFIG_PREFIX}"*; do
333
config_filename=$(basename ${configuration})
334
config_name=${config_filename#"${DESKTOP_CONFIG_PREFIX}"}
335
options+=("${config_filename}" "${config_name} configuration")
336
done
337
338
DESKTOP_ENVIRONMENT_CONFIG_NAME=$(show_menu "Choose the desktop environment config" "$backtitle" "Select the configuration for this environment.\nThese are sourced from ${desktop_environment_config_dir}" "${options[@]}")
339
unset options
340
341
if [[ -z $DESKTOP_ENVIRONMENT_CONFIG_NAME ]]; then
342
exit_with_error "No desktop configuration selected... Do you really want a desktop environment ?"
343
fi
344
fi
345
346
if [[ $BUILD_DESKTOP == "yes" ]]; then
347
DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH="${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}"
348
DESKTOP_ENVIRONMENT_PACKAGE_LIST_FILEPATH="${DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH}/packages"
349
fi
350
351
# "-z ${VAR+x}" allows to check for unset variable
352
# Technically, someone might want to build a desktop with no additional
353
# appgroups.
354
if [[ $BUILD_DESKTOP == "yes" && -z ${DESKTOP_APPGROUPS_SELECTED+x} && ${RELEASE} != "raspi" ]]; then
355
356
options=()
357
for appgroup_path in "${DESKTOP_APPGROUPS_DIR}/"*; do
358
appgroup="$(basename "${appgroup_path}")"
359
options+=("${appgroup}" "${appgroup^}" off)
360
done
361
362
DESKTOP_APPGROUPS_SELECTED=$(\
363
show_select_menu \
364
"Choose desktop softwares to add" \
365
"$backtitle" \
366
"Select which kind of softwares you'd like to add to your build" \
367
"${options[@]}")
368
369
DESKTOP_APPGROUPS_SELECTED=${DESKTOP_APPGROUPS_SELECTED//\"/}
370
371
unset options
372
fi
373
374
#exit_with_error 'Testing'
375
376
# Expected variables
377
# - aggregated_content
378
# - potential_paths
379
# - separator
380
# Write to variables :
381
# - aggregated_content
382
aggregate_content() {
383
LOG_OUTPUT_FILE="${SRC}/output/${LOG_SUBPATH}/potential-paths.log"
384
echo -e "Potential paths :" >> "${LOG_OUTPUT_FILE}"
385
show_checklist_variables potential_paths
386
for filepath in ${potential_paths}; do
387
if [[ -f "${filepath}" ]]; then
388
echo -e "${filepath/"$EXTER"\//} yes" >> "${LOG_OUTPUT_FILE}"
389
aggregated_content+=$(cat "${filepath}")
390
aggregated_content+="${separator}"
391
# else
392
# echo -e "${filepath/"$EXTER"\//} no\n" >> "${LOG_OUTPUT_FILE}"
393
fi
394
395
done
396
echo "" >> "${LOG_OUTPUT_FILE}"
397
unset LOG_OUTPUT_FILE
398
}
399
400
# set unique mounting directory
401
MOUNT_UUID=$(uuidgen)
402
SDCARD="${SRC}/.tmp/rootfs-${MOUNT_UUID}"
403
MOUNT="${SRC}/.tmp/mount-${MOUNT_UUID}"
404
DESTIMG="${SRC}/.tmp/image-${MOUNT_UUID}"
405
406
# dropbear needs to be configured differently
407
[[ $CRYPTROOT_ENABLE == yes && $RELEASE == xenial ]] && exit_with_error "Encrypted rootfs is not supported in Xenial"
408
[[ $RELEASE == stretch && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Debian Stretch images with selected kernel is not supported"
409
[[ $RELEASE == bionic && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Ubuntu Bionic images with selected kernel is not supported"
410
[[ $RELEASE == hirsute && $HOSTRELEASE == focal ]] && exit_with_error "Building Ubuntu Hirsute images requires Hirsute build host. Please upgrade your host or select a different target OS"
411
412
[[ -n $ATFSOURCE && -z $ATF_USE_GCC ]] && exit_with_error "Error in configuration: ATF_USE_GCC is unset"
413
[[ -z $UBOOT_USE_GCC ]] && exit_with_error "Error in configuration: UBOOT_USE_GCC is unset"
414
[[ -z $KERNEL_USE_GCC ]] && exit_with_error "Error in configuration: KERNEL_USE_GCC is unset"
415
416
BOOTCONFIG_VAR_NAME=BOOTCONFIG_${BRANCH^^}
417
[[ -n ${!BOOTCONFIG_VAR_NAME} ]] && BOOTCONFIG=${!BOOTCONFIG_VAR_NAME}
418
[[ -z $LINUXCONFIG ]] && LINUXCONFIG="linux-${LINUXFAMILY}-${BRANCH}"
419
[[ -z $BOOTPATCHDIR ]] && BOOTPATCHDIR="u-boot-$LINUXFAMILY"
420
[[ -z $ATFPATCHDIR ]] && ATFPATCHDIR="atf-$LINUXFAMILY"
421
[[ -z $KERNELPATCHDIR ]] && KERNELPATCHDIR="$LINUXFAMILY-$BRANCH"
422
423
if [[ "$RELEASE" =~ ^(xenial|bionic|focal|hirsute|impish|jammy|noble)$ ]]; then
424
DISTRIBUTION="Ubuntu"
425
elif [[ "$RELEASE" == raspi ]]; then
426
DISTRIBUTION="Bullseye"
427
else
428
DISTRIBUTION="Debian"
429
fi
430
431
CLI_CONFIG_PATH="${EXTER}/config/cli/${RELEASE}"
432
DEBOOTSTRAP_CONFIG_PATH="${CLI_CONFIG_PATH}/debootstrap"
433
434
if [[ $? != 0 ]]; then
435
exit_with_error "The desktop environment ${DESKTOP_ENVIRONMENT} is not available for your architecture ${ARCH}"
436
fi
437
438
AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS="
439
${EXTER}/config
440
${EXTER}/config/optional/_any_board/_config
441
${EXTER}/config/optional/architectures/${ARCH}/_config
442
${EXTER}/config/optional/families/${LINUXFAMILY}/_config
443
${EXTER}/config/optional/boards/${BOARD}/_config
444
${USERPATCHES_PATH}
445
"
446
447
DEBOOTSTRAP_SEARCH_RELATIVE_DIRS="
448
cli/_all_distributions/debootstrap
449
cli/${RELEASE}/debootstrap
450
"
451
452
CLI_SEARCH_RELATIVE_DIRS="
453
cli/_all_distributions/main
454
cli/${RELEASE}/main
455
"
456
457
PACKAGES_SEARCH_ROOT_ABSOLUTE_DIRS="
458
${EXTER}/packages
459
${EXTER}/config/optional/_any_board/_packages
460
${EXTER}/config/optional/architectures/${ARCH}/_packages
461
${EXTER}/config/optional/families/${LINUXFAMILY}/_packages
462
${EXTER}/config/optional/boards/${BOARD}/_packages
463
"
464
465
DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS="
466
desktop/_all_distributions/environments/_all_environments
467
desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}
468
desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}
469
desktop/${RELEASE}/environments/_all_environments
470
desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}
471
desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}
472
"
473
474
DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS="
475
desktop/_all_distributions/appgroups
476
desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}/appgroups
477
desktop/${RELEASE}/appgroups
478
desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/appgroups
479
"
480
481
get_all_potential_paths() {
482
local root_dirs="${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}"
483
local rel_dirs="${1}"
484
local sub_dirs="${2}"
485
local looked_up_subpath="${3}"
486
for root_dir in ${root_dirs}; do
487
for rel_dir in ${rel_dirs}; do
488
for sub_dir in ${sub_dirs}; do
489
potential_paths+="${root_dir}/${rel_dir}/${sub_dir}/${looked_up_subpath} "
490
done
491
done
492
done
493
# for ppath in ${potential_paths}; do
494
# echo "Checking for ${ppath}"
495
# if [[ -f "${ppath}" ]]; then
496
# echo "OK !|"
497
# else
498
# echo "Nope|"
499
# fi
500
# done
501
}
502
503
# Environment variables expected :
504
# - aggregated_content
505
# Arguments :
506
# 1. File to look up in each directory
507
# 2. The separator to add between each concatenated file
508
# 3. Relative directories paths added to ${3}
509
# 4. Relative directories paths added to ${4}
510
#
511
# The function will basically generate a list of potential paths by
512
# generating all the potential paths combinations leading to the
513
# looked up file
514
# ${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}/${3}/${4}/${1}
515
# Then it will concatenate the content of all the available files
516
# into ${aggregated_content}
517
#
518
# TODO :
519
# ${4} could be removed by just adding the appropriate paths to ${3}
520
# dynamically for each case
521
# (debootstrap, cli, desktop environments, desktop appgroups, ...)
522
523
aggregate_all_root_rel_sub() {
524
local separator="${2}"
525
526
local potential_paths=""
527
get_all_potential_paths "${3}" "${4}" "${1}"
528
529
aggregate_content
530
}
531
532
aggregate_all_debootstrap() {
533
local sub_dirs_to_check=". "
534
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
535
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
536
fi
537
aggregate_all_root_rel_sub "${1}" "${2}" "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"
538
}
539
540
aggregate_all_cli() {
541
local sub_dirs_to_check=". "
542
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
543
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
544
fi
545
aggregate_all_root_rel_sub "${1}" "${2}" "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"
546
}
547
548
aggregate_all_desktop() {
549
aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "."
550
aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}"
551
}
552
553
one_line() {
554
local aggregate_func_name="${1}"
555
local aggregated_content=""
556
shift 1
557
$aggregate_func_name "${@}"
558
cleanup_list aggregated_content
559
}
560
561
DEBOOTSTRAP_LIST="$(one_line aggregate_all_debootstrap "packages" " ")"
562
DEBOOTSTRAP_COMPONENTS="$(one_line aggregate_all_debootstrap "components" " ")"
563
DEBOOTSTRAP_COMPONENTS="${DEBOOTSTRAP_COMPONENTS// /,}"
564
PACKAGE_LIST="$(one_line aggregate_all_cli "packages" " ")"
565
PACKAGE_LIST_ADDITIONAL="$(one_line aggregate_all_cli "packages.additional" " ")"
566
567
LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/debootstrap-list.log"
568
show_checklist_variables "DEBOOTSTRAP_LIST DEBOOTSTRAP_COMPONENTS PACKAGE_LIST PACKAGE_LIST_ADDITIONAL PACKAGE_LIST_UNINSTALL"
569
570
# Dependent desktop packages
571
# Myy : Sources packages from file here
572
573
# Myy : FIXME Rename aggregate_all to aggregate_all_desktop
574
if [[ $BUILD_DESKTOP == "yes" ]]; then
575
PACKAGE_LIST_DESKTOP+="$(one_line aggregate_all_desktop "packages" " ")"
576
echo -e "\nGroups selected ${DESKTOP_APPGROUPS_SELECTED} -> PACKAGES :" >> "${LOG_OUTPUT_FILE}"
577
show_checklist_variables PACKAGE_LIST_DESKTOP
578
fi
579
unset LOG_OUTPUT_FILE
580
581
DEBIAN_MIRROR='deb.debian.org/debian'
582
DEBIAN_SECURTY='security.debian.org/'
583
UBUNTU_MIRROR='ports.ubuntu.com/'
584
RASPI_MIRROR='archive.raspberrypi.org/debian/'
585
586
if [[ $DOWNLOAD_MIRROR == "china" ]] ; then
587
588
if [[ ${CHINA_DOWNLOAD_MIRROR} == tsinghua ]]; then
589
DEBIAN_MIRROR='mirrors.tuna.tsinghua.edu.cn/debian'
590
DEBIAN_SECURTY='mirrors.tuna.tsinghua.edu.cn/debian-security'
591
UBUNTU_MIRROR='mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/'
592
fi
593
594
if [[ ${CHINA_DOWNLOAD_MIRROR} == huawei ]]; then
595
DEBIAN_MIRROR='repo.huaweicloud.com/debian'
596
DEBIAN_SECURTY='repo.huaweicloud.com/debian-security'
597
UBUNTU_MIRROR='repo.huaweicloud.com/ubuntu-ports/'
598
fi
599
600
RASPI_MIRROR='mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/'
601
602
fi
603
604
if [[ $DOWNLOAD_MIRROR == "bfsu" ]] ; then
605
DEBIAN_MIRROR='mirrors.bfsu.edu.cn/debian'
606
DEBIAN_SECURTY='mirrors.bfsu.edu.cn/debian-security'
607
UBUNTU_MIRROR='mirrors.bfsu.edu.cn/ubuntu-ports/'
608
fi
609
610
if [[ "${ARCH}" == "amd64" ]]; then
611
UBUNTU_MIRROR='archive.ubuntu.com/ubuntu' # ports are only for non-amd64, of course.
612
613
if [[ -n ${CUSTOM_UBUNTU_MIRROR} ]]; then # ubuntu redirector doesn't work well on amd64
614
UBUNTU_MIRROR="${CUSTOM_UBUNTU_MIRROR}"
615
fi
616
fi
617
618
# don't use mirrors that throws garbage on 404
619
if [[ -z ${ARMBIAN_MIRROR} ]]; then
620
while true; do
621
622
ARMBIAN_MIRROR=$(wget -SO- -T 1 -t 1 https://redirect.armbian.com 2>&1 | egrep -i "Location" | awk '{print $2}' | head -1)
623
[[ ${ARMBIAN_MIRROR} != *armbian.hosthatch* ]] && break
624
625
done
626
fi
627
628
# For (late) user override.
629
# Notice: it is too late to define hook functions or add extensions in lib.config, since the extension initialization already ran by now.
630
# in case the user tries to use them in lib.config, hopefully they'll be detected as "wishful hooking" and the user will be wrn'ed.
631
if [[ -f $USERPATCHES_PATH/lib.config ]]; then
632
display_alert "Using user configuration override" "$USERPATCHES_PATH/lib.config" "info"
633
source "$USERPATCHES_PATH"/lib.config
634
fi
635
636
call_extension_method "user_config" << 'USER_CONFIG'
637
*Invoke function with user override*
638
Allows for overriding configuration values set anywhere else.
639
It is called after sourcing the `lib.config` file if it exists,
640
but before assembling any package lists.
641
USER_CONFIG
642
643
call_extension_method "extension_prepare_config" << 'EXTENSION_PREPARE_CONFIG'
644
*allow extensions to prepare their own config, after user config is done*
645
Implementors should preserve variable values pre-set, but can default values an/or validate them.
646
This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user.
647
EXTENSION_PREPARE_CONFIG
648
649
# apt-cacher-ng mirror configurarion
650
if [[ $DISTRIBUTION == Ubuntu ]]; then
651
APT_MIRROR=$UBUNTU_MIRROR
652
else
653
APT_MIRROR=$DEBIAN_MIRROR
654
fi
655
656
[[ -n $APT_PROXY_ADDR ]] && display_alert "Using custom apt-cacher-ng address" "$APT_PROXY_ADDR" "info"
657
658
# Build final package list after possible override
659
PACKAGE_LIST="$PACKAGE_LIST $PACKAGE_LIST_RELEASE $PACKAGE_LIST_ADDITIONAL"
660
PACKAGE_MAIN_LIST="$(cleanup_list PACKAGE_LIST)"
661
662
[[ $BUILD_DESKTOP == yes ]] && PACKAGE_LIST="$PACKAGE_LIST $PACKAGE_LIST_DESKTOP"
663
PACKAGE_LIST="$(cleanup_list PACKAGE_LIST)"
664
665
# remove any packages defined in PACKAGE_LIST_RM in lib.config
666
aggregated_content="${PACKAGE_LIST_RM} "
667
aggregate_all_cli "packages.remove" " "
668
aggregate_all_desktop "packages.remove" " "
669
PACKAGE_LIST_RM="$(cleanup_list aggregated_content)"
670
unset aggregated_content
671
672
aggregated_content=""
673
aggregate_all_cli "packages.uninstall" " "
674
aggregate_all_desktop "packages.uninstall" " "
675
PACKAGE_LIST_UNINSTALL="$(cleanup_list aggregated_content)"
676
unset aggregated_content
677
678
679
if [[ -n $PACKAGE_LIST_RM ]]; then
680
display_alert "Package remove list ${PACKAGE_LIST_RM}"
681
# Turns out that \b can be tricked by dashes.
682
# So if you remove mesa-utils but still want to install "mesa-utils-extra"
683
# a "\b(mesa-utils)\b" filter will convert "mesa-utils-extra" to "-extra".
684
# \W is not tricked by this but consumes the surrounding spaces, so we
685
# replace the occurence by one space, to avoid sticking the next word to
686
# the previous one after consuming the spaces.
687
DEBOOTSTRAP_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${DEBOOTSTRAP_LIST} ")
688
PACKAGE_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_LIST} ")
689
PACKAGE_MAIN_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_MAIN_LIST} ")
690
if [[ $BUILD_DESKTOP == "yes" ]]; then
691
PACKAGE_LIST_DESKTOP=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_LIST_DESKTOP} ")
692
# Removing double spaces... AGAIN, since we might have used a sed on them
693
# Do not quote the variables. This would defeat the trick.
694
PACKAGE_LIST_DESKTOP="$(echo ${PACKAGE_LIST_DESKTOP})"
695
fi
696
697
# Removing double spaces... AGAIN, since we might have used a sed on them
698
# Do not quote the variables. This would defeat the trick.
699
DEBOOTSTRAP_LIST="$(echo ${DEBOOTSTRAP_LIST})"
700
PACKAGE_LIST="$(echo ${PACKAGE_LIST})"
701
PACKAGE_MAIN_LIST="$(echo ${PACKAGE_MAIN_LIST})"
702
fi
703
704
705
LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/debootstrap-list.log"
706
echo -e "\nVariables after manual configuration" >>$LOG_OUTPUT_FILE
707
show_checklist_variables "DEBOOTSTRAP_COMPONENTS DEBOOTSTRAP_LIST PACKAGE_LIST PACKAGE_MAIN_LIST"
708
unset LOG_OUTPUT_FILE
709
710
# Give the option to configure DNS server used in the chroot during the build process
711
[[ -z $NAMESERVER ]] && NAMESERVER="1.0.0.1" # default is cloudflare alternate
712
713
call_extension_method "post_aggregate_packages" "user_config_post_aggregate_packages" << 'POST_AGGREGATE_PACKAGES'
714
*For final user override, using a function, after all aggregations are done*
715
Called after aggregating all package lists, before the end of `compilation.sh`.
716
Packages will still be installed after this is called, so it is the last chance
717
to confirm or change any packages.
718
POST_AGGREGATE_PACKAGES
719
720
# debug
721
cat <<-EOF >> "${DEST}"/${LOG_SUBPATH}/output.log
722
723
## BUILD SCRIPT ENVIRONMENT
724
725
Repository: $REPOSITORY_URL
726
Version: $REPOSITORY_COMMIT
727
728
Host OS: $HOSTRELEASE
729
Host arch: $(dpkg --print-architecture)
730
Host system: $(uname -a)
731
Virtualization type: $(systemd-detect-virt)
732
733
## Build script directories
734
Build directory is located on:
735
$(findmnt -o TARGET,SOURCE,FSTYPE,AVAIL -T "${SRC}")
736
737
Build directory permissions:
738
$(getfacl -p "${SRC}")
739
740
Temp directory permissions:
741
$(getfacl -p "${SRC}"/.tmp 2> /dev/null)
742
743
## BUILD CONFIGURATION
744
745
Build target:
746
Board: $BOARD
747
Branch: $BRANCH
748
Minimal: $BUILD_MINIMAL
749
Desktop: $BUILD_DESKTOP
750
Desktop Environment: $DESKTOP_ENVIRONMENT
751
Software groups: $DESKTOP_APPGROUPS_SELECTED
752
753
Kernel configuration:
754
Repository: $KERNELSOURCE
755
Branch: $KERNELBRANCH
756
Config file: $LINUXCONFIG
757
758
U-boot configuration:
759
Repository: $BOOTSOURCE
760
Branch: $BOOTBRANCH
761
Config file: $BOOTCONFIG
762
763
Partitioning configuration: $IMAGE_PARTITION_TABLE offset: $OFFSET
764
Boot partition type: ${BOOTFS_TYPE:-(none)} ${BOOTSIZE:+"(${BOOTSIZE} MB)"}
765
Root partition type: $ROOTFS_TYPE ${FIXED_IMAGE_SIZE:+"(${FIXED_IMAGE_SIZE} MB)"}
766
767
CPU configuration: $CPUMIN - $CPUMAX with $GOVERNOR
768
EOF
769
770