From 2f6f116d550a49d4239b0aecbaf4562ef922bab9 Mon Sep 17 00:00:00 2001 From: David P Date: Tue, 2 Feb 2021 00:59:26 -0300 Subject: sync with archiso Imported changes: f0ef2f3 (HEAD -> master, tag: v51, origin/master, origin/HEAD) Add changelog file b588c52 build-host.sh: Style and syntax fixes 428bf47 Add build stage for continuous integration 2a24429 Add continuous integration scripts to linting 0723949 Add scripts for continuous integration f9a7b20 configs/releng: move locale-gen from customize_airootfs.sh to a pacman hook a46c740 config/releng: remove pacman hooks specific to ISO build process from airootfs after they run 767c095 Update my email in AUTHORS dd51457 rm un-used set_image() dupe of check_image() in run_archiso.sh 23c5d52 add vorburger to AUTHORS.rst 0f20a11 Support setting more variables in profiledef.sh and rework the way overrides are applied e7306a3 add cloud-init to baseline 744b8f1 make baseline have working ethernet networking, like releng 94dd194 add SSH server to baseline 221a921 use same airootfs_image_tool_options in baseline as in releng 4f4047a configs/releng: move the mirror uncommenting sed command from customize_airootfs.sh to a pacman hook a2c8dd3 archiso_pxe_common: remove resolv.conf before copy b30d1ca mkarchiso: add version information Signed-off-by: David P --- parabolaiso/mkparabolaiso | 272 ++++++++++++++++++++++++++++------------------ 1 file changed, 165 insertions(+), 107 deletions(-) (limited to 'parabolaiso/mkparabolaiso') diff --git a/parabolaiso/mkparabolaiso b/parabolaiso/mkparabolaiso index a3bb49b..1bb0887 100755 --- a/parabolaiso/mkparabolaiso +++ b/parabolaiso/mkparabolaiso @@ -9,34 +9,29 @@ umask 0022 export LANG="C" export SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-"$(date +%s)"}" -# mkparabolaiso defaults +# Set application name from the script's file name app_name="${0##*/}" + +# Define global variables. All of them will be overwritten later pkg_list=() -quiet="y" -work_dir="work" -out_dir="out" -img_name="${app_name}.iso" +quiet="" +work_dir="" +out_dir="" +img_name="" gpg_key="" -override_gpg_key="" - -# profile defaults -profile="" -iso_name="${app_name}" -iso_label="${app_name^^}" -override_iso_label="" -iso_publisher="${app_name}" -override_iso_publisher="" -iso_application="${app_name} iso" -override_iso_application="" +iso_name="" +iso_label="" +iso_publisher="" +iso_application="" iso_version="" -install_dir="${app_name}" -override_install_dir="" -arch="$(uname -m)" -pacman_conf="/etc/pacman.conf" -override_pacman_conf="" +install_dir="" +arch="" +pacman_conf="" +packages="" +packages_dual="" bootmodes=() -airootfs_image_type="squashfs" -airootfs_image_tool_options=('-comp' 'xz') +airootfs_image_type="" +airootfs_image_tool_options=() declare -A file_permissions=() @@ -103,7 +98,8 @@ usage: ${app_name} [options] -h This message -o Set the output directory Default: '${out_dir}' - -p PACKAGE(S) Package(s) to install, can be used multiple times + -p PACKAGE(S) Package(s) to install. + Multiple packages are provided as quoted, space delimited list. -v Enable verbose output -w Set the working directory Default: '${work_dir}' @@ -164,6 +160,11 @@ _cleanup_airootfs() { } _run_mksquashfs() { + # Set default mksquashfs options + if (( ${#airootfs_image_tool_options[@]} < 1 )); then + airootfs_image_tool_options=('-comp' 'xz') + fi + local image_path="${isofs_dir}/${install_dir}/${arch}/airootfs.sfs" if [[ "${quiet}" == "y" ]]; then mksquashfs "$@" "${image_path}" -noappend "${airootfs_image_tool_options[@]}" -no-progress > /dev/null @@ -288,7 +289,7 @@ _make_custom_airootfs() { for filename in "${!file_permissions[@]}"; do IFS=':' read -ra permissions <<< "${file_permissions["${filename}"]}" # Prevent file path traversal outside of $airootfs_dir - if [[ "$(realpath -q -- "${airootfs_dir}${filename}")" != "$(realpath -q -- "${airootfs_dir}")"* ]]; then + if [[ "$(realpath -q -- "${airootfs_dir}${filename}")" != "${airootfs_dir}"* ]]; then _msg_error "Failed to set permissions on '${airootfs_dir}${filename}'. Outside of valid path." 1 # Warn if the file does not exist elif [[ ! -e "${airootfs_dir}${filename}" ]]; then @@ -333,7 +334,7 @@ _make_customize_airootfs() { local passwd=() if [[ -e "${profile}/airootfs/etc/passwd" ]]; then - _msg_info "Copying /etc/skel/* to user homes..." + _msg_info "Copying /etc/skel/* to ${arch} user homes..." while IFS=':' read -a passwd -r; do # Only operate on UIDs in range 1000–59999 (( passwd[2] >= 1000 && passwd[2] < 60000 )) || continue @@ -919,10 +920,6 @@ _build_iso() { # Read profile's values from profiledef.sh _read_profile() { - local validation_error=0 - local bootmode - - _msg_info "Reading profile..." if [[ -z "${profile}" ]]; then _msg_error "No profile specified!" 1 fi @@ -937,102 +934,166 @@ _read_profile() { # shellcheck source=configs/releng/profiledef.sh . "${profile}/profiledef.sh" - # Resolve paths + # Resolve paths of files that are expected to reside in the profile's directory if [[ "${arch}" == "dual" ]]; then - packages_dual="$(realpath -- "${profile}"/packages.{both,i686,x86_64})" - pacman_conf="$(realpath -- "${pacman_conf}")" + [[ -n "$packages_dual" ]] || packages_dual=("${profile}/packages."{both,i686,x86_64}) + # shellcheck disable=SC2178 + packages_dual="$(realpath -- "${packages_dual[@]}")" else - packages="$(realpath -- "${profile}/packages.${arch}")" - pacman_conf="$(realpath -- "${pacman_conf}")" + [[ -n "$packages" ]] || packages="${profile}/packages.${arch}" + packages="$(realpath -- "${packages}")" fi + pacman_conf="$(realpath -- "${pacman_conf}")" cd -- "${OLDPWD}" + fi +} - # Validate profile - # Check if the package list file exists and read packages from it - if [[ "${arch}" == "dual" ]]; then - for packages in ${packages_dual}; do - if [[ "${packages##*/}" = "packages.both" ]]; then - if [[ -e "${packages}" ]]; then - mapfile -t pkg_list < <(sed '/^[[:blank:]]*#.*/d;s/#.*//;/^[[:blank:]]*$/d' "${packages}") - if (( ${#pkg_list} < 1 )); then - (( validation_error=validation_error+1 )) - _msg_error "No package specified in '${packages}'." 0 - fi - else +# Validate set options +_validate_options() { + local validation_error=0 bootmode + local pkg_list_from_file=() + _msg_info "Validating options..." + # Check if the package list file exists and read packages from it + if [[ "${arch}" == "dual" ]]; then + # shellcheck disable=SC2128 + for packages in ${packages_dual}; do + if [[ "${packages##*/}" = "packages.both" ]]; then + if [[ -e "${packages}" ]]; then + mapfile -t pkg_list_from_file < <(sed '/^[[:blank:]]*#.*/d;s/#.*//;/^[[:blank:]]*$/d' "${packages}") + pkg_list+=("${pkg_list_from_file[@]}") + if (( ${#pkg_list_from_file} < 1 )); then (( validation_error=validation_error+1 )) - _msg_error "File '${packages}' does not exist." 0 + _msg_error "No package specified in '${packages}'." 0 fi - elif [[ -e "${packages}" ]]; then - mapfile -t "pkg_list_${packages##*.}" < <(sed '/^[[:blank:]]*#.*/d;s/#.*//;/^[[:blank:]]*$/d' "${packages}") - fi - done - else - if [[ -e "${packages}" ]]; then - mapfile -t pkg_list < <(sed '/^[[:blank:]]*#.*/d;s/#.*//;/^[[:blank:]]*$/d' "${packages}") - if (( ${#pkg_list} < 1 )); then + else (( validation_error=validation_error+1 )) - _msg_error "No package specified in '${packages}'." 0 + _msg_error "File '${packages}' does not exist." 0 fi - else + elif [[ -e "${packages}" ]]; then + mapfile -t "pkg_list_from_file_${packages##*.}" < <(sed '/^[[:blank:]]*#.*/d;s/#.*//;/^[[:blank:]]*$/d' "${packages}") + eval "pkg_list_${packages##*.}+=(\${pkg_list_from_file_${packages##*.}[@]})" + fi + done + else + if [[ -e "${packages}" ]]; then + mapfile -t pkg_list_from_file < <(sed '/^[[:blank:]]*#.*/d;s/#.*//;/^[[:blank:]]*$/d' "${packages}") + pkg_list+=("${pkg_list_from_file[@]}") + if (( ${#pkg_list_from_file} < 1 )); then (( validation_error=validation_error+1 )) - _msg_error "File '${packages}' does not exist." 0 + _msg_error "No package specified in '${packages}'." 0 fi - fi - # Check if pacman configuration file exists - if [[ ! -e "${pacman_conf}" ]]; then + else (( validation_error=validation_error+1 )) - _msg_error "File '${pacman_conf}' does not exist." 0 + _msg_error "File '${packages}' does not exist." 0 + fi - # Check if the specified bootmodes are supported - for bootmode in "${bootmodes[@]}"; do - if typeset -f "_make_bootmode_${bootmode}" &> /dev/null; then - if typeset -f "_validate_requirements_bootmode_${bootmode}" &> /dev/null; then - "_validate_requirements_bootmode_${bootmode}" - else - _msg_warning "Function '_validate_requirements_bootmode_${bootmode}' does not exist. Validating the requirements of '${bootmode}' boot mode will not be possible." - fi - else - (( validation_error=validation_error+1 )) - _msg_error "${bootmode} is not a valid boot mode!" 0 - fi - done - # Check if the specified airootfs_image_type is supported - if typeset -f "_mkairootfs_${airootfs_image_type}" &> /dev/null; then - if typeset -f "_validate_requirements_airootfs_image_type_${airootfs_image_type}" &> /dev/null; then - "_validate_requirements_airootfs_image_type_${airootfs_image_type}" + fi + + # Check if pacman configuration file exists + if [[ ! -e "${pacman_conf}" ]]; then + (( validation_error=validation_error+1 )) + _msg_error "File '${pacman_conf}' does not exist." 0 + fi + # Check if the specified bootmodes are supported + for bootmode in "${bootmodes[@]}"; do + if typeset -f "_make_bootmode_${bootmode}" &> /dev/null; then + if typeset -f "_validate_requirements_bootmode_${bootmode}" &> /dev/null; then + "_validate_requirements_bootmode_${bootmode}" else - _msg_warning "Function '_validate_requirements_airootfs_image_type_${airootfs_image_type}' does not exist. Validating the requirements of '${airootfs_image_type}' airootfs image type will not be possible." + _msg_warning "Function '_validate_requirements_bootmode_${bootmode}' does not exist. Validating the requirements of '${bootmode}' boot mode will not be possible." fi else (( validation_error=validation_error+1 )) - _msg_error "Unsupported image type: '${airootfs_image_type}'" 0 + _msg_error "${bootmode} is not a valid boot mode!" 0 fi - if (( validation_error )); then - _msg_error "${validation_error} errors were encountered while validating the profile. Aborting." 1 + done + # Check if the specified airootfs_image_type is supported + if typeset -f "_mkairootfs_${airootfs_image_type}" &> /dev/null; then + if typeset -f "_validate_requirements_airootfs_image_type_${airootfs_image_type}" &> /dev/null; then + "_validate_requirements_airootfs_image_type_${airootfs_image_type}" + else + _msg_warning "Function '_validate_requirements_airootfs_image_type_${airootfs_image_type}' does not exist. Validating the requirements of '${airootfs_image_type}' airootfs image type will not be possible." fi + else + (( validation_error=validation_error+1 )) + _msg_error "Unsupported image type: '${airootfs_image_type}'" 0 + fi + if (( validation_error )); then + _msg_error "${validation_error} errors were encountered while validating the profile. Aborting." 1 fi _msg_info "Done!" } -# set overrides from mkparabolaiso option parameters, if present +# Set defaults and, if present, overrides from mkparabolaiso command line option parameters _set_overrides() { - _msg_info "Setting overrides..." - [[ -n "$override_iso_label" ]] && iso_label="$override_iso_label" - [[ -n "$override_iso_publisher" ]] && iso_publisher="$override_iso_publisher" - [[ -n "$override_iso_application" ]] && iso_application="$override_iso_application" - [[ -n "$override_install_dir" ]] && install_dir="$override_install_dir" - [[ -n "$override_pacman_conf" ]] && pacman_conf="$override_pacman_conf" - [[ -n "$override_gpg_key" ]] && gpg_key="$override_gpg_key" - # NOTE: the call to _msg_info() conveniently guards this function from evaluating to false - _msg_info "Done!" -} + # Set variables that have command line overrides + if [[ -v override_work_dir ]]; then + work_dir="$override_work_dir" + elif [[ -z "$work_dir" ]]; then + work_dir='./work' + fi + work_dir="$(realpath -- "$work_dir")" + if [[ -v override_out_dir ]]; then + out_dir="$override_out_dir" + elif [[ -z "$out_dir" ]]; then + out_dir='./out' + fi + out_dir="$(realpath -- "$out_dir")" + if [[ -v override_pacman_conf ]]; then + pacman_conf="$override_pacman_conf" + elif [[ -z "$pacman_conf" ]]; then + pacman_conf="/etc/pacman.conf" + fi + pacman_conf="$(realpath -- "$pacman_conf")" + [[ ! -v override_pkg_list ]] || pkg_list+=("${override_pkg_list[@]}") + if [[ -v override_iso_label ]]; then + iso_label="$override_iso_label" + elif [[ -z "$iso_label" ]]; then + iso_label="${app_name^^}" + fi + if [[ -v override_iso_publisher ]]; then + iso_publisher="$override_iso_publisher" + elif [[ -z "$iso_publisher" ]]; then + iso_publisher="${app_name}" + fi + if [[ -v override_iso_application ]]; then + iso_application="$override_iso_application" + elif [[ -z "$iso_application" ]]; then + iso_application="${app_name} iso" + fi + if [[ -v override_install_dir ]]; then + install_dir="$override_install_dir" + elif [[ -z "$install_dir" ]]; then + install_dir="${app_name}" + fi + [[ ! -v override_gpg_key ]] || gpg_key="$override_gpg_key" + if [[ -v override_quiet ]]; then + quiet="$override_quiet" + elif [[ -z "$quiet" ]]; then + quiet="y" + fi + # Set variables that do not have overrides + [[ -n "$arch" ]] || arch="$(uname -m)" + [[ -n "$airootfs_image_type" ]] || airootfs_image_type="squashfs" + [[ -n "$iso_name" ]] || iso_name="${app_name}" + [[ -n "$img_name" ]] || img_name="${iso_name}-${iso_version}-${arch}.iso" +} _export_gpg_publickey() { gpg --batch --output "${work_dir}/pubkey.gpg" --export "${gpg_key}" } +_make_version() { + install -d -m 0755 -- "${isofs_dir}/${install_dir}" + _msg_info "Creating ${arch} files with iso version..." + printf '%s\n' "${iso_version}" > "${airootfs_dir}/version" + printf '%s\n' "${iso_version}" > "${isofs_dir}/${install_dir}/version" + printf '%.1024s' "$(printf '# GRUB Environment Block\nVERSION=%s\n%s' "${iso_version}" \ + "$(printf '%0.1s' "#"{1..1024})")" > "${isofs_dir}/${install_dir}/grubenv" + _msg_info "Done!" +} _make_pkglist() { install -d -m 0755 -- "${isofs_dir}/${install_dir}" @@ -1045,8 +1106,6 @@ _build_profile() { # Set up essential directory paths airootfs_dir="${work_dir}/${arch}/airootfs" isofs_dir="${work_dir}/iso" - # Set ISO file name - img_name="${iso_name}-${iso_version}-${arch}.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 @@ -1056,11 +1115,12 @@ _build_profile() { printf '%s\n' "$SOURCE_DATE_EPOCH" > "${work_dir}/build_date" fi - [[ "${quiet}" == "n" ]] && _show_config + [[ "${quiet}" == "y" ]] || _show_config _run_dual '_run_once _make_pacman_conf' - [[ -n "${gpg_key}" ]] && _run_once _export_gpg_publickey + [[ -z "${gpg_key}" ]] || _run_once _export_gpg_publickey _run_dual '_run_once _make_custom_airootfs' \ '_run_once _make_packages' + _run_dual '_run_once _make_version' _run_dual '_run_once _make_customize_airootfs' _run_dual '_run_once _make_pkglist' _make_bootmodes @@ -1071,19 +1131,16 @@ _build_profile() { while getopts 'p:C:L:P:A:D:w:o:g:vh?' arg; do case "${arg}" in - p) - read -r -a opt_pkg_list <<< "${OPTARG}" - pkg_list+=("${opt_pkg_list[@]}") - ;; - C) override_pacman_conf="$(realpath -- "${OPTARG}")" ;; + p) read -r -a override_pkg_list <<< "${OPTARG}" ;; + C) override_pacman_conf="${OPTARG}" ;; L) override_iso_label="${OPTARG}" ;; P) override_iso_publisher="${OPTARG}" ;; A) override_iso_application="${OPTARG}" ;; D) override_install_dir="${OPTARG}" ;; - w) work_dir="$(realpath -- "${OPTARG}")" ;; - o) out_dir="$(realpath -- "${OPTARG}")" ;; + w) override_work_dir="${OPTARG}" ;; + o) override_out_dir="${OPTARG}" ;; g) override_gpg_key="${OPTARG}" ;; - v) quiet="n" ;; + v) override_quiet="n" ;; h|?) _usage 0 ;; *) _msg_error "Invalid argument '${arg}'" 0 @@ -1108,6 +1165,7 @@ profile="$(realpath -- "${1}")" _read_profile _set_overrides +_validate_options _build_profile # vim:ts=4:sw=4:et: -- cgit v1.2.2