diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 40961be..2f234fe 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,8 @@ Added ----- - Add a man page for ``mkarchiso``. +- Implement configurable bootstrap tarball compression. It is configured in ``profiledef.sh`` using a bash array called + ``bootstrap_tarball_compression``. Changed ------- diff --git a/README.rst b/README.rst index fff961d..cf91628 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ archiso ======= The archiso project features scripts and configuration templates to build installation media (*.iso* images and -*.tar.gz* bootstrap images) as well as netboot artifacts for BIOS and UEFI based systems on the x86_64 architecture. +*.tar bootstrap images) as well as netboot artifacts for BIOS and UEFI based systems on the x86_64 architecture. Currently creating the images is only supported on Arch Linux but may work on other operating systems as well. Requirements diff --git a/archiso/mkarchiso b/archiso/mkarchiso index dbae227..e3b582f 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -40,6 +40,7 @@ buildmodes=() bootmodes=() airootfs_image_type="" airootfs_image_tool_options=() +bootstrap_tarball_compression="" cert_list=() declare -A file_permissions=() efibootimg="" @@ -1356,6 +1357,32 @@ _validate_requirements_buildmode_bootstrap() { (( validation_error=validation_error+1 )) _msg_error "Validating build mode '${_buildmode}': bsdtar is not available on this host. Install 'libarchive'!" 0 fi + + # Check if the compressor is installed + if (( ${#bootstrap_tarball_compression[@]} )); then + case "${bootstrap_tarball_compression[0]}" in + 'bzip'|'gzip'|'lrzip'|'lzip'|'lzop'|'zstd'|'zstdmt') + if ! command -v "${bootstrap_tarball_compression[0]}" &>/dev/null; then + (( validation_error=validation_error+1 )) + _msg_error "Validating build mode '${_buildmode}': '${bootstrap_tarball_compression[0]}' is not available on this host. Install '${bootstrap_tarball_compression[0]/zstdmt/zstd}'!" 0 + fi + ;; + 'cat') + if ! command -v cat &>/dev/null; then + (( validation_error=validation_error+1 )) + _msg_error "Validating build mode '${_buildmode}': 'cat' is not available on this host. Install 'coreutils'!" 0 + fi + if (( ${#bootstrap_tarball_compression[@]} > 1 )); then + (( validation_error=validation_error+1 )) + _msg_error "Validating build mode '${_buildmode}': 'cat' compression does not accept arguments!" 0 + fi + ;; + *) + (( validation_error=validation_error+1 )) + _msg_error "Validating build mode '${_buildmode}': '${bootstrap_tarball_compression[0]}' is not a supported compression method!" 0 + ;; + esac + fi } _validate_common_requirements_buildmode_iso_netboot() { @@ -1632,6 +1659,25 @@ _add_xorrisofs_options_uefi-x64.grub.eltorito() { # Build bootstrap image _build_bootstrap_image() { + local tarball_ext + + # Set default tarball compression to uncompressed + if (( ! "${#bootstrap_tarball_compression[@]}" )); then + bootstrap_tarball_compression=('cat') + fi + + # Set tarball extension + case "${bootstrap_tarball_compression[0]}" in + 'cat') tarball_ext='' ;; + 'bzip') tarball_ext='.b2z' ;; + 'gzip') tarball_ext='.gz' ;; + 'lrzip') tarball_ext='.lrz' ;; + 'lzip') tarball_ext='.lz' ;; + 'lzop') tarball_ext='.lzo' ;; + 'zstd'|'zstdmt') tarball_ext='.zst' ;; + *) _msg_error 'Unsupported compression!' 1 ;; + esac + local _bootstrap_parent _bootstrap_parent="$(dirname -- "${pacstrap_dir}")" @@ -1640,9 +1686,10 @@ _build_bootstrap_image() { cd -- "${_bootstrap_parent}" _msg_info "Creating bootstrap image..." - bsdtar -cf - "root.${arch}" | gzip -cn9 >"${out_dir}/${image_name}" + rm -f -- "${out_dir:?}/${image_name:?}${tarball_ext}" + bsdtar -cf - "root.${arch}" | "${bootstrap_tarball_compression[@]}" >"${out_dir}/${image_name}${tarball_ext}" _msg_info "Done!" - du -h -- "${out_dir}/${image_name}" + du -h -- "${out_dir}/${image_name}${tarball_ext}" cd -- "${OLDPWD}" } @@ -1945,7 +1992,7 @@ _build_iso_base() { # Build the bootstrap buildmode _build_buildmode_bootstrap() { - local image_name="${iso_name}-bootstrap-${iso_version}-${arch}.tar.gz" + local image_name="${iso_name}-bootstrap-${iso_version}-${arch}.tar" local run_once_mode="${buildmode}" local buildmode_packages="${bootstrap_packages}" # Set the package list to use diff --git a/docs/README.profile.rst b/docs/README.profile.rst index 5a0c0bd..d1f6bc3 100644 --- a/docs/README.profile.rst +++ b/docs/README.profile.rst @@ -66,6 +66,8 @@ The image file is constructed from some of the variables in ``profiledef.sh``: ` - ``erofs``: Create an EROFS image for the airootfs work directory * ``airootfs_image_tool_options``: An array of options to pass to the tool to create the airootfs image. ``mksquashfs`` and ``mkfs.erofs`` are supported. See ``mksquashfs --help`` or ``mkfs.erofs --help`` for all possible options +* ``bootstrap_tarball_compression``: An array containing the compression program and arguments passed to it for + compressing the bootstrap tarball (defaults to ``cat``). For example: ``bootstrap_tarball_compression=(zstd -c -T0 --long -19)``. * ``file_permissions``: An associative array that lists files and/or directories who need specific ownership or permissions. The array's keys contain the path and the value is a colon separated list of owner UID, owner GID and access mode. E.g. ``file_permissions=(["/etc/shadow"]="0:0:400")``. When directories are listed with a trailing backslash (``/``) **all** files and directories contained within the listed directory will have the same owner UID, owner GID, and access mode applied recursively.