diff --git a/installkernel b/installkernel index ce65c72..4b3125f 100755 --- a/installkernel +++ b/installkernel @@ -134,6 +134,22 @@ dropindirs_sort() { done } +# Used to find drop-in files for install.conf +dropinconfs_sort() { + for d; do + for i in "${d}/"*.conf; do + [ -e "${i}" ] && echo "${i##*/}" + done + done | sort -Vu | while read -r f; do + for d; do + if [ -e "${d}/${f}" ]; then + echo "${d}/${f}" + continue 2 + fi + done + done +} + # Create backups of older versions before installing updatever() { oldsuffix="${3}.old" @@ -440,7 +456,10 @@ main() { return 0 } -# Find and read the install.conf +# Read configuration +has_read_conf=0 + +# First find and read the install.conf if [ -n "${INSTALLKERNEL_CONF_ROOT}" ]; then install_conf="${INSTALLKERNEL_CONF_ROOT}/install.conf" elif [ -f /etc/kernel/install.conf ]; then @@ -461,42 +480,72 @@ if [ -f "${install_conf}" ]; then fi # shellcheck source=/dev/null . "${install_conf}" + has_read_conf=1 +else + if [ "${INSTALLKERNEL_VERBOSE}" -gt 0 ]; then + echo "No install.conf found at ${install_conf}" + fi +fi - if [ -n "${layout}" ]; then - if [ "${INSTALLKERNEL_VERBOSE}" -gt 0 ]; then - echo "${install_conf} configures layout=${layout}" - fi - if [ -z "${INSTALLKERNEL_LAYOUT}" ]; then - INSTALLKERNEL_LAYOUT="${layout}" - fi - else - echo "No layout= configured by ${install_conf}" - exit 1 +# Read drop-in files for install.conf +if [ -n "${INSTALLKERNEL_CONF_ROOT}" ]; then + # Don't read drop-ins in other directories; + # this behavior is consistent with kernel-install + dropins="$(dropinconfs_sort "${INSTALLKERNEL_CONF_ROOT}/install.conf.d")" +else + dropins="$( + dropinconfs_sort \ + "/etc/kernel/install.conf.d" \ + "/run/kernel/install.conf.d" \ + "/usr/local/lib/kernel/install.conf.d" \ + "/usr/lib/kernel/install.conf.d" + )" +fi +for dropin in ${dropins}; do + if [ "${INSTALLKERNEL_VERBOSE}" -gt 0 ]; then + echo "Reading drop-in file ${dropin}..." fi - if [ -n "${initrd_generator}" ]; then - if [ "${INSTALLKERNEL_VERBOSE}" -gt 0 ]; then - echo "${install_conf} configures initrd_generator=${initrd_generator}" - fi - if [ -z "${INSTALLKERNEL_INITRD_GENERATOR}" ]; then - INSTALLKERNEL_INITRD_GENERATOR="${initrd_generator}" - fi - else - echo "No initrd_generator= configured by ${install_conf}" - exit 1 + # shellcheck source=/dev/null + . "${dropin}" + has_read_conf=1 +done + +if [ ${has_read_conf} -ne 1 ]; then + echo "No install.conf found at ${install_conf}, and no drop-in file found" + exit 1 +fi + +if [ -n "${layout}" ]; then + if [ "${INSTALLKERNEL_VERBOSE}" -gt 0 ]; then + echo "Read configuration layout=${layout}" fi - if [ -n "${uki_generator}" ]; then - if [ "${INSTALLKERNEL_VERBOSE}" -gt 0 ]; then - echo "${install_conf} configures uki_generator=${uki_generator}" - fi - if [ -z "${INSTALLKERNEL_UKI_GENERATOR}" ]; then - INSTALLKERNEL_UKI_GENERATOR="${uki_generator}" - fi - else - echo "No uki_generator= configured by ${install_conf}" - exit 1 + if [ -z "${INSTALLKERNEL_LAYOUT}" ]; then + INSTALLKERNEL_LAYOUT="${layout}" + fi +else + echo "No layout= configured by ${install_conf}" + exit 1 +fi +if [ -n "${initrd_generator}" ]; then + if [ "${INSTALLKERNEL_VERBOSE}" -gt 0 ]; then + echo "Read configuration initrd_generator=${initrd_generator}" + fi + if [ -z "${INSTALLKERNEL_INITRD_GENERATOR}" ]; then + INSTALLKERNEL_INITRD_GENERATOR="${initrd_generator}" + fi +else + echo "No initrd_generator= configured by ${install_conf}" + exit 1 +fi +if [ -n "${uki_generator}" ]; then + if [ "${INSTALLKERNEL_VERBOSE}" -gt 0 ]; then + echo "Read configuration uki_generator=${uki_generator}" + fi + if [ -z "${INSTALLKERNEL_UKI_GENERATOR}" ]; then + INSTALLKERNEL_UKI_GENERATOR="${uki_generator}" fi else - echo "No install.conf found at ${install_conf}" + echo "No uki_generator= configured by ${install_conf}" exit 1 fi diff --git a/installkernel.8 b/installkernel.8 index b8b75da..cf03e5b 100644 --- a/installkernel.8 +++ b/installkernel.8 @@ -138,3 +138,21 @@ INSTALLKERNEL_UKI_GENERATOR respectively. If the environment variable .B INSTALLKERNEL_CONF_ROOT is set, then the install.conf at this location is used instead. +.P +Drop-in files may also be used to partially override the settings. The syntax +for drop-in files is the same as that for install.conf. However, a drop-in file +need not define all these settings; it just needs to define settings that +override install.conf. Each drop-in file should have filename suffix ".conf". +.P +Drop-in files should be placed in one of these directories +.IR /etc/kernel/install.conf.d/ +.IR /run/kernel/install.conf.d/ +.IR /usr/local/lib/kernel/install.conf.d/ +.IR /usr/lib/kernel/install.conf.d/. +Drop-in files in directories listed earlier override files with the same name +in directories listed later. Multiple drop-in files with different names are +applied in lexicographic order, regardless of which directory they reside in. +If the environment variable +.B INSTALLKERNEL_CONF_ROOT +is set, then the install.conf.d directory at this location is used instead, and +no other directory is used.