[arch-projects] [mkinitcpio][PATCH 00/12] RIP gen_init_cpio
Hi! I'm flooding your mailboxes again. There's been some changes, so I'm resubmitting the stuff I'm happy with (and need to stop refactoring). The latest is always available on github, but I'll do my best to keep these 12 frozen unless I find a showstopper. Major patches to note are: 2/12: deprecates install, changes every install hook to have a 'build' function instead. 8/12: kills gen_init_cpio. it's a bit of a scary large patch. 12/12: allows specifying a kernel as a path, e.g. /boot/vmlinuz26. This one is, imo, important to have before linux 3.0 is released. Patches 5 and 9 are refactors of some of the install hook API which yield some tasty speedups beyond what patch 8 offers. The rest is assorted cleanup and bashification. Also, there's still more to come, but I'll hold off until this gets digested. d functions | 290 ++++++++++++++++++++----------------------- hooks/dmesg | 5 - install/autodetect | 2 +- install/base | 7 +- install/btrfs | 2 +- install/consolefont | 2 +- install/dmesg | 18 --- install/dsdt | 2 +- install/filesystems | 2 +- install/fw | 2 +- install/ide | 2 +- install/keymap | 2 +- install/memdisk | 2 +- install/net | 2 +- install/pata | 2 +- install/pcmcia | 2 +- install/resume | 3 +- install/sata | 2 +- install/scsi | 2 +- install/sleep | 2 +- install/udev | 2 +- install/usb | 2 +- install/usbinput | 2 +- mkinitcpio | 134 +++++++++++++-------- mkinitcpio.5.txt | 7 +- mkinitcpio.conf | 9 +- mkinitcpio.d/example.preset | 2 +- 27 files changed, 246 insertions(+), 265 deletions(-)
'raid' is the old deprecated hook name, which no longer exists. mdadm is the proper name. Signed-off-by: Dave Reisner <d@falconindy.com> --- mkinitcpio.conf | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mkinitcpio.conf b/mkinitcpio.conf index 52abd56..ce0a077 100644 --- a/mkinitcpio.conf +++ b/mkinitcpio.conf @@ -48,9 +48,9 @@ FILES="" ## No autodetection is done. # HOOKS="base udev pata scsi sata usb filesystems" # -## This setup assembles a pata raid array with an encrypted root FS. -## Note: See 'mkinitcpio -H raid' for more information on raid devices. -# HOOKS="base udev pata raid encrypt filesystems" +## This setup assembles a pata mdadm array with an encrypted root FS. +## Note: See 'mkinitcpio -H mdadm' for more information on raid devices. +# HOOKS="base udev pata mdadm encrypt filesystems" # ## This setup loads an lvm2 volume group on a usb device. # HOOKS="base udev usb lvm2 filesystems" -- 1.7.5.4
This is an unfortunate name clash with a common utility and should be avoided. Rename the install function to 'build' and warn the user when we discover a hook using an 'install' function. Signed-off-by: Dave Reisner <d@falconindy.com> --- install/autodetect | 2 +- install/base | 2 +- install/btrfs | 2 +- install/consolefont | 2 +- install/dmesg | 5 +++-- install/dsdt | 2 +- install/filesystems | 2 +- install/fw | 2 +- install/ide | 2 +- install/keymap | 2 +- install/memdisk | 2 +- install/net | 2 +- install/pata | 2 +- install/pcmcia | 2 +- install/resume | 3 ++- install/sata | 2 +- install/scsi | 2 +- install/sleep | 2 +- install/udev | 2 +- install/usb | 2 +- install/usbinput | 2 +- mkinitcpio | 21 +++++++++++++-------- 22 files changed, 37 insertions(+), 30 deletions(-) diff --git a/install/autodetect b/install/autodetect index 70fac56..118c9a5 100644 --- a/install/autodetect +++ b/install/autodetect @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULE_FILE="${TMPDIR}/autodetect_modules" #blegh, we'll let /tmp clean itself up diff --git a/install/base b/install/base index 4a0ff14..87d789d 100644 --- a/install/base +++ b/install/base @@ -1,6 +1,6 @@ # vim:set ft=sh: -install () +build() { add_dir "/proc" add_dir "/sys" diff --git a/install/btrfs b/install/btrfs index 60dc2ac..c156bb0 100644 --- a/install/btrfs +++ b/install/btrfs @@ -1,6 +1,6 @@ # vim:set ft=sh: -install() +build() { MODULES="$(all_modules btrfs)" BINARIES="/sbin/btrfs" diff --git a/install/consolefont b/install/consolefont index 7a3e73f..395387b 100644 --- a/install/consolefont +++ b/install/consolefont @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES="" BINARIES="" diff --git a/install/dmesg b/install/dmesg index d25deba..9482874 100644 --- a/install/dmesg +++ b/install/dmesg @@ -1,5 +1,6 @@ # vim: set ft=sh: -install () + +build() { MODULES="" BINARIES="" @@ -15,4 +16,4 @@ cat<<HELPEOF with the boot process during early userspace (like when entering a passphrase). HELPEOF -} \ No newline at end of file +} diff --git a/install/dsdt b/install/dsdt index 138ee47..f1345d0 100644 --- a/install/dsdt +++ b/install/dsdt @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES="" BINARIES="" diff --git a/install/filesystems b/install/filesystems index cd1a4cb..337a6a5 100644 --- a/install/filesystems +++ b/install/filesystems @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { if [ "${autodetect_fs_detection_failed}" = "1" ]; then MODULES=" $(all_modules '/kernel/fs' | grep -v "nls")" diff --git a/install/fw b/install/fw index 9f4ed26..a5a77cb 100644 --- a/install/fw +++ b/install/fw @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES=" $(checked_modules "/firewire/") " diff --git a/install/ide b/install/ide index f3bee4e..fa0da51 100644 --- a/install/ide +++ b/install/ide @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES=" $(checked_modules "/ide/" | grep -v "legacy") "; diff --git a/install/keymap b/install/keymap index 65990dd..4038c87 100644 --- a/install/keymap +++ b/install/keymap @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES="" BINARIES="" diff --git a/install/memdisk b/install/memdisk index d2a844d..69c996f 100644 --- a/install/memdisk +++ b/install/memdisk @@ -1,6 +1,6 @@ # vim:set ft=sh: -install () +build() { MODULES="phram mtdblock" BINARIES="/usr/bin/memdiskfind" diff --git a/install/net b/install/net index 6016ed5..2c816ba 100644 --- a/install/net +++ b/install/net @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES="nfs $(checked_modules "/drivers/net/") " diff --git a/install/pata b/install/pata index af3c106..1d750dc 100644 --- a/install/pata +++ b/install/pata @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES=" $(checked_modules "ata/pata_*") $(checked_modules "ata/ata_generic") $(checked_modules "ata/ata_piix")" diff --git a/install/pcmcia b/install/pcmcia index 8b685c5..a9920c1 100644 --- a/install/pcmcia +++ b/install/pcmcia @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES=" $(checked_modules '/pcmcia/' | grep -ve 'sound' -e 'net') $(checked_modules '/ide/legacy')" MODULES=$(echo ${MODULES}) #trim whitespace diff --git a/install/resume b/install/resume index cbef453..dcf6442 100644 --- a/install/resume +++ b/install/resume @@ -1,5 +1,6 @@ # vim:set ft=sh: -install () + +build() { MODULES="" BINARIES="" diff --git a/install/sata b/install/sata index 4ed4d1c..cbd2db2 100644 --- a/install/sata +++ b/install/sata @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES=" $(checked_modules "scsi/.*ata") $(checked_modules "block/sx8") $(checked_modules "scsi/ahci") $(checked_modules "scsi/pdc_adma") diff --git a/install/scsi b/install/scsi index b831b64..9a97a8c 100644 --- a/install/scsi +++ b/install/scsi @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES=" $(checked_modules "/scsi/" | grep -ve "imm" -e "pdc_adma" -e "ahci" -e "ata" -e "pcmcia" -e "ide") $(checked_modules "/block/" | grep -e "cciss" -e "cpqarray" -e "DAC960") diff --git a/install/sleep b/install/sleep index a59d0c3..c7a8902 100644 --- a/install/sleep +++ b/install/sleep @@ -1,6 +1,6 @@ # vim:set ft=sh: -install () +build() { MODULES="" BINARIES="" diff --git a/install/udev b/install/udev index 33a13cc..74c9b5e 100644 --- a/install/udev +++ b/install/udev @@ -1,6 +1,6 @@ # vim:set ft=sh: -install () +build() { MODULES="" BINARIES="" diff --git a/install/usb b/install/usb index 605912c..620f695 100644 --- a/install/usb +++ b/install/usb @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES=" $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811-hcd" -e "isp116x-hcd")" diff --git a/install/usbinput b/install/usbinput index 0d293ae..a90cd15 100644 --- a/install/usbinput +++ b/install/usbinput @@ -1,6 +1,6 @@ # vim: set ft=sh: -install () +build() { MODULES=" $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811-hcd" -e "isp116x-hcd") " MODULES=" $(echo ${MODULES}) $(all_modules "/hid/hid-") " diff --git a/mkinitcpio b/mkinitcpio index c6428bb..fc50396 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -239,10 +239,8 @@ parse_hook for hook in ${HOOKS}; do in_array ${hook} ${SKIPHOOKS[@]} && continue - unset MODULES - unset BINARIES - unset FILES - install () { msg "${hook}: no install function..."; } + unset MODULES BINARIES FILES + build () { msg "${hook}: no build function..."; } # Deprecation check # A hook is considered deprecated if it is a symlink # within $INSTDIR. @@ -257,10 +255,19 @@ for hook in ${HOOKS}; do hook="${newhook}" fi fi - if grep -q "install" "${INSTDIR}/${hook}"; then + if [[ -r "${INSTDIR}/${hook}" ]]; then . "${INSTDIR}/${hook}" echo ":: Parsing hook [${hook}]" - install + if [[ $(type -t install) = 'function' ]]; then + echo " -----------------------------------------------------------------------" + echo " WARNING: Hook '$hook' uses a deprecated 'install' function. This " + echo " should be switched to a 'build' function instead." + echo " -----------------------------------------------------------------------" + install + unset install + else + build + fi parse_hook else die "Hook '${hook}' can not be found." @@ -269,8 +276,6 @@ done if [ "${HAS_MODULES}" = "y" ]; then echo ":: Generating module dependencies" - # unfortuate name collision between a function and utility program - unset install for mod in $(grep "file /lib/modules/${KERNELVERSION}" ${FILELIST} | cut -d' ' -f2); do install -m 644 -D "${BASEDIR}${mod}" "${TMPDIR}${mod}" done -- 1.7.5.4
On Thu, Jun 09, 2011 at 04:09:56PM -0400, Dave Reisner wrote:
This is an unfortunate name clash with a common utility and should be avoided. Rename the install function to 'build' and warn the user when we discover a hook using an 'install' function.
Signed-off-by: Dave Reisner <d@falconindy.com> --- install/autodetect | 2 +- install/base | 2 +- install/btrfs | 2 +- install/consolefont | 2 +- install/dmesg | 5 +++-- install/dsdt | 2 +- install/filesystems | 2 +- install/fw | 2 +- install/ide | 2 +- install/keymap | 2 +- install/memdisk | 2 +- install/net | 2 +- install/pata | 2 +- install/pcmcia | 2 +- install/resume | 3 ++- install/sata | 2 +- install/scsi | 2 +- install/sleep | 2 +- install/udev | 2 +- install/usb | 2 +- install/usbinput | 2 +- mkinitcpio | 21 +++++++++++++-------- 22 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/install/autodetect b/install/autodetect index 70fac56..118c9a5 100644 --- a/install/autodetect +++ b/install/autodetect @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULE_FILE="${TMPDIR}/autodetect_modules" #blegh, we'll let /tmp clean itself up diff --git a/install/base b/install/base index 4a0ff14..87d789d 100644 --- a/install/base +++ b/install/base @@ -1,6 +1,6 @@ # vim:set ft=sh:
-install () +build() { add_dir "/proc" add_dir "/sys" diff --git a/install/btrfs b/install/btrfs index 60dc2ac..c156bb0 100644 --- a/install/btrfs +++ b/install/btrfs @@ -1,6 +1,6 @@ # vim:set ft=sh:
-install() +build() { MODULES="$(all_modules btrfs)" BINARIES="/sbin/btrfs" diff --git a/install/consolefont b/install/consolefont index 7a3e73f..395387b 100644 --- a/install/consolefont +++ b/install/consolefont @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES="" BINARIES="" diff --git a/install/dmesg b/install/dmesg index d25deba..9482874 100644 --- a/install/dmesg +++ b/install/dmesg @@ -1,5 +1,6 @@ # vim: set ft=sh: -install () + +build() { MODULES="" BINARIES="" @@ -15,4 +16,4 @@ cat<<HELPEOF with the boot process during early userspace (like when entering a passphrase). HELPEOF -} \ No newline at end of file +} diff --git a/install/dsdt b/install/dsdt index 138ee47..f1345d0 100644 --- a/install/dsdt +++ b/install/dsdt @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES="" BINARIES="" diff --git a/install/filesystems b/install/filesystems index cd1a4cb..337a6a5 100644 --- a/install/filesystems +++ b/install/filesystems @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { if [ "${autodetect_fs_detection_failed}" = "1" ]; then MODULES=" $(all_modules '/kernel/fs' | grep -v "nls")" diff --git a/install/fw b/install/fw index 9f4ed26..a5a77cb 100644 --- a/install/fw +++ b/install/fw @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES=" $(checked_modules "/firewire/") "
diff --git a/install/ide b/install/ide index f3bee4e..fa0da51 100644 --- a/install/ide +++ b/install/ide @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES=" $(checked_modules "/ide/" | grep -v "legacy") ";
diff --git a/install/keymap b/install/keymap index 65990dd..4038c87 100644 --- a/install/keymap +++ b/install/keymap @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES="" BINARIES="" diff --git a/install/memdisk b/install/memdisk index d2a844d..69c996f 100644 --- a/install/memdisk +++ b/install/memdisk @@ -1,6 +1,6 @@ # vim:set ft=sh:
-install () +build() { MODULES="phram mtdblock" BINARIES="/usr/bin/memdiskfind" diff --git a/install/net b/install/net index 6016ed5..2c816ba 100644 --- a/install/net +++ b/install/net @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES="nfs $(checked_modules "/drivers/net/") "
diff --git a/install/pata b/install/pata index af3c106..1d750dc 100644 --- a/install/pata +++ b/install/pata @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES=" $(checked_modules "ata/pata_*") $(checked_modules "ata/ata_generic") $(checked_modules "ata/ata_piix")" diff --git a/install/pcmcia b/install/pcmcia index 8b685c5..a9920c1 100644 --- a/install/pcmcia +++ b/install/pcmcia @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES=" $(checked_modules '/pcmcia/' | grep -ve 'sound' -e 'net') $(checked_modules '/ide/legacy')" MODULES=$(echo ${MODULES}) #trim whitespace diff --git a/install/resume b/install/resume index cbef453..dcf6442 100644 --- a/install/resume +++ b/install/resume @@ -1,5 +1,6 @@ # vim:set ft=sh: -install () + +build() { MODULES="" BINARIES="" diff --git a/install/sata b/install/sata index 4ed4d1c..cbd2db2 100644 --- a/install/sata +++ b/install/sata @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES=" $(checked_modules "scsi/.*ata") $(checked_modules "block/sx8") $(checked_modules "scsi/ahci") $(checked_modules "scsi/pdc_adma") diff --git a/install/scsi b/install/scsi index b831b64..9a97a8c 100644 --- a/install/scsi +++ b/install/scsi @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES=" $(checked_modules "/scsi/" | grep -ve "imm" -e "pdc_adma" -e "ahci" -e "ata" -e "pcmcia" -e "ide") $(checked_modules "/block/" | grep -e "cciss" -e "cpqarray" -e "DAC960") diff --git a/install/sleep b/install/sleep index a59d0c3..c7a8902 100644 --- a/install/sleep +++ b/install/sleep @@ -1,6 +1,6 @@ # vim:set ft=sh:
-install () +build() { MODULES="" BINARIES="" diff --git a/install/udev b/install/udev index 33a13cc..74c9b5e 100644 --- a/install/udev +++ b/install/udev @@ -1,6 +1,6 @@ # vim:set ft=sh:
-install () +build() { MODULES="" BINARIES="" diff --git a/install/usb b/install/usb index 605912c..620f695 100644 --- a/install/usb +++ b/install/usb @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES=" $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811-hcd" -e "isp116x-hcd")"
diff --git a/install/usbinput b/install/usbinput index 0d293ae..a90cd15 100644 --- a/install/usbinput +++ b/install/usbinput @@ -1,6 +1,6 @@ # vim: set ft=sh:
-install () +build() { MODULES=" $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811-hcd" -e "isp116x-hcd") " MODULES=" $(echo ${MODULES}) $(all_modules "/hid/hid-") " diff --git a/mkinitcpio b/mkinitcpio index c6428bb..fc50396 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -239,10 +239,8 @@ parse_hook
for hook in ${HOOKS}; do in_array ${hook} ${SKIPHOOKS[@]} && continue - unset MODULES - unset BINARIES - unset FILES - install () { msg "${hook}: no install function..."; } + unset MODULES BINARIES FILES + build () { msg "${hook}: no build function..."; } # Deprecation check # A hook is considered deprecated if it is a symlink # within $INSTDIR. @@ -257,10 +255,19 @@ for hook in ${HOOKS}; do hook="${newhook}" fi fi - if grep -q "install" "${INSTDIR}/${hook}"; then + if [[ -r "${INSTDIR}/${hook}" ]]; then . "${INSTDIR}/${hook}" echo ":: Parsing hook [${hook}]" - install + if [[ $(type -t install) = 'function' ]]; then + echo " -----------------------------------------------------------------------" + echo " WARNING: Hook '$hook' uses a deprecated 'install' function. This " + echo " should be switched to a 'build' function instead." + echo " -----------------------------------------------------------------------" + install + unset install + else + build + fi parse_hook else die "Hook '${hook}' can not be found." @@ -269,8 +276,6 @@ done
if [ "${HAS_MODULES}" = "y" ]; then echo ":: Generating module dependencies" - # unfortuate name collision between a function and utility program - unset install for mod in $(grep "file /lib/modules/${KERNELVERSION}" ${FILELIST} | cut -d' ' -f2); do install -m 644 -D "${BASEDIR}${mod}" "${TMPDIR}${mod}" done -- 1.7.5.4
This is missing a 's/install/build/' in the SHOW_AUTOMODS block. Corrected in git. d
This should be set via the loglevel= parameter on the kernel cmdline. Signed-off-by: Dave Reisner <d@falconindy.com> --- hooks/dmesg | 5 ----- install/dmesg | 19 ------------------- 2 files changed, 0 insertions(+), 24 deletions(-) delete mode 100644 hooks/dmesg delete mode 100644 install/dmesg diff --git a/hooks/dmesg b/hooks/dmesg deleted file mode 100644 index f7d4088..0000000 --- a/hooks/dmesg +++ /dev/null @@ -1,5 +0,0 @@ -# vim: set ft=sh: -run_hook () -{ - dmesg -n 3 -} diff --git a/install/dmesg b/install/dmesg deleted file mode 100644 index 9482874..0000000 --- a/install/dmesg +++ /dev/null @@ -1,19 +0,0 @@ -# vim: set ft=sh: - -build() -{ - MODULES="" - BINARIES="" - FILES="" - SCRIPT="dmesg" -} - -help () -{ -cat<<HELPEOF - This hook lowers the console log level to 3. - It is useful when the user has to interact - with the boot process during early userspace - (like when entering a passphrase). -HELPEOF -} -- 1.7.5.4
Modify the sed filter to remove PIC addresses and ignore the first line which will always be the vdso. Also remove the tls filter, as glibc has had threaded support mainlined for many years now. If a user has a glibc this old, we don't have support for them elsewhere (udev, kernel). We also cleanup the logical flow through this function and remove a lot of cruft that would always return true, or that didn't quite make sense. Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 52 +++++++++++++++++++--------------------------------- 1 files changed, 19 insertions(+), 33 deletions(-) diff --git a/functions b/functions index 75ea0a0..1282e58 100644 --- a/functions +++ b/functions @@ -152,7 +152,7 @@ add_file () add_symlink "${fil}" "${lnk}" fil="${lnk}" fi - if [ $# -eq 2 ]; then + if [[ $2 ]]; then dest="${2}" else dest="${fil##$BASEDIR}" @@ -221,48 +221,34 @@ add_module () add_binary () { - local bin dest type lib - bin=$(which "${1}") - if [ $? -ne 0 ]; then - bin="${1}" - fi + local bin dest lib - dest="" - if [ $# -eq 2 ]; then - dest=${2} - fi + bin=$(type -P "$1") + dest=$2 - if [ ! -f "${bin}" ]; then - err "'${bin}' is not a file" + if [[ ! -f "$bin" ]]; then + err "'$1' is not a file" return 1 fi - if [ $? -eq 0 ]; then - type=$(file -b "${bin}") - case "${type}" in - *script*) + case "$(file -b "$bin")" in + *script*) msg " adding '${type}' script, ensure proper interp exists..." - add_file "${bin}" ${dest} + add_file "$bin" ${dest+"$dest"} ;; - *executable*|*shared\ object*|*symbolic\ link*) - add_file "${bin}" ${dest} - #note, this will also handle 'not a dynamic executable' spit out by - # static binaries... the deps will produce nothing - for lib in $(ldd ${bin} 2>/dev/null | sed "s|.*=>\(.*\)|\1|"); do - if [ -n "${lib}" ]; then - #remove TLS libraries - notls=$(echo ${lib} | sed 's|/lib/tls.*/\(lib.*\)|/lib/\1|') - [ -e "${notls}" ] && lib="${notls}" - [ -f "${lib}" ] && add_file "${lib}" - fi - done + *executable*|*shared\ object*|*symbolic\ link*) + add_file "$bin" ${dest+"$dest"} + # note, this will also handle 'not a dynamic executable' spit out + # by static binaries... the deps will produce nothing + while read -r lib; do + [[ -f "$lib" ]] && add_file "$lib" + done < <(ldd "$bin" 2>/dev/null | sed '1d;s|.*=>\(.*\)|\1|;s/(0x[0-9a-f]\+)//') ;; - *) - err "unknown type '${type}' for binary '${bin}'" + *) + err "unknown type '$type' for binary '$bin'" return 1 ;; - esac - fi + esac } parse_hook () -- 1.7.5.4
Simplify and fix a few bugs in the process. We rely solely on modinfo for obtaining information about module location, dependencies and firmware. Add a small wrapper function for modinfo that will always specify our $BASEDIR and $KERNELVERSION for us. Also, kill off HAS_MODULES. Since we have ADDED_MODULES, which contains all currently added modules, we can count the elements in this when it comes time to decide to create depmod files. Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 64 ++++++++++++++++++++++++++++++----------------------------- mkinitcpio | 2 +- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/functions b/functions index 1282e58..c0c0a78 100644 --- a/functions +++ b/functions @@ -39,6 +39,10 @@ in_array() { return 1 # Not Found } +kmodinfo() { + modinfo -b "$BASEDIR" -k "$KERNELVERSION" "$@" 2>/dev/null +} + auto_modules () { IFS=$'\n' read -rd '' -a mods < \ @@ -173,50 +177,48 @@ add_file () fi } -HAS_MODULES="n" declare -a ADDED_MODULES #modules are handled specially in order to enable autodetection add_module () { - local m fil path fw mod deps - m=$(get_module_name "${1}") - #find pattern - replace _ with [-_] to match either - fil="${m//_/[-_]}" + local module path fw dep deps + module=${1%.ko*} #skip expensive stuff if this module has already been added - if in_array $m ${ADDED_MODULES[@]}; then - msg "module $m was already added" + if in_array $module ${ADDED_MODULES[@]}; then + msg "module $module was already added" return fi - found=0 - for path in $(find "${MODULEDIR}" -type f -name "${fil}.ko" -or -name "${fil}.ko.gz"); do - #get needed firmware files - for fw in $(/sbin/modinfo -F firmware "${path}"); do - [ -f "/lib/firmware/$fw" ] && add_file "/lib/firmware/$fw" - done - #get module depends - deps="$(/sbin/modinfo -F depends "${path}")" - for mod in ${deps//,/ }; do - if [ -n "${mod}" ]; then - add_module "${mod}" + path=$(kmodinfo -0F filename "$module") + if [[ $path ]]; then + # get module firmware + while read -r -d '' fw; do + if [[ -e "$BASEDIR/lib/firmware/$fw" ]]; then + add_file "$BASEDIR/lib/firmware/$fw" fi + done < <(kmodinfo -0F firmware "$module") + + # get module depends + IFS=',' read -r -d '' -a deps < <(kmodinfo -0F depends "$module") + for dep in "${deps[@]}"; do + add_module "$dep" done - HAS_MODULES="y" - ADDED_MODULES[${#ADDED_MODULES[*]}]="$m" - msg " adding module ${fil}" - add_file "${path}" && found=1 - done - if [ ${found} -eq 1 ]; then - #explicit module depends - case "$m" in - fat) add_module "nls_cp437" ;; - ocfs2) add_module "configfs" ;; - libcrc32c) add_module "crc32c"; add_module "crc32c_intel" ;; - esac + + ADDED_MODULES+=("$module") + msg " adding module $module" + add_file "$path" || return else - err "module '$m' not found" + err "module '$module' not found" + return fi + + # explicit module depends + case "$module" in + fat) add_module "nls_cp437" ;; + ocfs2) add_module "configfs" ;; + libcrc32c) add_module "crc32c"; add_module "crc32c_intel" ;; + esac } add_binary () diff --git a/mkinitcpio b/mkinitcpio index fc50396..ac9522b 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -274,7 +274,7 @@ for hook in ${HOOKS}; do fi done -if [ "${HAS_MODULES}" = "y" ]; then +if (( ${#ADDED_MODULES[*]} )); then echo ":: Generating module dependencies" for mod in $(grep "file /lib/modules/${KERNELVERSION}" ${FILELIST} | cut -d' ' -f2); do install -m 644 -D "${BASEDIR}${mod}" "${TMPDIR}${mod}" -- 1.7.5.4
This was only ever used in the base layout, and it's not needed. devices will be present if we're using devtmpfs, and created for us by init if we mount on tmpfs. Also, this is part of our move towards using bsdcpio instead of gen_init_cpio, and as a side effect we can no longer support this. Any devices that need to be created should be done so by the runtime hooks, not the install time hooks. Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 17 ----------------- install/base | 5 ----- 2 files changed, 0 insertions(+), 22 deletions(-) diff --git a/functions b/functions index c0c0a78..dba647a 100644 --- a/functions +++ b/functions @@ -102,23 +102,6 @@ add_dir () fi } -# add_device /dev/foo type major minor [permissions] -add_device () -{ - if [ $# -ge 4 ]; then - local perms - perms="${5:-644}" - if ! grep -q "nod ${1}" "${FILELIST}"; then - add_dir $(get_dirname "${1}") - msg " adding node ${1}" - echo "nod ${1} ${perms} 0 0 ${2} ${3} ${4}" >> "${FILELIST}" - fi - else - err "invalid device node format: $@" - return 1 - fi -} - # what the hell does this do? add_symlink () { diff --git a/install/base b/install/base index 87d789d..bd1349b 100644 --- a/install/base +++ b/install/base @@ -14,11 +14,6 @@ build() add_dir "/usr/sbin" add_dir "/run" - add_device "/dev/null" c 1 3 - add_device "/dev/zero" c 1 5 - add_device "/dev/console" c 5 1 - add_device "/dev/mem" c 1 1 - add_binary /lib/initcpio/busybox /bin/busybox add_binary /sbin/modprobe add_binary /sbin/blkid -- 1.7.5.4
This is never used by anything in the official repos. Kill it with fire. Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 10 ---------- 1 files changed, 0 insertions(+), 10 deletions(-) diff --git a/functions b/functions index dba647a..03be8cc 100644 --- a/functions +++ b/functions @@ -119,16 +119,6 @@ add_symlink () #fail quietly } -add_symlink2 () -{ - add_dir $(get_dirname ${1}) - add_dir $(get_dirname ${2}) - if ! grep -q "slink ${1} " "${FILELIST}"; then - msg " adding link ${1} -> ${2}" - echo "slink ${1} ${2} 777 0 0" >> "${FILELIST}" - fi -} - add_file () { local fil lnk dir dest -- 1.7.5.4
This is a departure from using gen_init_cpio, which proved to be a huge bottleneck in performance. Tests for existance change from being a call to grep, to a simple shell test. In the process, we have to modify the behavior of the -s option, and we lose the -a option. Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 41 +++++++++++++---------------- mkinitcpio | 74 +++++++++++++++++++++++++++-------------------------- mkinitcpio.5.txt | 7 +--- 3 files changed, 58 insertions(+), 64 deletions(-) diff --git a/functions b/functions index 03be8cc..666aeec 100644 --- a/functions +++ b/functions @@ -79,12 +79,12 @@ checked_modules () add_full_dir () { - if [ -n "${1}" -a -d "${1}" ]; then - for f in ${1}/*; do - if [ -d "${f}" ]; then - add_full_dir "${f}" + if [[ -n $1 && -d $1 ]]; then + for f in "$1"/*; do + if [[ -d "$f" ]]; then + add_full_dir "$f" else - add_file "${f}" + add_file "$f" fi done fi @@ -92,28 +92,23 @@ add_full_dir () add_dir () { - #skip root directory and "." for relative directories... i.e. /foo/bar/./blah - if [ -n "${1}" -a "${1}" != "/" -a "${1}" != "." ]; then - if ! grep -q "dir ${1} " "${FILELIST}"; then - add_dir $(get_dirname "${1}") - msg " adding dir ${1}" - echo "dir ${1} 755 0 0" >> "${FILELIST}" - fi + if [[ ! -e "$TMPDIR/root/$1" ]]; then + msg " adding dir ${1}" + command install -dm755 "$TMPDIR/root/$1" fi } -# what the hell does this do? add_symlink () { local fil dest dir - if [ -h ${1} ]; then + if [[ -h $1 ]]; then fil="${1##$BASEDIR}" dest="${2##$BASEDIR}" add_dir $(get_dirname "${dest}") add_dir $(get_dirname "${fil}") - if ! grep -q "slink ${fil} " "${FILELIST}"; then + if [[ ! -e "$TMPDIR/root/$dest" ]]; then msg " adding link ${fil} -> ${dest}" - echo "slink ${fil} ${dest} $(stat -c '%a' ${1}) 0 0" >> "${FILELIST}" + ln -s "$dest" "$TMPDIR/root/$fil" fi fi #fail quietly @@ -122,27 +117,27 @@ add_symlink () add_file () { local fil lnk dir dest - if [ -f "${1}" ]; then - fil="${1}" + if [[ -f "$1" ]]; then + fil=$1 lnk=$(readlink -f "${fil}") - if [ -n "${lnk}" ]; then + if [[ ${lnk} ]]; then add_symlink "${fil}" "${lnk}" fil="${lnk}" fi if [[ $2 ]]; then - dest="${2}" + dest=$2 else dest="${fil##$BASEDIR}" - if [ "${dest}" = "${dest#/}" ]; then + if [[ "${dest}" = "${dest#/}" ]]; then dest="/${dest}" fi fi add_dir $(get_dirname "${dest}") - if ! grep -q "file ${dest} " "${FILELIST}"; then + if [[ ! -e $TMPDIR/root/$dest ]]; then msg " adding file ${dest}" - echo "file ${dest} ${fil} $(stat -c '%a' ${fil}) 0 0" >> "${FILELIST}" + command install -Dm$(stat -c '%a' "$fil") "$fil" "$TMPDIR/root/$dest" fi else err "file '${1}' does not exist" diff --git a/mkinitcpio b/mkinitcpio index ac9522b..c40fb2d 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -10,11 +10,11 @@ # in case of embedded spaces, quote all path names and string comparisons # +shopt -s extglob # Settings TMPDIR="$(mktemp -d /tmp/mkinitcpio.XXXXXX)" BASEDIR="" -FILELIST="${TMPDIR}/filelist" MESSAGEFILE="${TMPDIR}/message" KERNELVERSION="$(uname -r)" FUNCTIONS="functions" @@ -24,7 +24,6 @@ INSTDIR="install" MODULE_FILE="" SAVELIST="" GENIMG="" -APPEND="" PRESET="" MESSAGE="" SKIPHOOKS=() @@ -49,10 +48,9 @@ usage () echo "${APPNAME}: usage" echo " -c CONFIG Use CONFIG file. default: /etc/mkinitcpio.conf" echo " -k KERNELVERSION Use KERNELVERSION. default: $(uname -r)" - echo " -s NAME Save filelist. default: no" + echo " -s Save build directory. default: no" echo " -b BASEDIR Use BASEDIR. default: /" echo " -g IMAGE Generate a cpio image as IMAGE. default: no" - echo " -a NAME Append to an existing filelist. default: no" echo " -p PRESET Build specified preset." echo " -m MESSAGE Print MESSAGE before passing control to init." echo " -S SKIPHOOKS Skip SKIPHOOKS (comma-separated) when building the image." @@ -67,7 +65,11 @@ usage () cleanup () { - [ -n "${TMPDIR}" -a -d "${TMPDIR}" ] && rm -rf ${TMPDIR} + if [[ $SAVELIST ]]; then + echo ":: build directory saved in $TMPDIR" + else + rm -rf ${TMPDIR} + fi } sighandler() { @@ -77,7 +79,7 @@ sighandler() { trap sighandler TERM INT -while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do +while getopts ':c:k:sb:g:p:m:vH:LMhS:' arg; do if [ "${OPTARG#-}" != "${OPTARG}" ]; then echo "error: optional argument to '-${arg}' begins with a '-'" echo " you probably don't want this....aborting." @@ -86,10 +88,9 @@ while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do case "${arg}" in c) CONFIG="${OPTARG}" ;; k) KERNELVERSION="${OPTARG}" ;; - s) SAVELIST="y"; FILELIST="${OPTARG}" ;; + s) SAVELIST="y"; ;; b) BASEDIR="${OPTARG}" ;; g) GENIMG="${OPTARG}" ;; - a) APPEND="y"; SAVELIST="y"; FILELIST="${OPTARG}" ;; p) PRESET="${OPTARG}" ;; m) MESSAGE="${OPTARG}" ;; v) QUIET="n" ;; @@ -185,6 +186,15 @@ BASEDIR="${BASEDIR%/}" MODULEDIR="${BASEDIR}/lib/modules/${KERNELVERSION}" +if [[ $GENIMG ]]; then + IMGPATH=$(readlink -f "$GENIMG") + if [[ -z $IMGPATH || ! -w ${IMGPATH%/*} ]]; then + echo "error: unable to write to path: '$GENIMG'" + cleanup + exit 1 + fi +fi + if [ -n "${BASEDIR}" ]; then if [ "${BASEDIR}" = "${BASEDIR#/}" ]; then BASEDIR="$(pwd)/${BASEDIR}" @@ -202,19 +212,6 @@ if [ ! -f "${CONFIG}" ]; then fi . "${CONFIG}" -if [ -f "${FILELIST}" -a -z "${APPEND}" ]; then - if [ -z "${SAVELIST}" ]; then - rm ${FILELIST} - touch "${FILELIST}" - else - echo "destination file list '${FILELIST}' exists - remove before running" - cleanup - exit 1 - fi -else - touch "${FILELIST}" -fi - BASEDIR=$(echo ${BASEDIR} | tr -s /) MODULEDIR=$(echo ${MODULEDIR} | tr -s /) @@ -276,31 +273,36 @@ done if (( ${#ADDED_MODULES[*]} )); then echo ":: Generating module dependencies" - for mod in $(grep "file /lib/modules/${KERNELVERSION}" ${FILELIST} | cut -d' ' -f2); do - install -m 644 -D "${BASEDIR}${mod}" "${TMPDIR}${mod}" - done - /sbin/depmod -b ${TMPDIR} ${KERNELVERSION} - for dmfile in modules.{dep,alias,symbols}.bin; do - add_file "${TMPDIR}/lib/modules/${KERNELVERSION}/$dmfile" "/lib/modules/${KERNELVERSION}/$dmfile" - done + /sbin/depmod -b "${TMPDIR}/root" "${KERNELVERSION}" + rm "$TMPDIR/root/lib/modules/$KERNELVERSION"/modules.!(dep.bin|alias.bin|symbols.bin) fi -status=0 +declare -i status=0 +declare -a pipesave if [ -n "${GENIMG}" ]; then echo ":: Generating image '${GENIMG}'" - shopt -s -o pipefail [ ${COMPRESSION} = "xz" ] && COMPRESSION_OPTIONS="${COMPRESSION_OPTIONS} --check=crc32" - if ! /sbin/gen_init_cpio ${FILELIST} | ${COMPRESSION} ${COMPRESSION_OPTIONS} > "${GENIMG}"; then - echo ":: Image generation FAILED" + + pushd "$TMPDIR/root" >/dev/null + find . -print0 | bsdcpio -0oH newc | $COMPRESSION $COMPRESSION_OPTIONS > "$IMGPATH" + pipesave=("${PIPESTATUS[@]}") # save immediately + popd >/dev/null + + if (( pipesave[0] )); then + errmsg="find reported an error" + elif (( pipesave[1] )); then + errmsg="bsdcpio reported an error" + elif (( pipesave[2] )); then + errmsg="$COMPRESSION reported an error" + fi + + if [[ $errmsg ]]; then + echo ":: Image generation FAILED ($errmsg)" status=1 else echo ":: Image generation successful" - status=0 fi - if [ -z "${SAVELIST}" ]; then - rm ${FILELIST} - fi else echo ":: Dry run complete, use -g IMAGE to generate a real image" fi diff --git a/mkinitcpio.5.txt b/mkinitcpio.5.txt index 1c095dc..3d0fdc9 100644 --- a/mkinitcpio.5.txt +++ b/mkinitcpio.5.txt @@ -21,8 +21,8 @@ Options *-k* 'kernelversion':: Use 'kernelversion'. Default is the current running kernel. -*-s* 'filelist':: - Saves a list of all the files in the initial ramdisk in 'filelist'. Default: no; This means the filelist will not be retained if this option isn't specified. Useful for debugging purposes. +*-s*:: + Saves the build directory for the initial ramdisk. Default: no; This means the directory will not be retained if this option isn't specified. Useful for debugging purposes. *-b* 'basedir':: Use 'basedir' as a starting point for gathering information about the currently running system. Default: /. @@ -30,9 +30,6 @@ Options *-g* 'filename':: Generate a CPIO image as 'filename'. Default: no; this means nothing will be written to the filesystem unless this option is specified. -*-a* 'filelist':: - Append to an existing 'filelist'. Default no. - *-p* 'preset':: Build initial ramdisk according to specified 'preset'. Presets are found in /etc/mkinitcpio.d -- 1.7.5.4
Properly detect symlinks using the -L shell test, resolving and recursing on discovery. This results in removing a lot of extraneous variable declarations and code. --- functions | 126 +++++++++++++++++++++++++++++++++++------------------------- 1 files changed, 73 insertions(+), 53 deletions(-) diff --git a/functions b/functions index 666aeec..ad34315 100644 --- a/functions +++ b/functions @@ -2,21 +2,18 @@ msg () { [ "${QUIET}" = "n" ] && echo $@; } err () { echo "ERROR: $@" >&2; } die () { echo "FATAL: $@" >&2; cleanup; exit 1; } -get_dirname () -{ +get_dirname() { # strip any trailing slash first... local dir="${1%/}" # then get the directory portion echo "${dir%/*}" } -get_basename () -{ +get_basename() { echo "${1##*/}" } -get_module_name () -{ +get_module_name() { #cleanup - remove .ko, replace - with _ local modname="${1%.gz}" modname=$(get_basename "${modname%.ko}") @@ -24,12 +21,11 @@ get_module_name () echo "$modname" } -## -# usage : in_array( $needle, $haystack ) -# return : 0 - found -# 1 - not found -## in_array() { + # Search for an element in an array. + # $1: needle + # ${@:2}: haystack + local needle=$1; shift [[ -z $1 ]] && return 1 # Not Found local item @@ -40,11 +36,16 @@ in_array() { } kmodinfo() { + # A wrapper around modinfo, which is aware of our $BASEDIR and + # $KERNELVERSION + # $@: args to modinfo + modinfo -b "$BASEDIR" -k "$KERNELVERSION" "$@" 2>/dev/null } -auto_modules () -{ +auto_modules() { + # Perform auto detection of modules via sysfs. + IFS=$'\n' read -rd '' -a mods < \ <(find /sys/devices -name modalias -exec sort -zu {} + | xargs -0 modprobe -aRS "$KERNELVERSION" | @@ -54,8 +55,10 @@ auto_modules () (( ${#mods[*]} )) } -all_modules () -{ +all_modules() { + # Add modules to the initcpio, filtered by grep. + # $@: filter arguments to grep + local -i count=0 while read -r -d '' mod; do (( ++count )) @@ -67,8 +70,11 @@ all_modules () (( count )) } -checked_modules () -{ +checked_modules() { + # Add modules to the initcpio, filtered by the list of autodetected + # modules. + # $@: arguments to all_modules + if [[ -s "$MODULE_FILE" ]]; then grep -xFf "$MODULE_FILE" <(all_modules "$@") return 1 @@ -77,8 +83,11 @@ checked_modules () fi } -add_full_dir () -{ +add_full_dir() { + # Add a directory and all its contents, recursively, to the initcpio image. + # No parsing is performed and the contents of the directory is added as is. + # $1: path to directory + if [[ -n $1 && -d $1 ]]; then for f in "$1"/*; do if [[ -d "$f" ]]; then @@ -90,16 +99,21 @@ add_full_dir () fi } -add_dir () -{ +add_dir() { + # Add a directory to the initcpio image. + # $1: absolute path of directory on image + if [[ ! -e "$TMPDIR/root/$1" ]]; then msg " adding dir ${1}" command install -dm755 "$TMPDIR/root/$1" fi } -add_symlink () -{ +add_symlink() { + # Add a symlink to the initcpio image. + # $1: pathname of symlink on image + # $2: absolute path to target of symlink + local fil dest dir if [[ -h $1 ]]; then fil="${1##$BASEDIR}" @@ -114,41 +128,40 @@ add_symlink () #fail quietly } -add_file () -{ - local fil lnk dir dest - if [[ -f "$1" ]]; then - fil=$1 - lnk=$(readlink -f "${fil}") - if [[ ${lnk} ]]; then - add_symlink "${fil}" "${lnk}" - fil="${lnk}" - fi - if [[ $2 ]]; then - dest=$2 - else - dest="${fil##$BASEDIR}" - if [[ "${dest}" = "${dest#/}" ]]; then - dest="/${dest}" - fi - fi +add_file() { + # Add a plain file to the initcpio image. No parsing is performed and only + # the singular file is added. + # $1: path to file + # $2: destination on initcpio (optional, defaults to same as source) - add_dir $(get_dirname "${dest}") + local file dest + + file=$1 + dest=${2:-${file##$BASEDIR}} - if [[ ! -e $TMPDIR/root/$dest ]]; then - msg " adding file ${dest}" - command install -Dm$(stat -c '%a' "$fil") "$fil" "$TMPDIR/root/$dest" + if [[ -f "$file" ]]; then + if [[ -L "$file" ]]; then + add_symlink "$file" "$(readlink -f "$file")" + add_file "$(readlink -f "$file")" + return + fi + + if [[ ! -e "$TMPDIR/root/$dest" ]]; then + msg " adding file $dest" + command install -Dm$(stat -c '%a' "$file") "$file" "$TMPDIR/root/$dest" fi else - err "file '${1}' does not exist" + err "file '$file' does not exist" return 1 fi } declare -a ADDED_MODULES -#modules are handled specially in order to enable autodetection -add_module () -{ +add_module() { + # Add a kernel module to the initcpio image. Dependencies will be + # discovered and added. + # $1: module name + local module path fw dep deps module=${1%.ko*} @@ -189,8 +202,12 @@ add_module () esac } -add_binary () -{ +add_binary() { + # add a binary file to the initcpio image. library dependencies will + # be discovered and added. + # $1: path to binary + # $2: destination on initcpio (optional, defaults to same as source) + local bin dest lib bin=$(type -P "$1") @@ -221,8 +238,11 @@ add_binary () esac } -parse_hook () -{ +parse_hook() { + # parse key global variables set by install hooks. This function is called + # prior to the start of hook processing, and after each hook's build + # function is run. + local mod bin fil for mod in ${MODULES}; do if [ -n "${mod}" ]; then -- 1.7.5.4
Signed-off-by: Dave Reisner <d@falconindy.com> --- mkinitcpio.conf | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/mkinitcpio.conf b/mkinitcpio.conf index ce0a077..eb47949 100644 --- a/mkinitcpio.conf +++ b/mkinitcpio.conf @@ -60,7 +60,8 @@ HOOKS="base udev autodetect pata scsi sata filesystems" # Use this to compress the initramfs image. With kernels earlier than # 2.6.30, only gzip is supported, which is also the default. Newer kernels # support gzip, bzip2 and lzma. Kernels 2.6.38 and later support xz -# compression. +# compression. LZO support is available by installing the 'lzop' package +# and speciofying 'lzop' as COMPRESSION. #COMPRESSION="gzip" #COMPRESSION="bzip2" #COMPRESSION="lzma" -- 1.7.5.4
Signed-off-by: Dave Reisner <d@falconindy.com> --- mkinitcpio | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index c40fb2d..5c62868 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -41,7 +41,7 @@ fi # works around undetected problems like in #8448 PATH="${PATH}:/sbin:/usr/sbin" -APPNAME=$(basename "${0}") +APPNAME=${0##*/} usage () { @@ -107,7 +107,7 @@ while getopts ':c:k:sb:g:p:m:vH:LMhS:' arg; do exit 0 ;; L) echo "Available hooks: " for h in ${INSTDIR}/*; do - echo " $(basename ${h})" + echo " ${h##*/}" done cleanup exit 0 ;; @@ -212,8 +212,8 @@ if [ ! -f "${CONFIG}" ]; then fi . "${CONFIG}" -BASEDIR=$(echo ${BASEDIR} | tr -s /) -MODULEDIR=$(echo ${MODULEDIR} | tr -s /) +BASEDIR=${BASEDIR//+(\/)//} +MODULEDIR=${MODULEDIR//+(\/)//} . "${FUNCTIONS}" -- 1.7.5.4
update the example.preset to show this syntax as an alternative Signed-off-by: Dave Reisner <d@falconindy.com> --- mkinitcpio | 29 ++++++++++++++++++++++++++++- mkinitcpio.d/example.preset | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 5c62868..6a5fb62 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -77,6 +77,25 @@ sighandler() { exit 1 } +get_kernver() { + local kernel=$1 + + if [[ "${kernel:0:1}" != / ]]; then + echo $kernel + return 0 + fi + + [[ -r "$kernel" ]] || return 1 + + read _ kernver < <(file -b "$BASEDIR$kernel" | grep -o 'version [^ ]\+') + if [[ "$kernver" && -e "$BASEDIR/lib/modules/$kernver" ]]; then + echo "$kernver" + return 0 + fi + + return 1 +} + trap sighandler TERM INT while getopts ':c:k:sb:g:p:m:vH:LMhS:' arg; do @@ -87,7 +106,7 @@ while getopts ':c:k:sb:g:p:m:vH:LMhS:' arg; do fi case "${arg}" in c) CONFIG="${OPTARG}" ;; - k) KERNELVERSION="${OPTARG}" ;; + k) optkver=$OPTARG ;; s) SAVELIST="y"; ;; b) BASEDIR="${OPTARG}" ;; g) GENIMG="${OPTARG}" ;; @@ -119,6 +138,14 @@ while getopts ':c:k:sb:g:p:m:vH:LMhS:' arg; do done shift $((${OPTIND} - 1)) +if [[ $optkver ]]; then + if ! KERNELVERSION=$(get_kernver "$optkver"); then + echo "error: '$optkver' is an invalid kernel specifier" + cleanup + exit 1 + fi +fi + # use preset $PRESET if [ -n "${PRESET}" ]; then if [ -f "${PRESETDIR}/${PRESET}.preset" ]; then diff --git a/mkinitcpio.d/example.preset b/mkinitcpio.d/example.preset index 3fb32f1..93a8f92 100644 --- a/mkinitcpio.d/example.preset +++ b/mkinitcpio.d/example.preset @@ -7,7 +7,7 @@ PRESETS=('default' 'fallback') # note for distribution kernels: this should be in a separate file # and read like this: # . /etc/mkinitcpio.d/exmaple.kver -ALL_kver='2.6.24-ARCH' +ALL_kver='/boot/vmlinuz26' ALL_config='/etc/mkinitcpio.conf' # presetname_kver - the kernel version (omit if ALL_kver should be used) -- 1.7.5.4
participants (1)
-
Dave Reisner