Skip to content

Commit

Permalink
Unified error output messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ophub committed Jan 18, 2022
1 parent 2918d6d commit 800bd0e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
56 changes: 28 additions & 28 deletions rebuild
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -550,35 +550,35 @@ while [ "${1}" ]; do
IFS=$oldIFS
shift
else
die "Invalid -k parameter [ ${2} ]!"
error_msg "Invalid -k parameter [ ${2} ]!"
fi
;;
-a | --autokernel)
if [ -n "${2}" ]; then
auto_kernel="${2}"
shift
else
die "Invalid -a parameter [ ${2} ]!"
error_msg "Invalid -a parameter [ ${2} ]!"
fi
;;
-v | --versionbranch)
if [ -n "${2}" ]; then
version_branch="${2}"
shift
else
die "Invalid -v parameter [ ${2} ]!"
error_msg "Invalid -v parameter [ ${2} ]!"
fi
;;
-s | --size)
if [[ -n "${2}" && "${2}" -ge "2000" ]]; then
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
Expand All @@ -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} ]"
Expand Down Expand Up @@ -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"
Expand Down
40 changes: 20 additions & 20 deletions recompile
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -151,23 +151,23 @@ 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
if [[ "$?" -eq "0" && -s "${kernel_path}/${linux_kernel_dirname}.tar.xz" ]]; then
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."
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -441,35 +441,35 @@ while [ "${1}" ]; do
IFS=$oldIFS
shift
else
die "Invalid -k parameter [ ${2} ]!"
error_msg "Invalid -k parameter [ ${2} ]!"
fi
;;
-a | --autoKernel)
if [ -n "${2}" ]; then
auto_kernel="${2}"
shift
else
die "Invalid -a parameter [ ${2} ]!"
error_msg "Invalid -a parameter [ ${2} ]!"
fi
;;
-n | --customName)
if [ -n "${2}" ]; then
custom_name="${2}"
shift
else
die "Invalid -n parameter [ ${2} ]!"
error_msg "Invalid -n parameter [ ${2} ]!"
fi
;;
-r | --repo)
if [ -n "${2}" ]; then
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
Expand All @@ -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" " ") ]"
Expand Down

0 comments on commit 800bd0e

Please sign in to comment.