From e2c5b4527ff1848a0ebaaca0ab9d05077ae08eee Mon Sep 17 00:00:00 2001 From: nl6720 Date: Thu, 20 Aug 2020 17:00:06 +0300 Subject: [PATCH] archiso/mkarchiso: reduce duplication and add more info messages Fixes to issues introduced in https://gitlab.archlinux.org/archlinux/archiso/-/merge_requests/59 : - _make_boot_on_fat(): copy initramfs from "${airootfs_dir}/boot/" not "${isofs_dir}/". Otherwise UEFI-only ISOs cannot be built. Some general fixes: - Replace mkdir with install. Unlike mkdir, install does not complain when the target exists. - Reduce excess newlines produced by messages. - Ensure FAT image gets unmounted in case the script is interrupted. - Create the ext4 image with mkfs.ext4 instead of truncate. - Do not rely on user and group names for chown commands. Use numeric UID and GID instead. - Minimize the times stderr is redirected to /dev/null. - Add missing '?' to getopts. - Standardize function definitions by removing spaces between the function name and () . --- archiso/mkarchiso | 272 +++++++++++++++++++++++++--------------------- 1 file changed, 149 insertions(+), 123 deletions(-) diff --git a/archiso/mkarchiso b/archiso/mkarchiso index 4a010ad..2ccf7f0 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -39,14 +39,13 @@ bootmodes=() _msg_info() { local _msg="${1}" [[ "${quiet}" == "y" ]] || printf '[%s] INFO: %s\n' "${app_name}" "${_msg}" - } # Show a WARNING message # $1: message string _msg_warning() { local _msg="${1}" - printf '\n[%s] WARNING: %s\n\n' "${app_name}" "${_msg}" >&2 + printf '[%s] WARNING: %s\n' "${app_name}" "${_msg}" >&2 } # Show an ERROR message then exit with status @@ -55,14 +54,14 @@ _msg_warning() { _msg_error() { local _msg="${1}" local _error=${2} - printf '\n[%s] ERROR: %s\n\n' "${app_name}" "${_msg}" >&2 + printf '[%s] ERROR: %s\n' "${app_name}" "${_msg}" >&2 if (( _error > 0 )); then exit "${_error}" fi } _chroot_init() { - mkdir -p -- "${airootfs_dir}" + install -d -m 0755 -o 0 -g 0 -- "${airootfs_dir}" _pacman base syslinux } @@ -72,35 +71,51 @@ _chroot_run() { _mount_airootfs() { trap "_umount_airootfs" EXIT HUP INT TERM - mkdir -p -- "${work_dir}/mnt/airootfs" - _msg_info "Mounting '${airootfs_dir}.img' on '${work_dir}/mnt/airootfs'" + install -d -m 0755 -- "${work_dir}/mnt/airootfs" + _msg_info "Mounting '${airootfs_dir}.img' on '${work_dir}/mnt/airootfs'..." mount -- "${airootfs_dir}.img" "${work_dir}/mnt/airootfs" _msg_info "Done!" } _umount_airootfs() { - _msg_info "Unmounting '${work_dir}/mnt/airootfs'" + _msg_info "Unmounting '${work_dir}/mnt/airootfs'..." umount -d -- "${work_dir}/mnt/airootfs" _msg_info "Done!" rmdir -- "${work_dir}/mnt/airootfs" trap - EXIT HUP INT TERM } +_mount_efibootimg() { + trap "_umount_efibootimg" EXIT HUP INT TERM + install -d -m 0755 -- "${work_dir}/mnt/efiboot" + _msg_info "Mounting '${isofs_dir}/EFI/archiso/efiboot.img' on '${work_dir}/mnt/efiboot'..." + mount -- "${isofs_dir}/EFI/archiso/efiboot.img" "${work_dir}/mnt/efiboot" + _msg_info "Done!" +} + +_umount_efibootimg() { + _msg_info "Unmounting '${work_dir}/mnt/efiboot'..." + umount -d -- "${work_dir}/mnt/efiboot" + _msg_info "Done!" + rmdir -- "${work_dir}/mnt/efiboot" + trap - EXIT HUP INT TERM +} + # Show help usage, with an exit status. # $1: exit status number. -_usage () { +_usage() { IFS='' read -r -d '' usagetext < general options: -B Directory of the archiso profile to build -p PACKAGE(S) Package(s) to install, can be used multiple times - -C Config file for pacman. + -C pacman configuration file. Default: '${pacman_conf}' - -L