CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/configuration.sh
Views: 3960
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
[[ "${EXPERT}" == "yes" ]] && expert_infos="[$(cat "${desktop_env_dir}/support" 2> /dev/null)]"
263
desktop_element_supported "${desktop_env_dir}" "${ARCH}" && options+=("${desktop_env_name}" "${desktop_env_name^} desktop environment ${expert_infos}")
264
done
265
}
266
267
options=()
268
desktop_environments_prepare_menu
269
270
if [[ "${options[0]}" == "" ]]; then
271
exit_with_error "No desktop environment seems to be available for your board ${BOARD} (ARCH : ${ARCH} - EXPERT : ${EXPERT})"
272
fi
273
274
DESKTOP_ENVIRONMENT=$(show_menu "Choose a desktop environment" "$backtitle" "Select the default desktop environment to bundle with this image" "${options[@]}")
275
276
unset options
277
278
if [[ -z "${DESKTOP_ENVIRONMENT}" ]]; then
279
exit_with_error "No desktop environment selected..."
280
fi
281
282
fi
283
284
if [[ $BUILD_DESKTOP == "yes" ]]; then
285
# Expected environment variables :
286
# - options
287
# - ARCH
288
289
desktop_environment_check_if_valid() {
290
291
local error_msg=""
292
desktop_element_supported "${DESKTOP_ENVIRONMENT_DIRPATH}" "${ARCH}"
293
local retval=$?
294
295
if [[ ${retval} == 0 ]]; then
296
return
297
elif [[ ${retval} == 64 ]]; then
298
error_msg+="Either the desktop environment ${DESKTOP_ENVIRONMENT} does not exist "
299
error_msg+="or the file ${DESKTOP_ENVIRONMENT_DIRPATH}/support is missing"
300
elif [[ ${retval} == 65 ]]; then
301
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})"
302
elif [[ ${retval} == 66 ]]; then
303
error_msg+="The desktop environment \"${DESKTOP_ENVIRONMENT}\" has no packages for your targeted board architecture (BOARD=${BOARD} ARCH=${ARCH}). "
304
error_msg+="The supported boards architectures are : "
305
error_msg+="$(cat "${DESKTOP_ENVIRONMENT_DIRPATH}/only_for")"
306
fi
307
308
# supress error when cache is rebuilding
309
[[ -n "$ROOT_FS_CREATE_ONLY" ]] && exit 0
310
311
exit_with_error "${error_msg}"
312
}
313
314
DESKTOP_ENVIRONMENT_DIRPATH="${DESKTOP_CONFIGS_DIR}/${DESKTOP_ENVIRONMENT}"
315
316
desktop_environment_check_if_valid
317
fi
318
319
if [[ $BUILD_DESKTOP == "yes" && -z $DESKTOP_ENVIRONMENT_CONFIG_NAME ]]; then
320
# FIXME Check for empty folders, just in case the current maintainer
321
# messed up
322
# Note, we could also ignore it and don't show anything in the previous
323
# menu, but that hides information and make debugging harder, which I
324
# don't like. Adding desktop environments as a maintainer is not a
325
# trivial nor common task.
326
327
options=()
328
for configuration in "${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_CONFIG_PREFIX}"*; do
329
config_filename=$(basename ${configuration})
330
config_name=${config_filename#"${DESKTOP_CONFIG_PREFIX}"}
331
options+=("${config_filename}" "${config_name} configuration")
332
done
333
334
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[@]}")
335
unset options
336
337
if [[ -z $DESKTOP_ENVIRONMENT_CONFIG_NAME ]]; then
338
exit_with_error "No desktop configuration selected... Do you really want a desktop environment ?"
339
fi
340
fi
341
342
if [[ $BUILD_DESKTOP == "yes" ]]; then
343
DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH="${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}"
344
DESKTOP_ENVIRONMENT_PACKAGE_LIST_FILEPATH="${DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH}/packages"
345
fi
346
347
# "-z ${VAR+x}" allows to check for unset variable
348
# Technically, someone might want to build a desktop with no additional
349
# appgroups.
350
if [[ $BUILD_DESKTOP == "yes" && -z ${DESKTOP_APPGROUPS_SELECTED+x} && ${RELEASE} != "raspi" ]]; then
351
352
options=()
353
for appgroup_path in "${DESKTOP_APPGROUPS_DIR}/"*; do
354
appgroup="$(basename "${appgroup_path}")"
355
options+=("${appgroup}" "${appgroup^}" off)
356
done
357
358
DESKTOP_APPGROUPS_SELECTED=$(\
359
show_select_menu \
360
"Choose desktop softwares to add" \
361
"$backtitle" \
362
"Select which kind of softwares you'd like to add to your build" \
363
"${options[@]}")
364
365
DESKTOP_APPGROUPS_SELECTED=${DESKTOP_APPGROUPS_SELECTED//\"/}
366
367
unset options
368
fi
369
370
#exit_with_error 'Testing'
371
372
# Expected variables
373
# - aggregated_content
374
# - potential_paths
375
# - separator
376
# Write to variables :
377
# - aggregated_content
378
aggregate_content() {
379
LOG_OUTPUT_FILE="${SRC}/output/${LOG_SUBPATH}/potential-paths.log"
380
echo -e "Potential paths :" >> "${LOG_OUTPUT_FILE}"
381
show_checklist_variables potential_paths
382
for filepath in ${potential_paths}; do
383
if [[ -f "${filepath}" ]]; then
384
echo -e "${filepath/"$EXTER"\//} yes" >> "${LOG_OUTPUT_FILE}"
385
aggregated_content+=$(cat "${filepath}")
386
aggregated_content+="${separator}"
387
# else
388
# echo -e "${filepath/"$EXTER"\//} no\n" >> "${LOG_OUTPUT_FILE}"
389
fi
390
391
done
392
echo "" >> "${LOG_OUTPUT_FILE}"
393
unset LOG_OUTPUT_FILE
394
}
395
396
# set unique mounting directory
397
MOUNT_UUID=$(uuidgen)
398
SDCARD="${SRC}/.tmp/rootfs-${MOUNT_UUID}"
399
MOUNT="${SRC}/.tmp/mount-${MOUNT_UUID}"
400
DESTIMG="${SRC}/.tmp/image-${MOUNT_UUID}"
401
402
# dropbear needs to be configured differently
403
[[ $CRYPTROOT_ENABLE == yes && $RELEASE == xenial ]] && exit_with_error "Encrypted rootfs is not supported in Xenial"
404
[[ $RELEASE == stretch && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Debian Stretch images with selected kernel is not supported"
405
[[ $RELEASE == bionic && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Ubuntu Bionic images with selected kernel is not supported"
406
[[ $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"
407
408
[[ -n $ATFSOURCE && -z $ATF_USE_GCC ]] && exit_with_error "Error in configuration: ATF_USE_GCC is unset"
409
[[ -z $UBOOT_USE_GCC ]] && exit_with_error "Error in configuration: UBOOT_USE_GCC is unset"
410
[[ -z $KERNEL_USE_GCC ]] && exit_with_error "Error in configuration: KERNEL_USE_GCC is unset"
411
412
BOOTCONFIG_VAR_NAME=BOOTCONFIG_${BRANCH^^}
413
[[ -n ${!BOOTCONFIG_VAR_NAME} ]] && BOOTCONFIG=${!BOOTCONFIG_VAR_NAME}
414
[[ -z $LINUXCONFIG ]] && LINUXCONFIG="linux-${LINUXFAMILY}-${BRANCH}"
415
[[ -z $BOOTPATCHDIR ]] && BOOTPATCHDIR="u-boot-$LINUXFAMILY"
416
[[ -z $ATFPATCHDIR ]] && ATFPATCHDIR="atf-$LINUXFAMILY"
417
[[ -z $KERNELPATCHDIR ]] && KERNELPATCHDIR="$LINUXFAMILY-$BRANCH"
418
419
if [[ "$RELEASE" =~ ^(xenial|bionic|focal|hirsute|impish|jammy|noble)$ ]]; then
420
DISTRIBUTION="Ubuntu"
421
elif [[ "$RELEASE" == raspi ]]; then
422
DISTRIBUTION="Bullseye"
423
else
424
DISTRIBUTION="Debian"
425
fi
426
427
CLI_CONFIG_PATH="${EXTER}/config/cli/${RELEASE}"
428
DEBOOTSTRAP_CONFIG_PATH="${CLI_CONFIG_PATH}/debootstrap"
429
430
if [[ $? != 0 ]]; then
431
exit_with_error "The desktop environment ${DESKTOP_ENVIRONMENT} is not available for your architecture ${ARCH}"
432
fi
433
434
AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS="
435
${EXTER}/config
436
${EXTER}/config/optional/_any_board/_config
437
${EXTER}/config/optional/architectures/${ARCH}/_config
438
${EXTER}/config/optional/families/${LINUXFAMILY}/_config
439
${EXTER}/config/optional/boards/${BOARD}/_config
440
${USERPATCHES_PATH}
441
"
442
443
DEBOOTSTRAP_SEARCH_RELATIVE_DIRS="
444
cli/_all_distributions/debootstrap
445
cli/${RELEASE}/debootstrap
446
"
447
448
CLI_SEARCH_RELATIVE_DIRS="
449
cli/_all_distributions/main
450
cli/${RELEASE}/main
451
"
452
453
PACKAGES_SEARCH_ROOT_ABSOLUTE_DIRS="
454
${EXTER}/packages
455
${EXTER}/config/optional/_any_board/_packages
456
${EXTER}/config/optional/architectures/${ARCH}/_packages
457
${EXTER}/config/optional/families/${LINUXFAMILY}/_packages
458
${EXTER}/config/optional/boards/${BOARD}/_packages
459
"
460
461
DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS="
462
desktop/_all_distributions/environments/_all_environments
463
desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}
464
desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}
465
desktop/${RELEASE}/environments/_all_environments
466
desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}
467
desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}
468
"
469
470
DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS="
471
desktop/_all_distributions/appgroups
472
desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}/appgroups
473
desktop/${RELEASE}/appgroups
474
desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/appgroups
475
"
476
477
get_all_potential_paths() {
478
local root_dirs="${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}"
479
local rel_dirs="${1}"
480
local sub_dirs="${2}"
481
local looked_up_subpath="${3}"
482
for root_dir in ${root_dirs}; do
483
for rel_dir in ${rel_dirs}; do
484
for sub_dir in ${sub_dirs}; do
485
potential_paths+="${root_dir}/${rel_dir}/${sub_dir}/${looked_up_subpath} "
486
done
487
done
488
done
489
# for ppath in ${potential_paths}; do
490
# echo "Checking for ${ppath}"
491
# if [[ -f "${ppath}" ]]; then
492
# echo "OK !|"
493
# else
494
# echo "Nope|"
495
# fi
496
# done
497
}
498
499
# Environment variables expected :
500
# - aggregated_content
501
# Arguments :
502
# 1. File to look up in each directory
503
# 2. The separator to add between each concatenated file
504
# 3. Relative directories paths added to ${3}
505
# 4. Relative directories paths added to ${4}
506
#
507
# The function will basically generate a list of potential paths by
508
# generating all the potential paths combinations leading to the
509
# looked up file
510
# ${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}/${3}/${4}/${1}
511
# Then it will concatenate the content of all the available files
512
# into ${aggregated_content}
513
#
514
# TODO :
515
# ${4} could be removed by just adding the appropriate paths to ${3}
516
# dynamically for each case
517
# (debootstrap, cli, desktop environments, desktop appgroups, ...)
518
519
aggregate_all_root_rel_sub() {
520
local separator="${2}"
521
522
local potential_paths=""
523
get_all_potential_paths "${3}" "${4}" "${1}"
524
525
aggregate_content
526
}
527
528
aggregate_all_debootstrap() {
529
local sub_dirs_to_check=". "
530
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
531
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
532
fi
533
aggregate_all_root_rel_sub "${1}" "${2}" "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"
534
}
535
536
aggregate_all_cli() {
537
local sub_dirs_to_check=". "
538
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
539
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
540
fi
541
aggregate_all_root_rel_sub "${1}" "${2}" "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"
542
}
543
544
aggregate_all_desktop() {
545
aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "."
546
aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}"
547
}
548
549
one_line() {
550
local aggregate_func_name="${1}"
551
local aggregated_content=""
552
shift 1
553
$aggregate_func_name "${@}"
554
cleanup_list aggregated_content
555
}
556
557
DEBOOTSTRAP_LIST="$(one_line aggregate_all_debootstrap "packages" " ")"
558
DEBOOTSTRAP_COMPONENTS="$(one_line aggregate_all_debootstrap "components" " ")"
559
DEBOOTSTRAP_COMPONENTS="${DEBOOTSTRAP_COMPONENTS// /,}"
560
PACKAGE_LIST="$(one_line aggregate_all_cli "packages" " ")"
561
PACKAGE_LIST_ADDITIONAL="$(one_line aggregate_all_cli "packages.additional" " ")"
562
563
LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/debootstrap-list.log"
564
show_checklist_variables "DEBOOTSTRAP_LIST DEBOOTSTRAP_COMPONENTS PACKAGE_LIST PACKAGE_LIST_ADDITIONAL PACKAGE_LIST_UNINSTALL"
565
566
# Dependent desktop packages
567
# Myy : Sources packages from file here
568
569
# Myy : FIXME Rename aggregate_all to aggregate_all_desktop
570
if [[ $BUILD_DESKTOP == "yes" ]]; then
571
PACKAGE_LIST_DESKTOP+="$(one_line aggregate_all_desktop "packages" " ")"
572
echo -e "\nGroups selected ${DESKTOP_APPGROUPS_SELECTED} -> PACKAGES :" >> "${LOG_OUTPUT_FILE}"
573
show_checklist_variables PACKAGE_LIST_DESKTOP
574
fi
575
unset LOG_OUTPUT_FILE
576
577
DEBIAN_MIRROR='deb.debian.org/debian'
578
DEBIAN_SECURTY='security.debian.org/'
579
UBUNTU_MIRROR='ports.ubuntu.com/'
580
RASPI_MIRROR='archive.raspberrypi.org/debian/'
581
582
if [[ $DOWNLOAD_MIRROR == "china" ]] ; then
583
584
if [[ ${CHINA_DOWNLOAD_MIRROR} == tsinghua ]]; then
585
DEBIAN_MIRROR='mirrors.tuna.tsinghua.edu.cn/debian'
586
DEBIAN_SECURTY='mirrors.tuna.tsinghua.edu.cn/debian-security'
587
UBUNTU_MIRROR='mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/'
588
fi
589
590
if [[ ${CHINA_DOWNLOAD_MIRROR} == huawei ]]; then
591
DEBIAN_MIRROR='repo.huaweicloud.com/debian'
592
DEBIAN_SECURTY='repo.huaweicloud.com/debian-security'
593
UBUNTU_MIRROR='repo.huaweicloud.com/ubuntu-ports/'
594
fi
595
596
RASPI_MIRROR='mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/'
597
598
fi
599
600
if [[ $DOWNLOAD_MIRROR == "bfsu" ]] ; then
601
DEBIAN_MIRROR='mirrors.bfsu.edu.cn/debian'
602
DEBIAN_SECURTY='mirrors.bfsu.edu.cn/debian-security'
603
UBUNTU_MIRROR='mirrors.bfsu.edu.cn/ubuntu-ports/'
604
fi
605
606
if [[ "${ARCH}" == "amd64" ]]; then
607
UBUNTU_MIRROR='archive.ubuntu.com/ubuntu' # ports are only for non-amd64, of course.
608
609
if [[ -n ${CUSTOM_UBUNTU_MIRROR} ]]; then # ubuntu redirector doesn't work well on amd64
610
UBUNTU_MIRROR="${CUSTOM_UBUNTU_MIRROR}"
611
fi
612
fi
613
614
# don't use mirrors that throws garbage on 404
615
if [[ -z ${ARMBIAN_MIRROR} ]]; then
616
while true; do
617
618
ARMBIAN_MIRROR=$(wget -SO- -T 1 -t 1 https://redirect.armbian.com 2>&1 | egrep -i "Location" | awk '{print $2}' | head -1)
619
[[ ${ARMBIAN_MIRROR} != *armbian.hosthatch* ]] && break
620
621
done
622
fi
623
624
# For (late) user override.
625
# Notice: it is too late to define hook functions or add extensions in lib.config, since the extension initialization already ran by now.
626
# 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.
627
if [[ -f $USERPATCHES_PATH/lib.config ]]; then
628
display_alert "Using user configuration override" "$USERPATCHES_PATH/lib.config" "info"
629
source "$USERPATCHES_PATH"/lib.config
630
fi
631
632
call_extension_method "user_config" << 'USER_CONFIG'
633
*Invoke function with user override*
634
Allows for overriding configuration values set anywhere else.
635
It is called after sourcing the `lib.config` file if it exists,
636
but before assembling any package lists.
637
USER_CONFIG
638
639
call_extension_method "extension_prepare_config" << 'EXTENSION_PREPARE_CONFIG'
640
*allow extensions to prepare their own config, after user config is done*
641
Implementors should preserve variable values pre-set, but can default values an/or validate them.
642
This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user.
643
EXTENSION_PREPARE_CONFIG
644
645
# apt-cacher-ng mirror configurarion
646
if [[ $DISTRIBUTION == Ubuntu ]]; then
647
APT_MIRROR=$UBUNTU_MIRROR
648
else
649
APT_MIRROR=$DEBIAN_MIRROR
650
fi
651
652
[[ -n $APT_PROXY_ADDR ]] && display_alert "Using custom apt-cacher-ng address" "$APT_PROXY_ADDR" "info"
653
654
# Build final package list after possible override
655
PACKAGE_LIST="$PACKAGE_LIST $PACKAGE_LIST_RELEASE $PACKAGE_LIST_ADDITIONAL"
656
PACKAGE_MAIN_LIST="$(cleanup_list PACKAGE_LIST)"
657
658
[[ $BUILD_DESKTOP == yes ]] && PACKAGE_LIST="$PACKAGE_LIST $PACKAGE_LIST_DESKTOP"
659
PACKAGE_LIST="$(cleanup_list PACKAGE_LIST)"
660
661
# remove any packages defined in PACKAGE_LIST_RM in lib.config
662
aggregated_content="${PACKAGE_LIST_RM} "
663
aggregate_all_cli "packages.remove" " "
664
aggregate_all_desktop "packages.remove" " "
665
PACKAGE_LIST_RM="$(cleanup_list aggregated_content)"
666
unset aggregated_content
667
668
aggregated_content=""
669
aggregate_all_cli "packages.uninstall" " "
670
aggregate_all_desktop "packages.uninstall" " "
671
PACKAGE_LIST_UNINSTALL="$(cleanup_list aggregated_content)"
672
unset aggregated_content
673
674
675
if [[ -n $PACKAGE_LIST_RM ]]; then
676
display_alert "Package remove list ${PACKAGE_LIST_RM}"
677
# Turns out that \b can be tricked by dashes.
678
# So if you remove mesa-utils but still want to install "mesa-utils-extra"
679
# a "\b(mesa-utils)\b" filter will convert "mesa-utils-extra" to "-extra".
680
# \W is not tricked by this but consumes the surrounding spaces, so we
681
# replace the occurence by one space, to avoid sticking the next word to
682
# the previous one after consuming the spaces.
683
DEBOOTSTRAP_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${DEBOOTSTRAP_LIST} ")
684
PACKAGE_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_LIST} ")
685
PACKAGE_MAIN_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_MAIN_LIST} ")
686
if [[ $BUILD_DESKTOP == "yes" ]]; then
687
PACKAGE_LIST_DESKTOP=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_LIST_DESKTOP} ")
688
# Removing double spaces... AGAIN, since we might have used a sed on them
689
# Do not quote the variables. This would defeat the trick.
690
PACKAGE_LIST_DESKTOP="$(echo ${PACKAGE_LIST_DESKTOP})"
691
fi
692
693
# Removing double spaces... AGAIN, since we might have used a sed on them
694
# Do not quote the variables. This would defeat the trick.
695
DEBOOTSTRAP_LIST="$(echo ${DEBOOTSTRAP_LIST})"
696
PACKAGE_LIST="$(echo ${PACKAGE_LIST})"
697
PACKAGE_MAIN_LIST="$(echo ${PACKAGE_MAIN_LIST})"
698
fi
699
700
701
LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/debootstrap-list.log"
702
echo -e "\nVariables after manual configuration" >>$LOG_OUTPUT_FILE
703
show_checklist_variables "DEBOOTSTRAP_COMPONENTS DEBOOTSTRAP_LIST PACKAGE_LIST PACKAGE_MAIN_LIST"
704
unset LOG_OUTPUT_FILE
705
706
# Give the option to configure DNS server used in the chroot during the build process
707
[[ -z $NAMESERVER ]] && NAMESERVER="1.0.0.1" # default is cloudflare alternate
708
709
call_extension_method "post_aggregate_packages" "user_config_post_aggregate_packages" << 'POST_AGGREGATE_PACKAGES'
710
*For final user override, using a function, after all aggregations are done*
711
Called after aggregating all package lists, before the end of `compilation.sh`.
712
Packages will still be installed after this is called, so it is the last chance
713
to confirm or change any packages.
714
POST_AGGREGATE_PACKAGES
715
716
# debug
717
cat <<-EOF >> "${DEST}"/${LOG_SUBPATH}/output.log
718
719
## BUILD SCRIPT ENVIRONMENT
720
721
Repository: $REPOSITORY_URL
722
Version: $REPOSITORY_COMMIT
723
724
Host OS: $HOSTRELEASE
725
Host arch: $(dpkg --print-architecture)
726
Host system: $(uname -a)
727
Virtualization type: $(systemd-detect-virt)
728
729
## Build script directories
730
Build directory is located on:
731
$(findmnt -o TARGET,SOURCE,FSTYPE,AVAIL -T "${SRC}")
732
733
Build directory permissions:
734
$(getfacl -p "${SRC}")
735
736
Temp directory permissions:
737
$(getfacl -p "${SRC}"/.tmp 2> /dev/null)
738
739
## BUILD CONFIGURATION
740
741
Build target:
742
Board: $BOARD
743
Branch: $BRANCH
744
Minimal: $BUILD_MINIMAL
745
Desktop: $BUILD_DESKTOP
746
Desktop Environment: $DESKTOP_ENVIRONMENT
747
Software groups: $DESKTOP_APPGROUPS_SELECTED
748
749
Kernel configuration:
750
Repository: $KERNELSOURCE
751
Branch: $KERNELBRANCH
752
Config file: $LINUXCONFIG
753
754
U-boot configuration:
755
Repository: $BOOTSOURCE
756
Branch: $BOOTBRANCH
757
Config file: $BOOTCONFIG
758
759
Partitioning configuration: $IMAGE_PARTITION_TABLE offset: $OFFSET
760
Boot partition type: ${BOOTFS_TYPE:-(none)} ${BOOTSIZE:+"(${BOOTSIZE} MB)"}
761
Root partition type: $ROOTFS_TYPE ${FIXED_IMAGE_SIZE:+"(${FIXED_IMAGE_SIZE} MB)"}
762
763
CPU configuration: $CPUMIN - $CPUMAX with $GOVERNOR
764
EOF
765
766