Path: blob/next/scripts/configuration.sh
15181 views
#!/bin/bash1#2# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com3#4# This file is licensed under the terms of the GNU General Public5# License version 2. This program is licensed "as is" without any6# warranty of any kind, whether express or implied.789[[ -z $VENDOR ]] && VENDOR="Orange Pi"10[[ -z $ROOTPWD ]] && ROOTPWD="orangepi" # Must be changed @first login11[[ -z $OPI_USERNAME ]] && OPI_USERNAME="orangepi"12[[ -z $OPI_PWD ]] && OPI_PWD="orangepi"13[[ -z $MAINTAINER ]] && MAINTAINER="Orange Pi" # deb signature14[[ -z $MAINTAINERMAIL ]] && MAINTAINERMAIL="[email protected]" # deb signature15[[ -z $DEB_COMPRESS ]] && DEB_COMPRESS="xz" # compress .debs with XZ by default. Use 'none' for faster/larger builds16TZDATA=$(cat /etc/timezone) # Timezone for target is taken from host or defined here.17USEALLCORES=yes # Use all CPU cores for compiling18HOSTRELEASE=$(cat /etc/os-release | grep VERSION_CODENAME | cut -d"=" -f2)19[[ -z $HOSTRELEASE ]] && HOSTRELEASE=$(cut -d'/' -f1 /etc/debian_version)20[[ -z $EXIT_PATCHING_ERROR ]] && EXIT_PATCHING_ERROR="" # exit patching if failed21[[ -z $HOST ]] && HOST="$BOARD" # set hostname to the board22[[ -z $CHINA_DOWNLOAD_MIRROR ]] && CHINA_DOWNLOAD_MIRROR=huawei23cd "${SRC}" || exit24[[ -z "${ROOTFSCACHE_VERSION}" ]] && ROOTFSCACHE_VERSION=1125[[ -z "${CHROOT_CACHE_VERSION}" ]] && CHROOT_CACHE_VERSION=726[[ -z $PLYMOUTH ]] && PLYMOUTH="yes"2728cd ${SRC}/scripts29BUILD_REPOSITORY_URL=$(improved_git remote get-url $(improved_git remote 2>/dev/null | grep origin) 2>/dev/null)30BUILD_REPOSITORY_COMMIT=$(improved_git describe --match=d_e_a_d_b_e_e_f --always --dirty 2>/dev/null)31ROOTFS_CACHE_MAX=200 # max number of rootfs cache, older ones will be cleaned up3233DEB_STORAGE=$DEST/debs34DEB_ORANGEPI=$EXTER/cache/debs3536# TODO: fixed name can't be used for parallel image building37ROOT_MAPPER="orangepi-root"38[[ -z $ROOTFS_TYPE ]] && ROOTFS_TYPE=ext4 # default rootfs type is ext439[[ "ext4 f2fs btrfs xfs nfs fel" != *$ROOTFS_TYPE* ]] && exit_with_error "Unknown rootfs type" "$ROOTFS_TYPE"4041[[ -z $BTRFS_COMPRESSION ]] && BTRFS_COMPRESSION=zlib # default btrfs filesystem compression method is zlib42[[ ! $BTRFS_COMPRESSION =~ zlib|lzo|zstd|none ]] && exit_with_error "Unknown btrfs compression method" "$BTRFS_COMPRESSION"4344# Fixed image size is in 1M dd blocks (MiB)45# to get size of block device /dev/sdX execute as root:46# echo $(( $(blockdev --getsize64 /dev/sdX) / 1024 / 1024 ))47[[ "f2fs" == *$ROOTFS_TYPE* && -z $FIXED_IMAGE_SIZE ]] && exit_with_error "Please define FIXED_IMAGE_SIZE"4849# a passphrase is mandatory if rootfs encryption is enabled50if [[ $CRYPTROOT_ENABLE == yes && -z $CRYPTROOT_PASSPHRASE ]]; then51exit_with_error "Root encryption is enabled but CRYPTROOT_PASSPHRASE is not set"52fi5354# small SD card with kernel, boot script and .dtb/.bin files55[[ $ROOTFS_TYPE == nfs ]] && FIXED_IMAGE_SIZE=645657# Since we are having too many options for mirror management,58# then here is yet another mirror related option.59# Respecting user's override in case a mirror is unreachable.60case $REGIONAL_MIRROR in61china)62[[ -z $USE_MAINLINE_GOOGLE_MIRROR ]] && [[ -z $MAINLINE_MIRROR ]] && MAINLINE_MIRROR=tuna63[[ -z $USE_GITHUB_UBOOT_MIRROR ]] && [[ -z $UBOOT_MIRROR ]] && UBOOT_MIRROR=gitee64[[ -z $GITHUB_MIRROR ]] && GITHUB_MIRROR=gitclone65[[ -z $DOWNLOAD_MIRROR ]] && DOWNLOAD_MIRROR=china66;;67*)68;;69esac7071# used by multiple sources - reduce code duplication72[[ $USE_MAINLINE_GOOGLE_MIRROR == yes ]] && MAINLINE_MIRROR=google7374case $MAINLINE_MIRROR in75google)76MAINLINE_KERNEL_SOURCE='https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable'77MAINLINE_FIRMWARE_SOURCE='https://kernel.googlesource.com/pub/scm/linux/kernel/git/firmware/linux-firmware.git'78;;79tuna)80MAINLINE_KERNEL_SOURCE='https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git'81MAINLINE_FIRMWARE_SOURCE='https://mirrors.tuna.tsinghua.edu.cn/git/linux-firmware.git'82;;83bfsu)84MAINLINE_KERNEL_SOURCE='https://mirrors.bfsu.edu.cn/git/linux-stable.git'85MAINLINE_FIRMWARE_SOURCE='https://mirrors.bfsu.edu.cn/git/linux-firmware.git'86;;87*)88MAINLINE_KERNEL_SOURCE='git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git'89MAINLINE_FIRMWARE_SOURCE='git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git'90;;91esac9293MAINLINE_KERNEL_DIR="$SRC/kernel"9495[[ $USE_GITHUB_UBOOT_MIRROR == yes ]] && UBOOT_MIRROR=github9697case $UBOOT_MIRROR in98gitee)99MAINLINE_UBOOT_SOURCE='https://github.com/orangepi-xunlong/u-boot-orangepi.git'100;;101github)102MAINLINE_UBOOT_SOURCE='https://github.com/orangepi-xunlong/u-boot-orangepi.git'103;;104*)105MAINLINE_UBOOT_SOURCE='https://source.denx.de/u-boot/u-boot.git'106;;107esac108109MAINLINE_UBOOT_DIR="$SRC/u-boot"110111case $GITHUB_MIRROR in112fastgit)113GITHUB_SOURCE='https://hub.fastgit.xyz'114;;115gitclone)116GITHUB_SOURCE='https://gitclone.com/github.com'117;;118*)119GITHUB_SOURCE='https://github.com'120;;121esac122123# Let's set default data if not defined in board configuration above124[[ -z $OFFSET ]] && OFFSET=4 # offset to 1st partition (we use 4MiB boundaries by default)125ARCH=armhf126KERNEL_IMAGE_TYPE=zImage127CAN_BUILD_STRETCH=yes128ATF_COMPILE=yes129[[ -z $CRYPTROOT_SSH_UNLOCK ]] && CRYPTROOT_SSH_UNLOCK=yes130[[ -z $CRYPTROOT_SSH_UNLOCK_PORT ]] && CRYPTROOT_SSH_UNLOCK_PORT=2022131# Default to pdkdf2, this used to be the default with cryptroot <= 2.0, however132# cryptroot 2.1 changed that to Argon2i. Argon2i is a memory intensive133# algorithm which doesn't play well with SBCs (need 1GiB RAM by default !)134# https://gitlab.com/cryptsetup/cryptsetup/-/issues/372135[[ -z $CRYPTROOT_PARAMETERS ]] && CRYPTROOT_PARAMETERS="--pbkdf pbkdf2"136[[ -z $WIREGUARD ]] && WIREGUARD="no"137[[ -z $EXTRAWIFI ]] && EXTRAWIFI="yes"138[[ -z $SKIP_BOOTSPLASH ]] && SKIP_BOOTSPLASH="no"139[[ -z $AUFS ]] && AUFS="yes"140[[ -z $IMAGE_PARTITION_TABLE ]] && IMAGE_PARTITION_TABLE="msdos"141[[ -z $EXTRA_BSP_NAME ]] && EXTRA_BSP_NAME=""142[[ -z $EXTRA_ROOTFS_MIB_SIZE ]] && EXTRA_ROOTFS_MIB_SIZE=0143[[ -z $BUILD_KSRC ]] && BUILD_KSRC="no"144145# single ext4 partition is the default and preferred configuration146#BOOTFS_TYPE=''147[[ ! -f ${EXTER}/config/sources/families/$LINUXFAMILY.conf ]] && \148exit_with_error "Sources configuration not found" "$LINUXFAMILY"149150source "${EXTER}/config/sources/families/${LINUXFAMILY}.conf"151152if [[ -f $USERPATCHES_PATH/sources/families/$LINUXFAMILY.conf ]]; then153display_alert "Adding user provided $LINUXFAMILY overrides"154source "$USERPATCHES_PATH/sources/families/${LINUXFAMILY}.conf"155fi156157# load architecture defaults158source "${EXTER}/config/sources/${ARCH}.conf"159160## Extensions: at this point we've sourced all the config files that will be used,161## and (hopefully) not yet invoked any extension methods. So this is the perfect162## place to initialize the extension manager. It will create functions163## like the 'post_family_config' that is invoked below.164initialize_extension_manager165166call_extension_method "post_family_config" "config_tweaks_post_family_config" << 'POST_FAMILY_CONFIG'167*give the config a chance to override the family/arch defaults*168This hook is called after the family configuration (`sources/families/xxx.conf`) is sourced.169Since the family can override values from the user configuration and the board configuration,170it is often used to in turn override those.171POST_FAMILY_CONFIG172173# Myy : Menu configuration for choosing desktop configurations174175show_menu() {176provided_title=$1177provided_backtitle=$2178provided_menuname=$3179# Myy : I don't know why there's a TTY_Y - 8...180#echo "Provided title : $provided_title"181#echo "Provided backtitle : $provided_backtitle"182#echo "Provided menuname : $provided_menuname"183#echo "Provided options : " "${@:4}"184#echo "TTY X: $TTY_X Y: $TTY_Y"185whiptail --title "${provided_title}" --backtitle "${provided_backtitle}" --notags \186--menu "${provided_menuname}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \187"${@:4}" \1883>&1 1>&2 2>&3189}190191# Myy : FIXME Factorize192show_select_menu() {193provided_title=$1194provided_backtitle=$2195provided_menuname=$3196#dialog --stdout --title "${provided_title}" --backtitle "${provided_backtitle}" \197#--checklist "${provided_menuname}" $TTY_Y $TTY_X $((TTY_Y - 8)) "${@:4}"198199#whiptail --separate-output --title "${provided_title}" --backtitle "${provided_backtitle}" \200# --checklist "${provided_menuname}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \201# "${@:4}" \202# 3>&1 1>&2 2>&3203204whiptail --title "${provided_title}" --backtitle "${provided_backtitle}" \205--checklist "${provided_menuname}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \206"${@:4}" \2073>&1 1>&2 2>&3208}209210# Myy : Once we got a list of selected groups, parse the PACKAGE_LIST inside configuration.sh211212DESKTOP_ELEMENTS_DIR="${EXTER}/config/desktop/${RELEASE}"213DESKTOP_CONFIGS_DIR="${DESKTOP_ELEMENTS_DIR}/environments"214DESKTOP_CONFIG_PREFIX="config_"215DESKTOP_APPGROUPS_DIR="${DESKTOP_ELEMENTS_DIR}/appgroups"216217desktop_element_available_for_arch() {218local desktop_element_path="${1}"219local targeted_arch="${2}"220221local arch_limitation_file="${1}/only_for"222223echo "Checking if ${desktop_element_path} is available for ${targeted_arch} in ${arch_limitation_file}" >> "${DEST}"/${LOG_SUBPATH}/output.log224if [[ -f "${arch_limitation_file}" ]]; then225grep -- "${targeted_arch}" "${arch_limitation_file}" > /dev/null226return $?227else228return 0229fi230}231232desktop_element_supported() {233234local desktop_element_path="${1}"235236local support_level_filepath="${desktop_element_path}/support"237if [[ -f "${support_level_filepath}" ]]; then238local support_level="$(cat "${support_level_filepath}")"239if [[ "${support_level}" != "supported" && "${EXPERT}" != "yes" ]]; then240return 65241fi242243desktop_element_available_for_arch "${desktop_element_path}" "${ARCH}"244if [[ $? -ne 0 ]]; then245return 66246fi247else248return 64249fi250251return 0252253}254255if [[ $BUILD_DESKTOP == "yes" && -z $DESKTOP_ENVIRONMENT ]]; then256257desktop_environments_prepare_menu() {258for desktop_env_dir in "${DESKTOP_CONFIGS_DIR}/"*; do259local desktop_env_name=$(basename ${desktop_env_dir})260local expert_infos=""261if [[ $BOARDFAMILY == "cix" && $desktop_env_name == xfce ]]; then262:263else264[[ "${EXPERT}" == "yes" ]] && expert_infos="[$(cat "${desktop_env_dir}/support" 2> /dev/null)]"265desktop_element_supported "${desktop_env_dir}" "${ARCH}" && options+=("${desktop_env_name}" "${desktop_env_name^} desktop environment ${expert_infos}")266fi267done268}269270options=()271desktop_environments_prepare_menu272273if [[ "${options[0]}" == "" ]]; then274exit_with_error "No desktop environment seems to be available for your board ${BOARD} (ARCH : ${ARCH} - EXPERT : ${EXPERT})"275fi276277DESKTOP_ENVIRONMENT=$(show_menu "Choose a desktop environment" "$backtitle" "Select the default desktop environment to bundle with this image" "${options[@]}")278279unset options280281if [[ -z "${DESKTOP_ENVIRONMENT}" ]]; then282exit_with_error "No desktop environment selected..."283fi284285fi286287if [[ $BUILD_DESKTOP == "yes" ]]; then288# Expected environment variables :289# - options290# - ARCH291292desktop_environment_check_if_valid() {293294local error_msg=""295desktop_element_supported "${DESKTOP_ENVIRONMENT_DIRPATH}" "${ARCH}"296local retval=$?297298if [[ ${retval} == 0 ]]; then299return300elif [[ ${retval} == 64 ]]; then301error_msg+="Either the desktop environment ${DESKTOP_ENVIRONMENT} does not exist "302error_msg+="or the file ${DESKTOP_ENVIRONMENT_DIRPATH}/support is missing"303elif [[ ${retval} == 65 ]]; then304error_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})"305elif [[ ${retval} == 66 ]]; then306error_msg+="The desktop environment \"${DESKTOP_ENVIRONMENT}\" has no packages for your targeted board architecture (BOARD=${BOARD} ARCH=${ARCH}). "307error_msg+="The supported boards architectures are : "308error_msg+="$(cat "${DESKTOP_ENVIRONMENT_DIRPATH}/only_for")"309fi310311# supress error when cache is rebuilding312[[ -n "$ROOT_FS_CREATE_ONLY" ]] && exit 0313314exit_with_error "${error_msg}"315}316317DESKTOP_ENVIRONMENT_DIRPATH="${DESKTOP_CONFIGS_DIR}/${DESKTOP_ENVIRONMENT}"318319desktop_environment_check_if_valid320fi321322if [[ $BUILD_DESKTOP == "yes" && -z $DESKTOP_ENVIRONMENT_CONFIG_NAME ]]; then323# FIXME Check for empty folders, just in case the current maintainer324# messed up325# Note, we could also ignore it and don't show anything in the previous326# menu, but that hides information and make debugging harder, which I327# don't like. Adding desktop environments as a maintainer is not a328# trivial nor common task.329330options=()331for configuration in "${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_CONFIG_PREFIX}"*; do332config_filename=$(basename ${configuration})333config_name=${config_filename#"${DESKTOP_CONFIG_PREFIX}"}334options+=("${config_filename}" "${config_name} configuration")335done336337DESKTOP_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[@]}")338unset options339340if [[ -z $DESKTOP_ENVIRONMENT_CONFIG_NAME ]]; then341exit_with_error "No desktop configuration selected... Do you really want a desktop environment ?"342fi343fi344345if [[ $BUILD_DESKTOP == "yes" ]]; then346DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH="${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}"347DESKTOP_ENVIRONMENT_PACKAGE_LIST_FILEPATH="${DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH}/packages"348fi349350# "-z ${VAR+x}" allows to check for unset variable351# Technically, someone might want to build a desktop with no additional352# appgroups.353if [[ $BUILD_DESKTOP == "yes" && -z ${DESKTOP_APPGROUPS_SELECTED+x} && ${RELEASE} != "raspi" ]]; then354355options=()356for appgroup_path in "${DESKTOP_APPGROUPS_DIR}/"*; do357appgroup="$(basename "${appgroup_path}")"358options+=("${appgroup}" "${appgroup^}" off)359done360361DESKTOP_APPGROUPS_SELECTED=$(\362show_select_menu \363"Choose desktop softwares to add" \364"$backtitle" \365"Select which kind of softwares you'd like to add to your build" \366"${options[@]}")367368DESKTOP_APPGROUPS_SELECTED=${DESKTOP_APPGROUPS_SELECTED//\"/}369370unset options371fi372373#exit_with_error 'Testing'374375# Expected variables376# - aggregated_content377# - potential_paths378# - separator379# Write to variables :380# - aggregated_content381aggregate_content() {382LOG_OUTPUT_FILE="${SRC}/output/${LOG_SUBPATH}/potential-paths.log"383echo -e "Potential paths :" >> "${LOG_OUTPUT_FILE}"384show_checklist_variables potential_paths385for filepath in ${potential_paths}; do386if [[ -f "${filepath}" ]]; then387echo -e "${filepath/"$EXTER"\//} yes" >> "${LOG_OUTPUT_FILE}"388aggregated_content+=$(cat "${filepath}")389aggregated_content+="${separator}"390# else391# echo -e "${filepath/"$EXTER"\//} no\n" >> "${LOG_OUTPUT_FILE}"392fi393394done395echo "" >> "${LOG_OUTPUT_FILE}"396unset LOG_OUTPUT_FILE397}398399# set unique mounting directory400MOUNT_UUID=$(uuidgen)401SDCARD="${SRC}/.tmp/rootfs-${MOUNT_UUID}"402MOUNT="${SRC}/.tmp/mount-${MOUNT_UUID}"403DESTIMG="${SRC}/.tmp/image-${MOUNT_UUID}"404405# dropbear needs to be configured differently406[[ $CRYPTROOT_ENABLE == yes && $RELEASE == xenial ]] && exit_with_error "Encrypted rootfs is not supported in Xenial"407[[ $RELEASE == stretch && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Debian Stretch images with selected kernel is not supported"408[[ $RELEASE == bionic && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Ubuntu Bionic images with selected kernel is not supported"409[[ $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"410411[[ -n $ATFSOURCE && -z $ATF_USE_GCC ]] && exit_with_error "Error in configuration: ATF_USE_GCC is unset"412[[ -z $UBOOT_USE_GCC ]] && exit_with_error "Error in configuration: UBOOT_USE_GCC is unset"413[[ -z $KERNEL_USE_GCC ]] && exit_with_error "Error in configuration: KERNEL_USE_GCC is unset"414415BOOTCONFIG_VAR_NAME=BOOTCONFIG_${BRANCH^^}416[[ -n ${!BOOTCONFIG_VAR_NAME} ]] && BOOTCONFIG=${!BOOTCONFIG_VAR_NAME}417[[ -z $LINUXCONFIG ]] && LINUXCONFIG="linux-${LINUXFAMILY}-${BRANCH}"418[[ -z $BOOTPATCHDIR ]] && BOOTPATCHDIR="u-boot-$LINUXFAMILY"419[[ -z $ATFPATCHDIR ]] && ATFPATCHDIR="atf-$LINUXFAMILY"420[[ -z $KERNELPATCHDIR ]] && KERNELPATCHDIR="$LINUXFAMILY-$BRANCH"421422if [[ "$RELEASE" =~ ^(xenial|bionic|focal|hirsute|impish|jammy|noble)$ ]]; then423DISTRIBUTION="Ubuntu"424elif [[ "$RELEASE" == raspi ]]; then425DISTRIBUTION="Bullseye"426else427DISTRIBUTION="Debian"428fi429430CLI_CONFIG_PATH="${EXTER}/config/cli/${RELEASE}"431DEBOOTSTRAP_CONFIG_PATH="${CLI_CONFIG_PATH}/debootstrap"432433if [[ $? != 0 ]]; then434exit_with_error "The desktop environment ${DESKTOP_ENVIRONMENT} is not available for your architecture ${ARCH}"435fi436437AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS="438${EXTER}/config439${EXTER}/config/optional/_any_board/_config440${EXTER}/config/optional/architectures/${ARCH}/_config441${EXTER}/config/optional/families/${LINUXFAMILY}/_config442${EXTER}/config/optional/boards/${BOARD}/_config443${USERPATCHES_PATH}444"445446DEBOOTSTRAP_SEARCH_RELATIVE_DIRS="447cli/_all_distributions/debootstrap448cli/${RELEASE}/debootstrap449"450451CLI_SEARCH_RELATIVE_DIRS="452cli/_all_distributions/main453cli/${RELEASE}/main454"455456PACKAGES_SEARCH_ROOT_ABSOLUTE_DIRS="457${EXTER}/packages458${EXTER}/config/optional/_any_board/_packages459${EXTER}/config/optional/architectures/${ARCH}/_packages460${EXTER}/config/optional/families/${LINUXFAMILY}/_packages461${EXTER}/config/optional/boards/${BOARD}/_packages462"463464DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS="465desktop/_all_distributions/environments/_all_environments466desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}467desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}468desktop/${RELEASE}/environments/_all_environments469desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}470desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}471"472473DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS="474desktop/_all_distributions/appgroups475desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}/appgroups476desktop/${RELEASE}/appgroups477desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/appgroups478"479480get_all_potential_paths() {481local root_dirs="${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}"482local rel_dirs="${1}"483local sub_dirs="${2}"484local looked_up_subpath="${3}"485for root_dir in ${root_dirs}; do486for rel_dir in ${rel_dirs}; do487for sub_dir in ${sub_dirs}; do488potential_paths+="${root_dir}/${rel_dir}/${sub_dir}/${looked_up_subpath} "489done490done491done492# for ppath in ${potential_paths}; do493# echo "Checking for ${ppath}"494# if [[ -f "${ppath}" ]]; then495# echo "OK !|"496# else497# echo "Nope|"498# fi499# done500}501502# Environment variables expected :503# - aggregated_content504# Arguments :505# 1. File to look up in each directory506# 2. The separator to add between each concatenated file507# 3. Relative directories paths added to ${3}508# 4. Relative directories paths added to ${4}509#510# The function will basically generate a list of potential paths by511# generating all the potential paths combinations leading to the512# looked up file513# ${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}/${3}/${4}/${1}514# Then it will concatenate the content of all the available files515# into ${aggregated_content}516#517# TODO :518# ${4} could be removed by just adding the appropriate paths to ${3}519# dynamically for each case520# (debootstrap, cli, desktop environments, desktop appgroups, ...)521522aggregate_all_root_rel_sub() {523local separator="${2}"524525local potential_paths=""526get_all_potential_paths "${3}" "${4}" "${1}"527528aggregate_content529}530531aggregate_all_debootstrap() {532local sub_dirs_to_check=". "533if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then534sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"535fi536aggregate_all_root_rel_sub "${1}" "${2}" "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"537}538539aggregate_all_cli() {540local sub_dirs_to_check=". "541if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then542sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"543fi544aggregate_all_root_rel_sub "${1}" "${2}" "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"545}546547aggregate_all_desktop() {548aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "."549aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}"550}551552one_line() {553local aggregate_func_name="${1}"554local aggregated_content=""555shift 1556$aggregate_func_name "${@}"557cleanup_list aggregated_content558}559560DEBOOTSTRAP_LIST="$(one_line aggregate_all_debootstrap "packages" " ")"561DEBOOTSTRAP_COMPONENTS="$(one_line aggregate_all_debootstrap "components" " ")"562DEBOOTSTRAP_COMPONENTS="${DEBOOTSTRAP_COMPONENTS// /,}"563PACKAGE_LIST="$(one_line aggregate_all_cli "packages" " ")"564PACKAGE_LIST_ADDITIONAL="$(one_line aggregate_all_cli "packages.additional" " ")"565566LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/debootstrap-list.log"567show_checklist_variables "DEBOOTSTRAP_LIST DEBOOTSTRAP_COMPONENTS PACKAGE_LIST PACKAGE_LIST_ADDITIONAL PACKAGE_LIST_UNINSTALL"568569# Dependent desktop packages570# Myy : Sources packages from file here571572# Myy : FIXME Rename aggregate_all to aggregate_all_desktop573if [[ $BUILD_DESKTOP == "yes" ]]; then574PACKAGE_LIST_DESKTOP+="$(one_line aggregate_all_desktop "packages" " ")"575echo -e "\nGroups selected ${DESKTOP_APPGROUPS_SELECTED} -> PACKAGES :" >> "${LOG_OUTPUT_FILE}"576show_checklist_variables PACKAGE_LIST_DESKTOP577fi578unset LOG_OUTPUT_FILE579580DEBIAN_MIRROR='deb.debian.org/debian'581DEBIAN_SECURTY='security.debian.org/'582UBUNTU_MIRROR='ports.ubuntu.com/'583RASPI_MIRROR='archive.raspberrypi.org/debian/'584585if [[ $DOWNLOAD_MIRROR == "china" ]] ; then586587if [[ ${CHINA_DOWNLOAD_MIRROR} == tsinghua ]]; then588DEBIAN_MIRROR='mirrors.tuna.tsinghua.edu.cn/debian'589DEBIAN_SECURTY='mirrors.tuna.tsinghua.edu.cn/debian-security'590UBUNTU_MIRROR='mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/'591fi592593if [[ ${CHINA_DOWNLOAD_MIRROR} == huawei ]]; then594DEBIAN_MIRROR='repo.huaweicloud.com/debian'595DEBIAN_SECURTY='repo.huaweicloud.com/debian-security'596UBUNTU_MIRROR='repo.huaweicloud.com/ubuntu-ports/'597fi598599RASPI_MIRROR='mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/'600601fi602603if [[ $DOWNLOAD_MIRROR == "bfsu" ]] ; then604DEBIAN_MIRROR='mirrors.bfsu.edu.cn/debian'605DEBIAN_SECURTY='mirrors.bfsu.edu.cn/debian-security'606UBUNTU_MIRROR='mirrors.bfsu.edu.cn/ubuntu-ports/'607fi608609if [[ "${ARCH}" == "amd64" ]]; then610UBUNTU_MIRROR='archive.ubuntu.com/ubuntu' # ports are only for non-amd64, of course.611612if [[ -n ${CUSTOM_UBUNTU_MIRROR} ]]; then # ubuntu redirector doesn't work well on amd64613UBUNTU_MIRROR="${CUSTOM_UBUNTU_MIRROR}"614fi615fi616617# don't use mirrors that throws garbage on 404618if [[ -z ${ARMBIAN_MIRROR} ]]; then619while true; do620621ARMBIAN_MIRROR=$(wget -SO- -T 1 -t 1 https://redirect.armbian.com 2>&1 | egrep -i "Location" | awk '{print $2}' | head -1)622[[ ${ARMBIAN_MIRROR} != *armbian.hosthatch* ]] && break623624done625fi626627# For (late) user override.628# Notice: it is too late to define hook functions or add extensions in lib.config, since the extension initialization already ran by now.629# 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.630if [[ -f $USERPATCHES_PATH/lib.config ]]; then631display_alert "Using user configuration override" "$USERPATCHES_PATH/lib.config" "info"632source "$USERPATCHES_PATH"/lib.config633fi634635call_extension_method "user_config" << 'USER_CONFIG'636*Invoke function with user override*637Allows for overriding configuration values set anywhere else.638It is called after sourcing the `lib.config` file if it exists,639but before assembling any package lists.640USER_CONFIG641642call_extension_method "extension_prepare_config" << 'EXTENSION_PREPARE_CONFIG'643*allow extensions to prepare their own config, after user config is done*644Implementors should preserve variable values pre-set, but can default values an/or validate them.645This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user.646EXTENSION_PREPARE_CONFIG647648# apt-cacher-ng mirror configurarion649if [[ $DISTRIBUTION == Ubuntu ]]; then650APT_MIRROR=$UBUNTU_MIRROR651else652APT_MIRROR=$DEBIAN_MIRROR653fi654655[[ -n $APT_PROXY_ADDR ]] && display_alert "Using custom apt-cacher-ng address" "$APT_PROXY_ADDR" "info"656657# Build final package list after possible override658PACKAGE_LIST="$PACKAGE_LIST $PACKAGE_LIST_RELEASE $PACKAGE_LIST_ADDITIONAL"659PACKAGE_MAIN_LIST="$(cleanup_list PACKAGE_LIST)"660661[[ $BUILD_DESKTOP == yes ]] && PACKAGE_LIST="$PACKAGE_LIST $PACKAGE_LIST_DESKTOP"662PACKAGE_LIST="$(cleanup_list PACKAGE_LIST)"663664# remove any packages defined in PACKAGE_LIST_RM in lib.config665aggregated_content="${PACKAGE_LIST_RM} "666aggregate_all_cli "packages.remove" " "667aggregate_all_desktop "packages.remove" " "668PACKAGE_LIST_RM="$(cleanup_list aggregated_content)"669unset aggregated_content670671aggregated_content=""672aggregate_all_cli "packages.uninstall" " "673aggregate_all_desktop "packages.uninstall" " "674PACKAGE_LIST_UNINSTALL="$(cleanup_list aggregated_content)"675unset aggregated_content676677678if [[ -n $PACKAGE_LIST_RM ]]; then679display_alert "Package remove list ${PACKAGE_LIST_RM}"680# Turns out that \b can be tricked by dashes.681# So if you remove mesa-utils but still want to install "mesa-utils-extra"682# a "\b(mesa-utils)\b" filter will convert "mesa-utils-extra" to "-extra".683# \W is not tricked by this but consumes the surrounding spaces, so we684# replace the occurence by one space, to avoid sticking the next word to685# the previous one after consuming the spaces.686DEBOOTSTRAP_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${DEBOOTSTRAP_LIST} ")687PACKAGE_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_LIST} ")688PACKAGE_MAIN_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_MAIN_LIST} ")689if [[ $BUILD_DESKTOP == "yes" ]]; then690PACKAGE_LIST_DESKTOP=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_LIST_DESKTOP} ")691# Removing double spaces... AGAIN, since we might have used a sed on them692# Do not quote the variables. This would defeat the trick.693PACKAGE_LIST_DESKTOP="$(echo ${PACKAGE_LIST_DESKTOP})"694fi695696# Removing double spaces... AGAIN, since we might have used a sed on them697# Do not quote the variables. This would defeat the trick.698DEBOOTSTRAP_LIST="$(echo ${DEBOOTSTRAP_LIST})"699PACKAGE_LIST="$(echo ${PACKAGE_LIST})"700PACKAGE_MAIN_LIST="$(echo ${PACKAGE_MAIN_LIST})"701fi702703704LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/debootstrap-list.log"705echo -e "\nVariables after manual configuration" >>$LOG_OUTPUT_FILE706show_checklist_variables "DEBOOTSTRAP_COMPONENTS DEBOOTSTRAP_LIST PACKAGE_LIST PACKAGE_MAIN_LIST"707unset LOG_OUTPUT_FILE708709# Give the option to configure DNS server used in the chroot during the build process710[[ -z $NAMESERVER ]] && NAMESERVER="1.0.0.1" # default is cloudflare alternate711712call_extension_method "post_aggregate_packages" "user_config_post_aggregate_packages" << 'POST_AGGREGATE_PACKAGES'713*For final user override, using a function, after all aggregations are done*714Called after aggregating all package lists, before the end of `compilation.sh`.715Packages will still be installed after this is called, so it is the last chance716to confirm or change any packages.717POST_AGGREGATE_PACKAGES718719# debug720cat <<-EOF >> "${DEST}"/${LOG_SUBPATH}/output.log721722## BUILD SCRIPT ENVIRONMENT723724Repository: $REPOSITORY_URL725Version: $REPOSITORY_COMMIT726727Host OS: $HOSTRELEASE728Host arch: $(dpkg --print-architecture)729Host system: $(uname -a)730Virtualization type: $(systemd-detect-virt)731732## Build script directories733Build directory is located on:734$(findmnt -o TARGET,SOURCE,FSTYPE,AVAIL -T "${SRC}")735736Build directory permissions:737$(getfacl -p "${SRC}")738739Temp directory permissions:740$(getfacl -p "${SRC}"/.tmp 2> /dev/null)741742## BUILD CONFIGURATION743744Build target:745Board: $BOARD746Branch: $BRANCH747Minimal: $BUILD_MINIMAL748Desktop: $BUILD_DESKTOP749Desktop Environment: $DESKTOP_ENVIRONMENT750Software groups: $DESKTOP_APPGROUPS_SELECTED751752Kernel configuration:753Repository: $KERNELSOURCE754Branch: $KERNELBRANCH755Config file: $LINUXCONFIG756757U-boot configuration:758Repository: $BOOTSOURCE759Branch: $BOOTBRANCH760Config file: $BOOTCONFIG761762Partitioning configuration: $IMAGE_PARTITION_TABLE offset: $OFFSET763Boot partition type: ${BOOTFS_TYPE:-(none)} ${BOOTSIZE:+"(${BOOTSIZE} MB)"}764Root partition type: $ROOTFS_TYPE ${FIXED_IMAGE_SIZE:+"(${FIXED_IMAGE_SIZE} MB)"}765766CPU configuration: $CPUMIN - $CPUMAX with $GOVERNOR767EOF768769770