Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/scripts/configuration.sh
Views: 3960
#!/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=""261[[ "${EXPERT}" == "yes" ]] && expert_infos="[$(cat "${desktop_env_dir}/support" 2> /dev/null)]"262desktop_element_supported "${desktop_env_dir}" "${ARCH}" && options+=("${desktop_env_name}" "${desktop_env_name^} desktop environment ${expert_infos}")263done264}265266options=()267desktop_environments_prepare_menu268269if [[ "${options[0]}" == "" ]]; then270exit_with_error "No desktop environment seems to be available for your board ${BOARD} (ARCH : ${ARCH} - EXPERT : ${EXPERT})"271fi272273DESKTOP_ENVIRONMENT=$(show_menu "Choose a desktop environment" "$backtitle" "Select the default desktop environment to bundle with this image" "${options[@]}")274275unset options276277if [[ -z "${DESKTOP_ENVIRONMENT}" ]]; then278exit_with_error "No desktop environment selected..."279fi280281fi282283if [[ $BUILD_DESKTOP == "yes" ]]; then284# Expected environment variables :285# - options286# - ARCH287288desktop_environment_check_if_valid() {289290local error_msg=""291desktop_element_supported "${DESKTOP_ENVIRONMENT_DIRPATH}" "${ARCH}"292local retval=$?293294if [[ ${retval} == 0 ]]; then295return296elif [[ ${retval} == 64 ]]; then297error_msg+="Either the desktop environment ${DESKTOP_ENVIRONMENT} does not exist "298error_msg+="or the file ${DESKTOP_ENVIRONMENT_DIRPATH}/support is missing"299elif [[ ${retval} == 65 ]]; then300error_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})"301elif [[ ${retval} == 66 ]]; then302error_msg+="The desktop environment \"${DESKTOP_ENVIRONMENT}\" has no packages for your targeted board architecture (BOARD=${BOARD} ARCH=${ARCH}). "303error_msg+="The supported boards architectures are : "304error_msg+="$(cat "${DESKTOP_ENVIRONMENT_DIRPATH}/only_for")"305fi306307# supress error when cache is rebuilding308[[ -n "$ROOT_FS_CREATE_ONLY" ]] && exit 0309310exit_with_error "${error_msg}"311}312313DESKTOP_ENVIRONMENT_DIRPATH="${DESKTOP_CONFIGS_DIR}/${DESKTOP_ENVIRONMENT}"314315desktop_environment_check_if_valid316fi317318if [[ $BUILD_DESKTOP == "yes" && -z $DESKTOP_ENVIRONMENT_CONFIG_NAME ]]; then319# FIXME Check for empty folders, just in case the current maintainer320# messed up321# Note, we could also ignore it and don't show anything in the previous322# menu, but that hides information and make debugging harder, which I323# don't like. Adding desktop environments as a maintainer is not a324# trivial nor common task.325326options=()327for configuration in "${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_CONFIG_PREFIX}"*; do328config_filename=$(basename ${configuration})329config_name=${config_filename#"${DESKTOP_CONFIG_PREFIX}"}330options+=("${config_filename}" "${config_name} configuration")331done332333DESKTOP_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[@]}")334unset options335336if [[ -z $DESKTOP_ENVIRONMENT_CONFIG_NAME ]]; then337exit_with_error "No desktop configuration selected... Do you really want a desktop environment ?"338fi339fi340341if [[ $BUILD_DESKTOP == "yes" ]]; then342DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH="${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}"343DESKTOP_ENVIRONMENT_PACKAGE_LIST_FILEPATH="${DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH}/packages"344fi345346# "-z ${VAR+x}" allows to check for unset variable347# Technically, someone might want to build a desktop with no additional348# appgroups.349if [[ $BUILD_DESKTOP == "yes" && -z ${DESKTOP_APPGROUPS_SELECTED+x} && ${RELEASE} != "raspi" ]]; then350351options=()352for appgroup_path in "${DESKTOP_APPGROUPS_DIR}/"*; do353appgroup="$(basename "${appgroup_path}")"354options+=("${appgroup}" "${appgroup^}" off)355done356357DESKTOP_APPGROUPS_SELECTED=$(\358show_select_menu \359"Choose desktop softwares to add" \360"$backtitle" \361"Select which kind of softwares you'd like to add to your build" \362"${options[@]}")363364DESKTOP_APPGROUPS_SELECTED=${DESKTOP_APPGROUPS_SELECTED//\"/}365366unset options367fi368369#exit_with_error 'Testing'370371# Expected variables372# - aggregated_content373# - potential_paths374# - separator375# Write to variables :376# - aggregated_content377aggregate_content() {378LOG_OUTPUT_FILE="${SRC}/output/${LOG_SUBPATH}/potential-paths.log"379echo -e "Potential paths :" >> "${LOG_OUTPUT_FILE}"380show_checklist_variables potential_paths381for filepath in ${potential_paths}; do382if [[ -f "${filepath}" ]]; then383echo -e "${filepath/"$EXTER"\//} yes" >> "${LOG_OUTPUT_FILE}"384aggregated_content+=$(cat "${filepath}")385aggregated_content+="${separator}"386# else387# echo -e "${filepath/"$EXTER"\//} no\n" >> "${LOG_OUTPUT_FILE}"388fi389390done391echo "" >> "${LOG_OUTPUT_FILE}"392unset LOG_OUTPUT_FILE393}394395# set unique mounting directory396MOUNT_UUID=$(uuidgen)397SDCARD="${SRC}/.tmp/rootfs-${MOUNT_UUID}"398MOUNT="${SRC}/.tmp/mount-${MOUNT_UUID}"399DESTIMG="${SRC}/.tmp/image-${MOUNT_UUID}"400401# dropbear needs to be configured differently402[[ $CRYPTROOT_ENABLE == yes && $RELEASE == xenial ]] && exit_with_error "Encrypted rootfs is not supported in Xenial"403[[ $RELEASE == stretch && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Debian Stretch images with selected kernel is not supported"404[[ $RELEASE == bionic && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Ubuntu Bionic images with selected kernel is not supported"405[[ $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"406407[[ -n $ATFSOURCE && -z $ATF_USE_GCC ]] && exit_with_error "Error in configuration: ATF_USE_GCC is unset"408[[ -z $UBOOT_USE_GCC ]] && exit_with_error "Error in configuration: UBOOT_USE_GCC is unset"409[[ -z $KERNEL_USE_GCC ]] && exit_with_error "Error in configuration: KERNEL_USE_GCC is unset"410411BOOTCONFIG_VAR_NAME=BOOTCONFIG_${BRANCH^^}412[[ -n ${!BOOTCONFIG_VAR_NAME} ]] && BOOTCONFIG=${!BOOTCONFIG_VAR_NAME}413[[ -z $LINUXCONFIG ]] && LINUXCONFIG="linux-${LINUXFAMILY}-${BRANCH}"414[[ -z $BOOTPATCHDIR ]] && BOOTPATCHDIR="u-boot-$LINUXFAMILY"415[[ -z $ATFPATCHDIR ]] && ATFPATCHDIR="atf-$LINUXFAMILY"416[[ -z $KERNELPATCHDIR ]] && KERNELPATCHDIR="$LINUXFAMILY-$BRANCH"417418if [[ "$RELEASE" =~ ^(xenial|bionic|focal|hirsute|impish|jammy|noble)$ ]]; then419DISTRIBUTION="Ubuntu"420elif [[ "$RELEASE" == raspi ]]; then421DISTRIBUTION="Bullseye"422else423DISTRIBUTION="Debian"424fi425426CLI_CONFIG_PATH="${EXTER}/config/cli/${RELEASE}"427DEBOOTSTRAP_CONFIG_PATH="${CLI_CONFIG_PATH}/debootstrap"428429if [[ $? != 0 ]]; then430exit_with_error "The desktop environment ${DESKTOP_ENVIRONMENT} is not available for your architecture ${ARCH}"431fi432433AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS="434${EXTER}/config435${EXTER}/config/optional/_any_board/_config436${EXTER}/config/optional/architectures/${ARCH}/_config437${EXTER}/config/optional/families/${LINUXFAMILY}/_config438${EXTER}/config/optional/boards/${BOARD}/_config439${USERPATCHES_PATH}440"441442DEBOOTSTRAP_SEARCH_RELATIVE_DIRS="443cli/_all_distributions/debootstrap444cli/${RELEASE}/debootstrap445"446447CLI_SEARCH_RELATIVE_DIRS="448cli/_all_distributions/main449cli/${RELEASE}/main450"451452PACKAGES_SEARCH_ROOT_ABSOLUTE_DIRS="453${EXTER}/packages454${EXTER}/config/optional/_any_board/_packages455${EXTER}/config/optional/architectures/${ARCH}/_packages456${EXTER}/config/optional/families/${LINUXFAMILY}/_packages457${EXTER}/config/optional/boards/${BOARD}/_packages458"459460DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS="461desktop/_all_distributions/environments/_all_environments462desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}463desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}464desktop/${RELEASE}/environments/_all_environments465desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}466desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}467"468469DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS="470desktop/_all_distributions/appgroups471desktop/_all_distributions/environments/${DESKTOP_ENVIRONMENT}/appgroups472desktop/${RELEASE}/appgroups473desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/appgroups474"475476get_all_potential_paths() {477local root_dirs="${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}"478local rel_dirs="${1}"479local sub_dirs="${2}"480local looked_up_subpath="${3}"481for root_dir in ${root_dirs}; do482for rel_dir in ${rel_dirs}; do483for sub_dir in ${sub_dirs}; do484potential_paths+="${root_dir}/${rel_dir}/${sub_dir}/${looked_up_subpath} "485done486done487done488# for ppath in ${potential_paths}; do489# echo "Checking for ${ppath}"490# if [[ -f "${ppath}" ]]; then491# echo "OK !|"492# else493# echo "Nope|"494# fi495# done496}497498# Environment variables expected :499# - aggregated_content500# Arguments :501# 1. File to look up in each directory502# 2. The separator to add between each concatenated file503# 3. Relative directories paths added to ${3}504# 4. Relative directories paths added to ${4}505#506# The function will basically generate a list of potential paths by507# generating all the potential paths combinations leading to the508# looked up file509# ${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}/${3}/${4}/${1}510# Then it will concatenate the content of all the available files511# into ${aggregated_content}512#513# TODO :514# ${4} could be removed by just adding the appropriate paths to ${3}515# dynamically for each case516# (debootstrap, cli, desktop environments, desktop appgroups, ...)517518aggregate_all_root_rel_sub() {519local separator="${2}"520521local potential_paths=""522get_all_potential_paths "${3}" "${4}" "${1}"523524aggregate_content525}526527aggregate_all_debootstrap() {528local sub_dirs_to_check=". "529if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then530sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"531fi532aggregate_all_root_rel_sub "${1}" "${2}" "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"533}534535aggregate_all_cli() {536local sub_dirs_to_check=". "537if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then538sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"539fi540aggregate_all_root_rel_sub "${1}" "${2}" "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"541}542543aggregate_all_desktop() {544aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "."545aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}"546}547548one_line() {549local aggregate_func_name="${1}"550local aggregated_content=""551shift 1552$aggregate_func_name "${@}"553cleanup_list aggregated_content554}555556DEBOOTSTRAP_LIST="$(one_line aggregate_all_debootstrap "packages" " ")"557DEBOOTSTRAP_COMPONENTS="$(one_line aggregate_all_debootstrap "components" " ")"558DEBOOTSTRAP_COMPONENTS="${DEBOOTSTRAP_COMPONENTS// /,}"559PACKAGE_LIST="$(one_line aggregate_all_cli "packages" " ")"560PACKAGE_LIST_ADDITIONAL="$(one_line aggregate_all_cli "packages.additional" " ")"561562LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/debootstrap-list.log"563show_checklist_variables "DEBOOTSTRAP_LIST DEBOOTSTRAP_COMPONENTS PACKAGE_LIST PACKAGE_LIST_ADDITIONAL PACKAGE_LIST_UNINSTALL"564565# Dependent desktop packages566# Myy : Sources packages from file here567568# Myy : FIXME Rename aggregate_all to aggregate_all_desktop569if [[ $BUILD_DESKTOP == "yes" ]]; then570PACKAGE_LIST_DESKTOP+="$(one_line aggregate_all_desktop "packages" " ")"571echo -e "\nGroups selected ${DESKTOP_APPGROUPS_SELECTED} -> PACKAGES :" >> "${LOG_OUTPUT_FILE}"572show_checklist_variables PACKAGE_LIST_DESKTOP573fi574unset LOG_OUTPUT_FILE575576DEBIAN_MIRROR='deb.debian.org/debian'577DEBIAN_SECURTY='security.debian.org/'578UBUNTU_MIRROR='ports.ubuntu.com/'579RASPI_MIRROR='archive.raspberrypi.org/debian/'580581if [[ $DOWNLOAD_MIRROR == "china" ]] ; then582583if [[ ${CHINA_DOWNLOAD_MIRROR} == tsinghua ]]; then584DEBIAN_MIRROR='mirrors.tuna.tsinghua.edu.cn/debian'585DEBIAN_SECURTY='mirrors.tuna.tsinghua.edu.cn/debian-security'586UBUNTU_MIRROR='mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/'587fi588589if [[ ${CHINA_DOWNLOAD_MIRROR} == huawei ]]; then590DEBIAN_MIRROR='repo.huaweicloud.com/debian'591DEBIAN_SECURTY='repo.huaweicloud.com/debian-security'592UBUNTU_MIRROR='repo.huaweicloud.com/ubuntu-ports/'593fi594595RASPI_MIRROR='mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/'596597fi598599if [[ $DOWNLOAD_MIRROR == "bfsu" ]] ; then600DEBIAN_MIRROR='mirrors.bfsu.edu.cn/debian'601DEBIAN_SECURTY='mirrors.bfsu.edu.cn/debian-security'602UBUNTU_MIRROR='mirrors.bfsu.edu.cn/ubuntu-ports/'603fi604605if [[ "${ARCH}" == "amd64" ]]; then606UBUNTU_MIRROR='archive.ubuntu.com/ubuntu' # ports are only for non-amd64, of course.607608if [[ -n ${CUSTOM_UBUNTU_MIRROR} ]]; then # ubuntu redirector doesn't work well on amd64609UBUNTU_MIRROR="${CUSTOM_UBUNTU_MIRROR}"610fi611fi612613# don't use mirrors that throws garbage on 404614if [[ -z ${ARMBIAN_MIRROR} ]]; then615while true; do616617ARMBIAN_MIRROR=$(wget -SO- -T 1 -t 1 https://redirect.armbian.com 2>&1 | egrep -i "Location" | awk '{print $2}' | head -1)618[[ ${ARMBIAN_MIRROR} != *armbian.hosthatch* ]] && break619620done621fi622623# For (late) user override.624# Notice: it is too late to define hook functions or add extensions in lib.config, since the extension initialization already ran by now.625# 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.626if [[ -f $USERPATCHES_PATH/lib.config ]]; then627display_alert "Using user configuration override" "$USERPATCHES_PATH/lib.config" "info"628source "$USERPATCHES_PATH"/lib.config629fi630631call_extension_method "user_config" << 'USER_CONFIG'632*Invoke function with user override*633Allows for overriding configuration values set anywhere else.634It is called after sourcing the `lib.config` file if it exists,635but before assembling any package lists.636USER_CONFIG637638call_extension_method "extension_prepare_config" << 'EXTENSION_PREPARE_CONFIG'639*allow extensions to prepare their own config, after user config is done*640Implementors should preserve variable values pre-set, but can default values an/or validate them.641This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user.642EXTENSION_PREPARE_CONFIG643644# apt-cacher-ng mirror configurarion645if [[ $DISTRIBUTION == Ubuntu ]]; then646APT_MIRROR=$UBUNTU_MIRROR647else648APT_MIRROR=$DEBIAN_MIRROR649fi650651[[ -n $APT_PROXY_ADDR ]] && display_alert "Using custom apt-cacher-ng address" "$APT_PROXY_ADDR" "info"652653# Build final package list after possible override654PACKAGE_LIST="$PACKAGE_LIST $PACKAGE_LIST_RELEASE $PACKAGE_LIST_ADDITIONAL"655PACKAGE_MAIN_LIST="$(cleanup_list PACKAGE_LIST)"656657[[ $BUILD_DESKTOP == yes ]] && PACKAGE_LIST="$PACKAGE_LIST $PACKAGE_LIST_DESKTOP"658PACKAGE_LIST="$(cleanup_list PACKAGE_LIST)"659660# remove any packages defined in PACKAGE_LIST_RM in lib.config661aggregated_content="${PACKAGE_LIST_RM} "662aggregate_all_cli "packages.remove" " "663aggregate_all_desktop "packages.remove" " "664PACKAGE_LIST_RM="$(cleanup_list aggregated_content)"665unset aggregated_content666667aggregated_content=""668aggregate_all_cli "packages.uninstall" " "669aggregate_all_desktop "packages.uninstall" " "670PACKAGE_LIST_UNINSTALL="$(cleanup_list aggregated_content)"671unset aggregated_content672673674if [[ -n $PACKAGE_LIST_RM ]]; then675display_alert "Package remove list ${PACKAGE_LIST_RM}"676# Turns out that \b can be tricked by dashes.677# So if you remove mesa-utils but still want to install "mesa-utils-extra"678# a "\b(mesa-utils)\b" filter will convert "mesa-utils-extra" to "-extra".679# \W is not tricked by this but consumes the surrounding spaces, so we680# replace the occurence by one space, to avoid sticking the next word to681# the previous one after consuming the spaces.682DEBOOTSTRAP_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${DEBOOTSTRAP_LIST} ")683PACKAGE_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_LIST} ")684PACKAGE_MAIN_LIST=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_MAIN_LIST} ")685if [[ $BUILD_DESKTOP == "yes" ]]; then686PACKAGE_LIST_DESKTOP=$(sed -r "s/\W($(tr ' ' '|' <<< ${PACKAGE_LIST_RM}))\W/ /g" <<< " ${PACKAGE_LIST_DESKTOP} ")687# Removing double spaces... AGAIN, since we might have used a sed on them688# Do not quote the variables. This would defeat the trick.689PACKAGE_LIST_DESKTOP="$(echo ${PACKAGE_LIST_DESKTOP})"690fi691692# Removing double spaces... AGAIN, since we might have used a sed on them693# Do not quote the variables. This would defeat the trick.694DEBOOTSTRAP_LIST="$(echo ${DEBOOTSTRAP_LIST})"695PACKAGE_LIST="$(echo ${PACKAGE_LIST})"696PACKAGE_MAIN_LIST="$(echo ${PACKAGE_MAIN_LIST})"697fi698699700LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/debootstrap-list.log"701echo -e "\nVariables after manual configuration" >>$LOG_OUTPUT_FILE702show_checklist_variables "DEBOOTSTRAP_COMPONENTS DEBOOTSTRAP_LIST PACKAGE_LIST PACKAGE_MAIN_LIST"703unset LOG_OUTPUT_FILE704705# Give the option to configure DNS server used in the chroot during the build process706[[ -z $NAMESERVER ]] && NAMESERVER="1.0.0.1" # default is cloudflare alternate707708call_extension_method "post_aggregate_packages" "user_config_post_aggregate_packages" << 'POST_AGGREGATE_PACKAGES'709*For final user override, using a function, after all aggregations are done*710Called after aggregating all package lists, before the end of `compilation.sh`.711Packages will still be installed after this is called, so it is the last chance712to confirm or change any packages.713POST_AGGREGATE_PACKAGES714715# debug716cat <<-EOF >> "${DEST}"/${LOG_SUBPATH}/output.log717718## BUILD SCRIPT ENVIRONMENT719720Repository: $REPOSITORY_URL721Version: $REPOSITORY_COMMIT722723Host OS: $HOSTRELEASE724Host arch: $(dpkg --print-architecture)725Host system: $(uname -a)726Virtualization type: $(systemd-detect-virt)727728## Build script directories729Build directory is located on:730$(findmnt -o TARGET,SOURCE,FSTYPE,AVAIL -T "${SRC}")731732Build directory permissions:733$(getfacl -p "${SRC}")734735Temp directory permissions:736$(getfacl -p "${SRC}"/.tmp 2> /dev/null)737738## BUILD CONFIGURATION739740Build target:741Board: $BOARD742Branch: $BRANCH743Minimal: $BUILD_MINIMAL744Desktop: $BUILD_DESKTOP745Desktop Environment: $DESKTOP_ENVIRONMENT746Software groups: $DESKTOP_APPGROUPS_SELECTED747748Kernel configuration:749Repository: $KERNELSOURCE750Branch: $KERNELBRANCH751Config file: $LINUXCONFIG752753U-boot configuration:754Repository: $BOOTSOURCE755Branch: $BOOTBRANCH756Config file: $BOOTCONFIG757758Partitioning configuration: $IMAGE_PARTITION_TABLE offset: $OFFSET759Boot partition type: ${BOOTFS_TYPE:-(none)} ${BOOTSIZE:+"(${BOOTSIZE} MB)"}760Root partition type: $ROOTFS_TYPE ${FIXED_IMAGE_SIZE:+"(${FIXED_IMAGE_SIZE} MB)"}761762CPU configuration: $CPUMIN - $CPUMAX with $GOVERNOR763EOF764765766