From 800bd0ef0b151b4a3b45eb1efadb41ff035b839e Mon Sep 17 00:00:00 2001 From: ophub Date: Tue, 18 Jan 2022 14:03:41 +0800 Subject: [PATCH] Unified error output messages --- rebuild | 56 +++++++++++++++++++++++++++---------------------------- recompile | 40 +++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/rebuild b/rebuild index 92185aef9e..bf39cd99b6 100755 --- a/rebuild +++ b/rebuild @@ -40,12 +40,12 @@ BOOT_MB=256 ROOT_MB=2748 #===== Do not modify the following parameter settings, End ======= -die() { +error_msg() { echo -e " [\033[1;91m Error \033[0m] ${1}" exit 1 } -process() { +process_msg() { echo -e " [\033[1;92m ${build_soc}${out_kernel} \033[0m] ${1}" } @@ -135,7 +135,7 @@ make_image() { sync loop_new=$(losetup -P -f --show "${build_image_file}") - [ ${loop_new} ] || die "losetup ${build_image_file} failed." + [ ${loop_new} ] || error_msg "losetup ${build_image_file} failed." mkfs.vfat -n "BOOT" ${loop_new}p1 >/dev/null 2>&1 mke2fs -F -q -t ext4 -L "ROOTFS" -m 0 ${loop_new}p2 >/dev/null 2>&1 @@ -151,10 +151,10 @@ extract_armbian() { sync && sleep 3 loop_old=$(losetup -P -f --show "${armbian_image_file}") - [ ${loop_old} ] || die "losetup ${armbian_image_file} failed." + [ ${loop_old} ] || error_msg "losetup ${armbian_image_file} failed." if ! mount ${loop_old}p1 ${tmp_armbian}; then - die "mount ${loop_old}p1 failed!" + error_msg "mount ${loop_old}p1 failed!" fi cd ${tmp_armbian} @@ -176,7 +176,7 @@ replace_kernel() { # 01 For /boot five files (cd ${tmp_armbian}/boot && rm -rf *-${armbian_original_kernel}-* uInitrd zImage dtb* 2>/dev/null && sync) tar -xzf ${build_boot} -C ${tmp_armbian}/boot && sync - [ "$(ls ${tmp_armbian}/boot/*-${new_kernel}-* -l 2>/dev/null | grep "^-" | wc -l)" -ge "4" ] || die "boot/ 5 files is missing." + [ "$(ls ${tmp_armbian}/boot/*-${new_kernel}-* -l 2>/dev/null | grep "^-" | wc -l)" -ge "4" ] || error_msg "boot/ 5 files is missing." # 02 For dtb files mkdir -p ${tmp_armbian}/boot/dtb/amlogic && sync @@ -187,7 +187,7 @@ replace_kernel() { tar -xzf ${build_modules} -C ${tmp_armbian}/usr/lib/modules && sync (cd ${tmp_armbian}/usr/lib/modules/*/ && echo "build source" | xargs rm -f && sync) if [ "$(ls ${tmp_armbian}/usr/lib/modules/${new_kernel}* -l 2>/dev/null | grep "^d" | wc -l)" -ne "1" ]; then - die "${tmp_armbian}/usr/lib/modules/${new_kernel}-* kernel folder is missing." + error_msg "${tmp_armbian}/usr/lib/modules/${new_kernel}-* kernel folder is missing." fi # 04 For header files, usr/local/include @@ -204,8 +204,8 @@ copy_files() { cd ${tmp_armbian} #Check if writing to EMMC is supported - MODULES_NOW=$(ls usr/lib/modules/ 2>/dev/null) - VERSION_NOW=$(echo ${MODULES_NOW} | grep -oE '^[1-9].[0-9]{1,3}' 2>/dev/null) + VERSION_NOW=$(ls usr/lib/modules/ 2>/dev/null | sort -rV | head -n 1 | grep -oE '^[1-9].[0-9]{1,3}.[0-9]+') + [ -z "${VERSION_NOW}" ] && error_msg "Failed to query the current version." #echo -e "This Kernel [ ${VERSION_NOW} ]" k510_ver=$(echo "${VERSION_NOW}" | cut -d '.' -f1) @@ -318,7 +318,7 @@ copy_files() { AMLOGIC_SOC="s922x" ;; *) - die "Have no this soc: [ ${build_soc} ]" + error_msg "Have no this soc: [ ${build_soc} ]" ;; esac @@ -358,10 +358,10 @@ copy_files() { mkdir -p ${tag_bootfs} ${tag_rootfs} && sync if ! mount ${loop_new}p2 ${tag_rootfs}; then - die "mount ${loop_new}p2 failed!" + error_msg "mount ${loop_new}p2 failed!" fi if ! mount ${loop_new}p1 ${tag_bootfs}; then - die "mount ${loop_new}p1 failed!" + error_msg "mount ${loop_new}p1 failed!" fi # Copy boot files @@ -380,7 +380,7 @@ copy_files() { armbian_ubuntu=("bionic" "focal" "hirsute") armbian_debian=("bullseye" "buster" "stretch") release_codename="$(cat ${tag_rootfs}/${os_release_file} | grep -oE "^VERSION_CODENAME=.*" | cut -d"=" -f2)" - [ -z "${release_codename}" ] && die "RELEASE CODENAME is invalid." + [ -z "${release_codename}" ] && error_msg "RELEASE CODENAME is invalid." diff_release_files="${configfiles_path}/release/${release_codename}" if [[ -n "${release_codename}" && -d "${diff_release_files}" ]]; then # Backup source @@ -403,13 +403,13 @@ copy_files() { if [[ -f "${UBOOT_OVERLOAD}" && -n "${UBOOT_OVERLOAD}" ]]; then cp -f ${UBOOT_OVERLOAD} u-boot.ext && sync && chmod +x u-boot.ext else - die "${build_soc} have no the 5.10 kernel u-boot file: [ ${UBOOT_OVERLOAD} ]" + error_msg "${build_soc} have no the 5.10 kernel u-boot file: [ ${UBOOT_OVERLOAD} ]" fi fi # Edit the uEnv.txt if [ ! -f "uEnv.txt" ]; then - die "The uEnv.txt File does not exist" + error_msg "The uEnv.txt File does not exist" else old_fdt_dtb="meson-gxl-s905d-phicomm-n1.dtb" sed -i "s/${old_fdt_dtb}/${FDTFILE}/g" uEnv.txt @@ -539,7 +539,7 @@ while [ "${1}" ]; do IFS=$oldIFS shift else - die "Invalid -b parameter [ ${2} ]!" + error_msg "Invalid -b parameter [ ${2} ]!" fi ;; -k | --kernel) @@ -550,7 +550,7 @@ while [ "${1}" ]; do IFS=$oldIFS shift else - die "Invalid -k parameter [ ${2} ]!" + error_msg "Invalid -k parameter [ ${2} ]!" fi ;; -a | --autokernel) @@ -558,7 +558,7 @@ while [ "${1}" ]; do auto_kernel="${2}" shift else - die "Invalid -a parameter [ ${2} ]!" + error_msg "Invalid -a parameter [ ${2} ]!" fi ;; -v | --versionbranch) @@ -566,7 +566,7 @@ while [ "${1}" ]; do version_branch="${2}" shift else - die "Invalid -v parameter [ ${2} ]!" + error_msg "Invalid -v parameter [ ${2} ]!" fi ;; -s | --size) @@ -574,11 +574,11 @@ while [ "${1}" ]; do ROOT_MB="${2}" shift else - die "Invalid -s parameter [ ${2} ]!" + error_msg "Invalid -s parameter [ ${2} ]!" fi ;; *) - die "Invalid option [ ${1} ]!" + error_msg "Invalid option [ ${1} ]!" ;; esac shift @@ -589,12 +589,12 @@ done # Get armbian release and version armbian_image_name=$(ls ${armbian_original_file} 2>/dev/null | head -n 1 | awk -F "/" '{print $NF}') -[[ -n "${armbian_image_name}" ]] || die "The armbian original file does not exist: [ ${armbian_original_file} ]" +[[ -n "${armbian_image_name}" ]] || error_msg "The armbian original file does not exist: [ ${armbian_original_file} ]" armbian_original_version="$(echo ${armbian_image_name} | grep -oE '2[0-9].[0-9]{1,2}[.]*[0-9]{1,2}' | head -n 1)" armbian_original_kernel="$(echo ${armbian_image_name} | grep -oE '[4-5].[0-9]{1,2}.[0-9]{1,3}' | head -n 1)" # Show welcome message -[ $(id -u) = 0 ] || die "please run this script as root: [ sudo ./$0 ]" +[ $(id -u) = 0 ] || error_msg "please run this script as root: [ sudo ./$0 ]" echo -e "\n" echo -e "Welcome to build Armbian for Amlogic s9xxx tv box!" echo -e "Armbian original file: [ ${armbian_image_name} ], Version: [ ${armbian_original_version} ], Kernel: [ ${armbian_original_kernel} ]" @@ -627,15 +627,15 @@ for b in ${build_armbian[*]}; do out_kernel=" - ${x}" fi - process " (1/5) make new armbian image." + process_msg " (1/5) make new armbian image." make_image - process " (2/5) extract old armbian files." + process_msg " (2/5) extract old armbian files." extract_armbian - process " (3/5) replace kernel for armbian." + process_msg " (3/5) replace kernel for armbian." replace_kernel - process " (4/5) copy files to new image." + process_msg " (4/5) copy files to new image." copy_files - process " (5/5) clear temp files." + process_msg " (5/5) clear temp files." clean_tmp echo -e "(${k}.${i}) Build successfully. \n" diff --git a/recompile b/recompile index a86c5f4a4a..deeb3e35b2 100755 --- a/recompile +++ b/recompile @@ -57,7 +57,7 @@ WARNING="[${yellow_font_prefix}WARNING${font_color_suffix}]" ERROR="[${red_font_prefix}ERROR${font_color_suffix}]" #===== Do not modify the following parameter settings, End ======= -die() { +error_msg() { echo -e "${ERROR} ${1}" exit 1 } @@ -78,7 +78,7 @@ check_environment() { tar -xJf ${use_linuxgun_localpath}/${use_linuxgun_file} -C ${use_linuxgun_localpath} && sync fi if [ ! -d "${use_linuxgun_localpath}/${use_linuxgun_file//.tar.xz/}/bin" ]; then - die "The cross compilation environment is not set!" + error_msg "The cross compilation environment is not set!" fi else echo -e "${INFO} Run on aarch64" @@ -105,7 +105,7 @@ query_version() { if [[ "$?" -eq "0" && ! -z "${latest_version}" ]]; then tmp_arr_kernels[${i}]="${latest_version}" else - die "Failed to query the kernel version in [ ${kernel_org_repo} ]" + error_msg "Failed to query the kernel version in [ ${kernel_org_repo} ]" fi echo -e "${INFO} (${i}) [ ${tmp_arr_kernels[$i]} ] is kernel.org latest kernel. \n" else @@ -116,7 +116,7 @@ query_version() { if [[ "$?" -eq "0" && ! -z "${latest_version}" ]]; then tmp_arr_kernels[${i}]="${MAIN_LINE}.${latest_version}" else - die "Failed to query the kernel version in [ github.com/${github_kernel_repo} ]" + error_msg "Failed to query the kernel version in [ github.com/${github_kernel_repo} ]" fi echo -e "${INFO} (${i}) [ ${tmp_arr_kernels[$i]} ] is github.com/${github_kernel_repo} latest kernel. \n" fi @@ -133,7 +133,7 @@ local_kernel_check() { cd ${make_path} # Check whether the kernel of the same name has been installed locally local_kernel="$(ls /lib/modules -l | grep -E '^d' | awk '{print $9}' | grep -w "${kernel_version}${custom_name}")" - [ -n "${local_kernel}" ] && die "The current system has the same named kernel [ ${kernel_version}${custom_name} ], stop compiling!" + [ -n "${local_kernel}" ] && error_msg "The current system has the same named kernel [ ${kernel_version}${custom_name} ], stop compiling!" # Create a temp directory rm -rf ${out_kernel}/{armbian/,boot/,dtb/,modules/,header/,${kernel_version}/} 2>/dev/null && sync @@ -151,7 +151,7 @@ download_kernel() { echo -e "${INFO} Unzip local files [ ${linux_kernel_dirname}.tar.xz ]" cd ${kernel_path} tar -xJf ${linux_kernel_dirname}.tar.xz - [ "$?" -eq "0" ] || die "[ ${linux_kernel_dirname}.tar.xz ] file decompression failed." + [ "$?" -eq "0" ] || error_msg "[ ${linux_kernel_dirname}.tar.xz ] file decompression failed." else echo -e "${INFO} [ ${kernel_version} ] Kernel loading from [ ${kernel_org_repo}${linux_kernel_dirname}.tar.xz ]" wget -q -P ${kernel_path} ${kernel_org_repo}${linux_kernel_dirname}.tar.xz && sync @@ -159,15 +159,15 @@ download_kernel() { echo -e "${SUCCESS} The kernel file is downloaded successfully." cd ${kernel_path} tar -xJf ${linux_kernel_dirname}.tar.xz && sync - [ -d "${linux_kernel_dirname}" ] || die "[ ${linux_kernel_dirname}.tar.xz ] file decompression failed." + [ -d "${linux_kernel_dirname}" ] || error_msg "[ ${linux_kernel_dirname}.tar.xz ] file decompression failed." else - die "Kernel file download failed!" + error_msg "Kernel file download failed!" fi fi else echo -e "${INFO} Start cloning from [ https://github.com/${repo_owner}/${linux_kernel_dirname} ]" git clone --depth 1 https://github.com/${repo_owner}/${linux_kernel_dirname} ${repo_branch} ${kernel_path}/${linux_kernel_dirname} - [ "$?" -eq "0" ] || die "[ https://github.com/${repo_owner}/${linux_kernel_dirname} ] Clone failed." + [ "$?" -eq "0" ] || error_msg "[ https://github.com/${repo_owner}/${linux_kernel_dirname} ] Clone failed." fi else echo -e "${INFO} [ ${linux_kernel_dirname} ] Kernel is in the local directory." @@ -182,7 +182,7 @@ make_kernel() { echo -e "${STEPS} Copy config file to ${linux_kernel_dirname}" config_demo=$(ls ${config_dir}/config-${kernel_vermaj}* 2>/dev/null | head -n 1) config_demo_file=${config_demo##*/} - [ -z "${config_demo_file}" ] && die "Missing [ config-${kernel_vermaj}* ] template!" + [ -z "${config_demo_file}" ] && error_msg "Missing [ config-${kernel_vermaj}* ] template!" echo -e "${INFO} CONFIG_DEMO: ${config_demo_file}" cp -vf ${config_dir}/${config_demo_file} .config && sync else @@ -279,13 +279,13 @@ chroot_armbian_for_x64() { tag_rootfs=${out_kernel}/armbian/root loop_armbian=$(losetup -P -f --show "${armbian_chroot_file}") - [ ${loop_armbian} ] || die "losetup ${armbian_chroot_file} failed." + [ ${loop_armbian} ] || error_msg "losetup ${armbian_chroot_file} failed." if ! mount ${loop_armbian}p2 ${tag_rootfs}; then - die "mount ${loop_armbian}p2 failed!" + error_msg "mount ${loop_armbian}p2 failed!" fi if ! mount ${loop_armbian}p1 ${tag_rootfs}/boot; then - die "mount ${loop_armbian}p1 failed!" + error_msg "mount ${loop_armbian}p1 failed!" fi # Copy related files into armbian system @@ -361,7 +361,7 @@ packit_kernel() { echo -e "${WARNING} Use the backup uInitrd file instead." uInitrd_demo=$(ls ${uInitrd_dir}/uInitrd-${kernel_vermaj}* 2>/dev/null | head -n 1) uInitrd_demo_file=${uInitrd_demo##*/} - [ -z "${uInitrd_demo_file}" ] && die "Missing [ uInitrd-${kernel_vermaj}* ] template!" + [ -z "${uInitrd_demo_file}" ] && error_msg "Missing [ uInitrd-${kernel_vermaj}* ] template!" cp -vf ${uInitrd_dir}/${uInitrd_demo_file} uInitrd-${kernel_version}${LOCALVERSION} && sync else echo -e "${INFO} Use the newly generated uInitrd file." @@ -441,7 +441,7 @@ while [ "${1}" ]; do IFS=$oldIFS shift else - die "Invalid -k parameter [ ${2} ]!" + error_msg "Invalid -k parameter [ ${2} ]!" fi ;; -a | --autoKernel) @@ -449,7 +449,7 @@ while [ "${1}" ]; do auto_kernel="${2}" shift else - die "Invalid -a parameter [ ${2} ]!" + error_msg "Invalid -a parameter [ ${2} ]!" fi ;; -n | --customName) @@ -457,7 +457,7 @@ while [ "${1}" ]; do custom_name="${2}" shift else - die "Invalid -n parameter [ ${2} ]!" + error_msg "Invalid -n parameter [ ${2} ]!" fi ;; -r | --repo) @@ -465,11 +465,11 @@ while [ "${1}" ]; do repo_owner="${2}" shift else - die "Invalid -r parameter [ ${2} ]!" + error_msg "Invalid -r parameter [ ${2} ]!" fi ;; *) - die "Invalid option [ ${1} ]!" + error_msg "Invalid option [ ${1} ]!" ;; esac shift @@ -495,7 +495,7 @@ check_environment # Set whether to replace the kernel [[ "${auto_kernel}" == "true" || "${repo_owner}" != "kernel.org" ]] && query_version -[ $(id -u) = 0 ] || die "please run this script as root: [ sudo ./$0 ]" +[ $(id -u) = 0 ] || error_msg "please run this script as root: [ sudo ./$0 ]" echo -e "Welcome to compile kernel! \n" echo -e "Server space usage before starting to compile: \n$(df -hT ${PWD}) \n" echo -e "Kernel List: [ $(echo ${build_kernel[*]} | tr "\n" " ") ]"