From 4e870f9781f315b79c44b54d348317d73ea4b5b2 Mon Sep 17 00:00:00 2001 From: David P Date: Wed, 7 Oct 2020 16:36:42 -0300 Subject: sync with archiso, add _run_dual function Imported from archiso: bfab360 (HEAD -> master, origin/master, origin/HEAD) Ensure that _make_boot_uefi-x64.systemd-boot.esp can be re-run if it fails f45fc29 Save SOURCE_DATE_EPOCH to a file and read it from the file when resuming a build 455e2b9 Check command line parameter count instead of option count, and do it after evaluating option arguments New stuff: * add _run_dual function to simplify running commands for dual and non-dual isos * little typo fixes * tell which architecture is the squashfs image being created for * hardcode x86_64 in _make_boot_on_fat, since it only works for it and is needed due to the new way to handle dual isos Signed-off-by: David P --- parabolaiso/mkparabolaiso | 129 +++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 65 deletions(-) diff --git a/parabolaiso/mkparabolaiso b/parabolaiso/mkparabolaiso index 895c35e..52d14ff 100755 --- a/parabolaiso/mkparabolaiso +++ b/parabolaiso/mkparabolaiso @@ -149,7 +149,8 @@ ENDUSAGETEXT # Shows configuration according to command mode. # $1: build_profile | init | install | run | prepare | iso _show_config() { - local _mode="$1" + local _mode="$1" build_date + build_date="$(date --utc --iso-8601=seconds -d "@${SOURCE_DATE_EPOCH}")" _msg_info "${app_name} configuration settings" [[ ! -d "${command_name}" ]] && _msg_info " Legacy Command: ${command_name}" _msg_info " Architecture: ${arch}" @@ -157,6 +158,7 @@ _show_config() { _msg_info " Installation directory: ${install_dir}" case "${_mode}" in build_profile) + _msg_info " Build date: ${build_date}" _msg_info " Output directory: ${out_dir}" _msg_info " GPG key: ${gpg_key:-None}" _msg_info " Profile: ${profile}" @@ -214,7 +216,7 @@ _pacman() { # Cleanup airootfs _cleanup() { - _msg_info "Cleaning up what we can on airootfs..." + _msg_info "Cleaning up what we can on ${arch} airootfs..." # Delete all files in /boot if [[ -d "${airootfs_dir}/boot" ]]; then @@ -288,7 +290,7 @@ _mkairootfs_sfs() { fi install -d -m 0755 -- "${isofs_dir}/${install_dir}/${arch}" - _msg_info "Creating SquashFS image, this may take some time..." + _msg_info "Creating ${arch} SquashFS image, this may take some time..." if [[ "${quiet}" = "y" ]]; then mksquashfs "${airootfs_dir}" "${isofs_dir}/${install_dir}/${arch}/airootfs.sfs" -noappend \ -comp "${sfs_comp}" -no-progress > /dev/null @@ -323,6 +325,24 @@ _run_once() { fi } +# Helper function to run functions for both architectures +_run_dual() { + local cmd + if [[ "${arch}" == "dual" ]]; then + local arch + for arch in i686 x86_64; do + airootfs_dir="${work_dir}/${arch}/airootfs" + for cmd in "$@"; do + ${cmd} + done + done + else + for cmd in "$@"; do + ${cmd} + done + fi +} + # Set up custom pacman.conf with current cache directories. _make_pacman_conf() { local _cache_dirs @@ -338,7 +358,7 @@ _make_custom_airootfs() { install -d -m 0755 -o 0 -g 0 -- "${airootfs_dir}" if [[ -d "${profile}/airootfs" ]]; then - _msg_info "Copying custom custom airootfs files and setting up user home directories..." + _msg_info "Copying custom airootfs files and setting up user home directories..." cp -af --no-preserve=ownership -- "${profile}/airootfs/." "${airootfs_dir}" [[ -e "${airootfs_dir}/etc/shadow" ]] && chmod -f 0400 -- "${airootfs_dir}/etc/shadow" @@ -443,14 +463,7 @@ _make_boot_bios.syslinux.mbr() { install -m 0644 -- "${airootfs_dir}/usr/lib/syslinux/bios/lpxelinux.0" "${isofs_dir}/${install_dir}/boot/syslinux/" install -m 0644 -- "${airootfs_dir}/usr/lib/syslinux/bios/memdisk" "${isofs_dir}/${install_dir}/boot/syslinux/" - if [[ "${arch}" == "dual" ]]; then - for arch in i686 x86_64; do - airootfs_dir="${work_dir}/${arch}/airootfs" - _run_once _make_boot_on_iso - done - else - _run_once _make_boot_on_iso - fi + _run_dual '_run_once _make_boot_on_iso' if [[ -e "${isofs_dir}/${install_dir}/boot/syslinux/hdt.c32" ]]; then install -d -m 0755 -- "${isofs_dir}/${install_dir}/boot/syslinux/hdt" @@ -543,9 +556,9 @@ _make_refind_efi() { _make_boot_on_fat() { _msg_info "Preparing kernel and initramfs for the FAT file system..." mmd -i "${isofs_dir}/EFI/parabolaiso/efiboot.img" \ - "::/${install_dir}" "::/${install_dir}/boot" "::/${install_dir}/boot/${arch}" + "::/${install_dir}" "::/${install_dir}/boot" "::/${install_dir}/boot/x86_64" mcopy -i "${isofs_dir}/EFI/parabolaiso/efiboot.img" "${airootfs_dir}/boot/vmlinuz-"* \ - "${airootfs_dir}/boot/initramfs-"*".img" "::/${install_dir}/boot/${arch}/" + "${airootfs_dir}/boot/initramfs-"*".img" "::/${install_dir}/boot/x86_64/" _msg_info "Done!" } @@ -562,9 +575,14 @@ _make_boot_uefi-x64.systemd-boot.esp() { "${profile}/efiboot/" \ "${airootfs_dir}/boot/vmlinuz-"* \ "${airootfs_dir}/boot/initramfs-"*".img" \ - 2>/dev/null | awk 'END {print $1}') / 1048576 )) +1 )) * 1024 ))" + 2>/dev/null | awk 'function ceil(x){return int(x)+(x>int(x))} + function byte_to_kib(x){return x/1024} + function mib_to_kib(x){return x*1024} + END {print mib_to_kib(ceil((byte_to_kib($1)+1024)/1024))}' + )" # The FAT image must be created with mkfs.fat not mformat, as some systems have issues with mformat made images: # https://lists.gnu.org/archive/html/grub-devel/2019-04/msg00099.html + [[ -e "${isofs_dir}/EFI/parabolaiso/efiboot.img" ]] && rm -f -- "${isofs_dir}/EFI/parabolaiso/efiboot.img" _msg_info "Creating FAT image of size: ${efiboot_imgsize} KiB..." mkfs.fat -C -n PARABOLAISO_EFI "${isofs_dir}/EFI/parabolaiso/efiboot.img" "$efiboot_imgsize" @@ -588,7 +606,7 @@ _make_boot_uefi-x64.systemd-boot.esp() { fi # Copy kernel and initramfs - _run_once _make_boot_on_fat + _make_boot_on_fat _msg_info "Done! systemd-boot set up for UEFI booting successfully." } @@ -605,9 +623,14 @@ _make_boot_uefi-x64.refind.esp() { "${profile}/efiboot/" \ "${airootfs_dir}/boot/vmlinuz-"* \ "${airootfs_dir}/boot/initramfs-"*".img" \ - 2>/dev/null | awk 'END {print $1}') / 1048576 )) +1 )) * 1024 ))" + 2>/dev/null | awk 'function ceil(x){return int(x)+(x>int(x))} + function byte_to_kib(x){return x/1024} + function mib_to_kib(x){return x*1024} + END {print mib_to_kib(ceil((byte_to_kib($1)+1024)/1024))}' + )" # The FAT image must be created with mkfs.fat not mformat, as some systems have issues with mformat made images: # https://lists.gnu.org/archive/html/grub-devel/2019-04/msg00099.html + [[ -e "${isofs_dir}/EFI/parabolaiso/efiboot.img" ]] && rm -f -- "${isofs_dir}/EFI/parabolaiso/efiboot.img" _msg_info "Creating FAT image of size: ${efiboot_imgsize} KiB..." mkfs.fat -C -n PARABOLAISO_EFI "${isofs_dir}/EFI/parabolaiso/efiboot.img" "$efiboot_imgsize" @@ -631,7 +654,7 @@ _make_boot_uefi-x64.refind.esp() { fi # Copy kernel and initramfs - _run_once _make_boot_on_fat + _make_boot_on_fat _msg_info "Done! rEFInd set up for UEFI booting successfully." } @@ -652,9 +675,9 @@ _make_boot_uefi-x64.refind.eltorito() { # Build airootfs filesystem image _make_prepare() { if [[ "${sfs_mode}" == "sfs" ]]; then - _mkairootfs_sfs + _run_once _mkairootfs_sfs else - _mkairootfs_img + _run_once _mkairootfs_img fi _mkchecksum if [[ "${gpg_key}" ]]; then @@ -859,52 +882,27 @@ command_build_profile() { # Set ISO file name img_name="${iso_name}-${iso_version}-${arch}.iso" - if [[ "${arch}" == "dual" ]]; then - _show_config "${FUNCNAME[0]#command_}" - - # Create working directory - [[ -d "${work_dir}" ]] || install -d -- "${work_dir}" - - _run_once _make_pacman_conf - _run_once _export_gpg_publickey - for arch in i686 x86_64; do - airootfs_dir="${work_dir}/${arch}/airootfs" - _run_once _make_custom_airootfs - _run_once _make_packages - done - for arch in i686 x86_64; do - airootfs_dir="${work_dir}/${arch}/airootfs" - _run_once _make_customize_airootfs - done - for arch in i686 x86_64; do - airootfs_dir="${work_dir}/${arch}/airootfs" - _run_once _make_pkglist - done - arch="dual" - _make_bootmodes - for arch in i686 x86_64; do - airootfs_dir="${work_dir}/${arch}/airootfs" - _run_once _cleanup - _run_once _make_prepare - done - _run_once _make_iso + # Create working directory + [[ -d "${work_dir}" ]] || install -d -- "${work_dir}" + # Write build date to file or if the file exists, read it from there + if [[ -e "${work_dir}/build_date" ]]; then + SOURCE_DATE_EPOCH="$(<"${work_dir}/build_date")" else - _show_config "${FUNCNAME[0]#command_}" + printf '%s\n' "$SOURCE_DATE_EPOCH" > "${work_dir}/build_date" + fi - # Create working directory - [[ -d "${work_dir}" ]] || install -d -- "${work_dir}" + _show_config "${FUNCNAME[0]#command_}" - _run_once _make_pacman_conf - _run_once _export_gpg_publickey - _run_once _make_custom_airootfs - _run_once _make_packages - _run_once _make_customize_airootfs - _run_once _make_pkglist - _make_bootmodes - _run_once _cleanup - _run_once _make_prepare - _run_once _make_iso - fi + _run_once _make_pacman_conf + _run_once _export_gpg_publickey + _run_dual '_run_once _make_custom_airootfs' \ + '_run_once _make_packages' + _run_dual '_run_once _make_customize_airootfs' + _run_dual '_run_once _make_pkglist' + _make_bootmodes + _run_dual '_run_once _cleanup' \ + '_run_once _make_prepare' + _run_once _make_iso } while getopts 'p:r:C:L:P:A:D:w:o:s:c:g:vh?' arg; do @@ -933,7 +931,9 @@ while getopts 'p:r:C:L:P:A:D:w:o:s:c:g:vh?' arg; do esac done -if (( OPTIND <= 1 )); then +shift $((OPTIND - 1)) + +if (( $# < 1 )); then _msg_error "No command specified" 0 _usage 1 fi @@ -942,7 +942,6 @@ if (( EUID != 0 )); then _msg_error "${app_name} must be run as root." 1 fi -shift $((OPTIND - 1)) command_name="${1}" # Set directory path defaults for legacy commands -- cgit v1.2.2