From 0c72faf421ce884840aca78bf39621da86ce0b1d Mon Sep 17 00:00:00 2001 From: hzy Date: Sun, 9 Oct 2022 11:52:58 +0800 Subject: [PATCH] Split out functions from `/lib/main.sh` --- lib/functions/configuration/aggregation.sh | 8 + lib/functions/main/config-prepare.sh | 4 + lib/functions/main/default-build.sh | 160 +++++++++++++++++++ lib/main.sh | 173 --------------------- 4 files changed, 172 insertions(+), 173 deletions(-) create mode 100644 lib/functions/main/default-build.sh diff --git a/lib/functions/configuration/aggregation.sh b/lib/functions/configuration/aggregation.sh index 8a5b7a0858..1acd8591f4 100644 --- a/lib/functions/configuration/aggregation.sh +++ b/lib/functions/configuration/aggregation.sh @@ -101,3 +101,11 @@ one_line() { $aggregate_func_name "${@}" cleanup_list aggregated_content } + +cleanup_list() { + local varname="${1}" + local list_to_clean="${!varname}" + list_to_clean="${list_to_clean#"${list_to_clean%%[![:space:]]*}"}" + list_to_clean="${list_to_clean%"${list_to_clean##*[![:space:]]}"}" + echo ${list_to_clean} +} diff --git a/lib/functions/main/config-prepare.sh b/lib/functions/main/config-prepare.sh index e3cdf646ca..50df79eace 100644 --- a/lib/functions/main/config-prepare.sh +++ b/lib/functions/main/config-prepare.sh @@ -12,3 +12,7 @@ function set_distribution_status() { [[ "${DISTRIBUTION_STATUS}" != "supported" ]] && [[ "${EXPERT}" != "yes" ]] && exit_with_error "Armbian ${RELEASE} is unsupported and, therefore, only available to experts (EXPERT=yes)" } + +branch2dir() { + [[ "${1}" == "head" ]] && echo "HEAD" || echo "${1##*:}" +} diff --git a/lib/functions/main/default-build.sh b/lib/functions/main/default-build.sh new file mode 100644 index 0000000000..05f2102141 --- /dev/null +++ b/lib/functions/main/default-build.sh @@ -0,0 +1,160 @@ +do_default() { + + start=$(date +%s) + + # Check and install dependencies, directory structure and settings + # The OFFLINE_WORK variable inside the function + prepare_host + + [[ "${JUST_INIT}" == "yes" ]] && exit 0 + + [[ $CLEAN_LEVEL == *sources* ]] && cleaning "sources" + + # fetch_from_repo + + # ignore updates help on building all images - for internal purposes + if [[ $IGNORE_UPDATES != yes ]]; then + display_alert "Downloading sources" "" "info" + [[ -n $BOOTSOURCE ]] && fetch_from_repo "$BOOTSOURCE" "$BOOTDIR" "$BOOTBRANCH" "yes" + [[ -n $ATFSOURCE ]] && fetch_from_repo "$ATFSOURCE" "$ATFDIR" "$ATFBRANCH" "yes" + + if [[ -n $KERNELSOURCE ]]; then + if $(declare -f var_origin_kernel > /dev/null); then + unset LINUXSOURCEDIR + LINUXSOURCEDIR="linux-mainline/$KERNEL_VERSION_LEVEL" + VAR_SHALLOW_ORIGINAL=var_origin_kernel + waiter_local_git "url=$KERNELSOURCE $KERNELSOURCENAME $KERNELBRANCH dir=$LINUXSOURCEDIR $KERNELSWITCHOBJ" + unset VAR_SHALLOW_ORIGINAL + else + fetch_from_repo "$KERNELSOURCE" "$KERNELDIR" "$KERNELBRANCH" "yes" + fi + fi + + call_extension_method "fetch_sources_tools" <<- 'FETCH_SOURCES_TOOLS' + *fetch host-side sources needed for tools and build* + Run early to fetch_from_repo or otherwise obtain sources for needed tools. + FETCH_SOURCES_TOOLS + + call_extension_method "build_host_tools" <<- 'BUILD_HOST_TOOLS' + *build needed tools for the build, host-side* + After sources are fetched, build host-side tools needed for the build. + BUILD_HOST_TOOLS + + for option in $(tr ',' ' ' <<< "$CLEAN_LEVEL"); do + [[ $option != sources ]] && cleaning "$option" + done + fi + + # Don't build at all if the BOOTCONFIG is 'none'. + [[ "${BOOTCONFIG}" != "none" ]] && { + # Compile u-boot if packed .deb does not exist or use the one from repository + if [[ ! -f "${DEB_STORAGE}"/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb ]]; then + if [[ -n "${ATFSOURCE}" && "${REPOSITORY_INSTALL}" != *u-boot* ]]; then + compile_atf + fi + [[ "${REPOSITORY_INSTALL}" != *u-boot* ]] && compile_uboot + fi + } + + # Compile kernel if packed .deb does not exist or use the one from repository + if [[ ! -f ${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb ]]; then + + KDEB_CHANGELOG_DIST=$RELEASE + [[ -n $KERNELSOURCE ]] && [[ "${REPOSITORY_INSTALL}" != *kernel* ]] && compile_kernel + + fi + + # Compile armbian-config if packed .deb does not exist or use the one from repository + if [[ ! -f ${DEB_STORAGE}/armbian-config_${REVISION}_all.deb ]]; then + + [[ "${REPOSITORY_INSTALL}" != *armbian-config* ]] && compile_armbian-config + + fi + + # Compile armbian-zsh if packed .deb does not exist or use the one from repository + if [[ ! -f ${DEB_STORAGE}/armbian-zsh_${REVISION}_all.deb ]]; then + + [[ "${REPOSITORY_INSTALL}" != *armbian-zsh* ]] && compile_armbian-zsh + + fi + + # Compile plymouth-theme-armbian if packed .deb does not exist or use the one from repository + if [[ ! -f ${DEB_STORAGE}/plymouth-theme-armbian_${REVISION}_all.deb ]]; then + + [[ "${REPOSITORY_INSTALL}" != *plymouth-theme-armbian* ]] && compile_plymouth-theme-armbian + + fi + + # Compile armbian-firmware if packed .deb does not exist or use the one from repository + if ! ls "${DEB_STORAGE}/armbian-firmware_${REVISION}_all.deb" 1> /dev/null 2>&1 || ! ls "${DEB_STORAGE}/armbian-firmware-full_${REVISION}_all.deb" 1> /dev/null 2>&1; then + + if [[ "${REPOSITORY_INSTALL}" != *armbian-firmware* ]]; then + [[ "${INSTALL_ARMBIAN_FIRMWARE:-yes}" == "yes" ]] && { # Build firmware by default. + FULL="" + REPLACE="-full" + compile_firmware + FULL="-full" + REPLACE="" + compile_firmware + } + + fi + + fi + + overlayfs_wrapper "cleanup" + + # create board support package + [[ -n "${RELEASE}" && ! -f "${DEB_STORAGE}/${BSP_CLI_PACKAGE_FULLNAME}.deb" && "${REPOSITORY_INSTALL}" != *armbian-bsp-cli* ]] && create_board_package + + # create desktop package + [[ -n "${RELEASE}" && "${DESKTOP_ENVIRONMENT}" && ! -f "${DEB_STORAGE}/$RELEASE/${CHOSEN_DESKTOP}_${REVISION}_all.deb" && "${REPOSITORY_INSTALL}" != *armbian-desktop* ]] && create_desktop_package + [[ -n "${RELEASE}" && "${DESKTOP_ENVIRONMENT}" && ! -f "${DEB_STORAGE}/${RELEASE}/${BSP_DESKTOP_PACKAGE_FULLNAME}.deb" && "${REPOSITORY_INSTALL}" != *armbian-bsp-desktop* ]] && create_bsp_desktop_package + + # skip image creation if exists. useful for CI when making a lot of images + if [ "$IMAGE_PRESENT" == yes ] && ls "${FINALDEST}/${VENDOR}_${REVISION}_${BOARD^}_${RELEASE}_${BRANCH}_${VER/-$LINUXFAMILY/}${DESKTOP_ENVIRONMENT:+_$DESKTOP_ENVIRONMENT}"*.xz 1> /dev/null 2>&1; then + display_alert "Skipping image creation" "image already made - IMAGE_PRESENT is set" "wrn" + exit + fi + + # build additional packages + [[ $EXTERNAL_NEW == compile ]] && chroot_build_packages + + if [[ $KERNEL_ONLY != yes ]]; then + + [[ $BSP_BUILD != yes ]] && debootstrap_ng + + else + + display_alert "Kernel build done" "@host" "info" + display_alert "Target directory" "${DEB_STORAGE}/" "info" + display_alert "File name" "${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" "info" + + fi + + call_extension_method "run_after_build" << 'RUN_AFTER_BUILD' +*hook for function to run after build, i.e. to change owner of `$SRC`* +Really one of the last hooks ever called. The build has ended. Congratulations. +- *NOTE:* this will run only if there were no errors during build process. +RUN_AFTER_BUILD + + end=$(date +%s) + runtime=$(((end - start) / 60)) + display_alert "Runtime" "$runtime min" "info" + + # Make it easy to repeat build by displaying build options used + [ "$(systemd-detect-virt)" == 'docker' ] && BUILD_CONFIG='docker' + display_alert "Repeat Build Options" "./compile.sh ${BUILD_CONFIG} BOARD=${BOARD} BRANCH=${BRANCH} \ +$([[ -n $RELEASE ]] && echo "RELEASE=${RELEASE} ")\ +$([[ -n $BUILD_MINIMAL ]] && echo "BUILD_MINIMAL=${BUILD_MINIMAL} ")\ +$([[ -n $BUILD_DESKTOP ]] && echo "BUILD_DESKTOP=${BUILD_DESKTOP} ")\ +$([[ -n $KERNEL_ONLY ]] && echo "KERNEL_ONLY=${KERNEL_ONLY} ")\ +$([[ -n $KERNEL_CONFIGURE ]] && echo "KERNEL_CONFIGURE=${KERNEL_CONFIGURE} ")\ +$([[ -n $DESKTOP_ENVIRONMENT ]] && echo "DESKTOP_ENVIRONMENT=${DESKTOP_ENVIRONMENT} ")\ +$([[ -n $DESKTOP_ENVIRONMENT_CONFIG_NAME ]] && echo "DESKTOP_ENVIRONMENT_CONFIG_NAME=${DESKTOP_ENVIRONMENT_CONFIG_NAME} ")\ +$([[ -n $DESKTOP_APPGROUPS_SELECTED ]] && echo "DESKTOP_APPGROUPS_SELECTED=\"${DESKTOP_APPGROUPS_SELECTED}\" ")\ +$([[ -n $DESKTOP_APT_FLAGS_SELECTED ]] && echo "DESKTOP_APT_FLAGS_SELECTED=\"${DESKTOP_APT_FLAGS_SELECTED}\" ")\ +$([[ -n $COMPRESS_OUTPUTIMAGE ]] && echo "COMPRESS_OUTPUTIMAGE=${COMPRESS_OUTPUTIMAGE} ")\ +" "ext" + +} diff --git a/lib/main.sh b/lib/main.sh index 71f11ca019..b308bcce9e 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -9,14 +9,6 @@ # This file is a part of the Armbian build script # https://github.com/armbian/build/ -cleanup_list() { - local varname="${1}" - local list_to_clean="${!varname}" - list_to_clean="${list_to_clean#"${list_to_clean%%[![:space:]]*}"}" - list_to_clean="${list_to_clean%"${list_to_clean##*[![:space:]]}"}" - echo ${list_to_clean} -} - if [[ $(basename "$0") == main.sh ]]; then echo "Please use compile.sh to start the build process" @@ -184,10 +176,6 @@ else IMAGE_TYPE=user-built fi -branch2dir() { - [[ "${1}" == "head" ]] && echo "HEAD" || echo "${1##*:}" -} - BOOTSOURCEDIR="${BOOTDIR}/$(branch2dir "${BOOTBRANCH}")" LINUXSOURCEDIR="${KERNELDIR}/$(branch2dir "${KERNELBRANCH}")" [[ -n $ATFSOURCE ]] && ATFSOURCEDIR="${ATFDIR}/$(branch2dir "${ATFBRANCH}")" @@ -203,167 +191,6 @@ CHOSEN_ROOTFS=${BSP_CLI_PACKAGE_NAME} CHOSEN_DESKTOP=armbian-${RELEASE}-desktop-${DESKTOP_ENVIRONMENT} CHOSEN_KSRC=linux-source-${BRANCH}-${LINUXFAMILY} -do_default() { - - start=$(date +%s) - - # Check and install dependencies, directory structure and settings - # The OFFLINE_WORK variable inside the function - prepare_host - - [[ "${JUST_INIT}" == "yes" ]] && exit 0 - - [[ $CLEAN_LEVEL == *sources* ]] && cleaning "sources" - - # fetch_from_repo - - # ignore updates help on building all images - for internal purposes - if [[ $IGNORE_UPDATES != yes ]]; then - display_alert "Downloading sources" "" "info" - [[ -n $BOOTSOURCE ]] && fetch_from_repo "$BOOTSOURCE" "$BOOTDIR" "$BOOTBRANCH" "yes" - [[ -n $ATFSOURCE ]] && fetch_from_repo "$ATFSOURCE" "$ATFDIR" "$ATFBRANCH" "yes" - - if [[ -n $KERNELSOURCE ]]; then - if $(declare -f var_origin_kernel > /dev/null); then - unset LINUXSOURCEDIR - LINUXSOURCEDIR="linux-mainline/$KERNEL_VERSION_LEVEL" - VAR_SHALLOW_ORIGINAL=var_origin_kernel - waiter_local_git "url=$KERNELSOURCE $KERNELSOURCENAME $KERNELBRANCH dir=$LINUXSOURCEDIR $KERNELSWITCHOBJ" - unset VAR_SHALLOW_ORIGINAL - else - fetch_from_repo "$KERNELSOURCE" "$KERNELDIR" "$KERNELBRANCH" "yes" - fi - fi - - call_extension_method "fetch_sources_tools" <<- 'FETCH_SOURCES_TOOLS' - *fetch host-side sources needed for tools and build* - Run early to fetch_from_repo or otherwise obtain sources for needed tools. - FETCH_SOURCES_TOOLS - - call_extension_method "build_host_tools" <<- 'BUILD_HOST_TOOLS' - *build needed tools for the build, host-side* - After sources are fetched, build host-side tools needed for the build. - BUILD_HOST_TOOLS - - for option in $(tr ',' ' ' <<< "$CLEAN_LEVEL"); do - [[ $option != sources ]] && cleaning "$option" - done - fi - - # Don't build at all if the BOOTCONFIG is 'none'. - [[ "${BOOTCONFIG}" != "none" ]] && { - # Compile u-boot if packed .deb does not exist or use the one from repository - if [[ ! -f "${DEB_STORAGE}"/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb ]]; then - if [[ -n "${ATFSOURCE}" && "${REPOSITORY_INSTALL}" != *u-boot* ]]; then - compile_atf - fi - [[ "${REPOSITORY_INSTALL}" != *u-boot* ]] && compile_uboot - fi - } - - # Compile kernel if packed .deb does not exist or use the one from repository - if [[ ! -f ${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb ]]; then - - KDEB_CHANGELOG_DIST=$RELEASE - [[ -n $KERNELSOURCE ]] && [[ "${REPOSITORY_INSTALL}" != *kernel* ]] && compile_kernel - - fi - - # Compile armbian-config if packed .deb does not exist or use the one from repository - if [[ ! -f ${DEB_STORAGE}/armbian-config_${REVISION}_all.deb ]]; then - - [[ "${REPOSITORY_INSTALL}" != *armbian-config* ]] && compile_armbian-config - - fi - - # Compile armbian-zsh if packed .deb does not exist or use the one from repository - if [[ ! -f ${DEB_STORAGE}/armbian-zsh_${REVISION}_all.deb ]]; then - - [[ "${REPOSITORY_INSTALL}" != *armbian-zsh* ]] && compile_armbian-zsh - - fi - - # Compile plymouth-theme-armbian if packed .deb does not exist or use the one from repository - if [[ ! -f ${DEB_STORAGE}/plymouth-theme-armbian_${REVISION}_all.deb ]]; then - - [[ "${REPOSITORY_INSTALL}" != *plymouth-theme-armbian* ]] && compile_plymouth-theme-armbian - - fi - - # Compile armbian-firmware if packed .deb does not exist or use the one from repository - if ! ls "${DEB_STORAGE}/armbian-firmware_${REVISION}_all.deb" 1> /dev/null 2>&1 || ! ls "${DEB_STORAGE}/armbian-firmware-full_${REVISION}_all.deb" 1> /dev/null 2>&1; then - - if [[ "${REPOSITORY_INSTALL}" != *armbian-firmware* ]]; then - [[ "${INSTALL_ARMBIAN_FIRMWARE:-yes}" == "yes" ]] && { # Build firmware by default. - FULL="" - REPLACE="-full" - compile_firmware - FULL="-full" - REPLACE="" - compile_firmware - } - - fi - - fi - - overlayfs_wrapper "cleanup" - - # create board support package - [[ -n "${RELEASE}" && ! -f "${DEB_STORAGE}/${BSP_CLI_PACKAGE_FULLNAME}.deb" && "${REPOSITORY_INSTALL}" != *armbian-bsp-cli* ]] && create_board_package - - # create desktop package - [[ -n "${RELEASE}" && "${DESKTOP_ENVIRONMENT}" && ! -f "${DEB_STORAGE}/$RELEASE/${CHOSEN_DESKTOP}_${REVISION}_all.deb" && "${REPOSITORY_INSTALL}" != *armbian-desktop* ]] && create_desktop_package - [[ -n "${RELEASE}" && "${DESKTOP_ENVIRONMENT}" && ! -f "${DEB_STORAGE}/${RELEASE}/${BSP_DESKTOP_PACKAGE_FULLNAME}.deb" && "${REPOSITORY_INSTALL}" != *armbian-bsp-desktop* ]] && create_bsp_desktop_package - - # skip image creation if exists. useful for CI when making a lot of images - if [ "$IMAGE_PRESENT" == yes ] && ls "${FINALDEST}/${VENDOR}_${REVISION}_${BOARD^}_${RELEASE}_${BRANCH}_${VER/-$LINUXFAMILY/}${DESKTOP_ENVIRONMENT:+_$DESKTOP_ENVIRONMENT}"*.xz 1> /dev/null 2>&1; then - display_alert "Skipping image creation" "image already made - IMAGE_PRESENT is set" "wrn" - exit - fi - - # build additional packages - [[ $EXTERNAL_NEW == compile ]] && chroot_build_packages - - if [[ $KERNEL_ONLY != yes ]]; then - - [[ $BSP_BUILD != yes ]] && debootstrap_ng - - else - - display_alert "Kernel build done" "@host" "info" - display_alert "Target directory" "${DEB_STORAGE}/" "info" - display_alert "File name" "${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" "info" - - fi - - call_extension_method "run_after_build" << 'RUN_AFTER_BUILD' -*hook for function to run after build, i.e. to change owner of `$SRC`* -Really one of the last hooks ever called. The build has ended. Congratulations. -- *NOTE:* this will run only if there were no errors during build process. -RUN_AFTER_BUILD - - end=$(date +%s) - runtime=$(((end - start) / 60)) - display_alert "Runtime" "$runtime min" "info" - - # Make it easy to repeat build by displaying build options used - [ "$(systemd-detect-virt)" == 'docker' ] && BUILD_CONFIG='docker' - display_alert "Repeat Build Options" "./compile.sh ${BUILD_CONFIG} BOARD=${BOARD} BRANCH=${BRANCH} \ -$([[ -n $RELEASE ]] && echo "RELEASE=${RELEASE} ")\ -$([[ -n $BUILD_MINIMAL ]] && echo "BUILD_MINIMAL=${BUILD_MINIMAL} ")\ -$([[ -n $BUILD_DESKTOP ]] && echo "BUILD_DESKTOP=${BUILD_DESKTOP} ")\ -$([[ -n $KERNEL_ONLY ]] && echo "KERNEL_ONLY=${KERNEL_ONLY} ")\ -$([[ -n $KERNEL_CONFIGURE ]] && echo "KERNEL_CONFIGURE=${KERNEL_CONFIGURE} ")\ -$([[ -n $DESKTOP_ENVIRONMENT ]] && echo "DESKTOP_ENVIRONMENT=${DESKTOP_ENVIRONMENT} ")\ -$([[ -n $DESKTOP_ENVIRONMENT_CONFIG_NAME ]] && echo "DESKTOP_ENVIRONMENT_CONFIG_NAME=${DESKTOP_ENVIRONMENT_CONFIG_NAME} ")\ -$([[ -n $DESKTOP_APPGROUPS_SELECTED ]] && echo "DESKTOP_APPGROUPS_SELECTED=\"${DESKTOP_APPGROUPS_SELECTED}\" ")\ -$([[ -n $DESKTOP_APT_FLAGS_SELECTED ]] && echo "DESKTOP_APT_FLAGS_SELECTED=\"${DESKTOP_APT_FLAGS_SELECTED}\" ")\ -$([[ -n $COMPRESS_OUTPUTIMAGE ]] && echo "COMPRESS_OUTPUTIMAGE=${COMPRESS_OUTPUTIMAGE} ")\ -" "ext" - -} # end of do_default() - if [[ -z $1 ]]; then do_default else