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 bf9817a..0706d0d 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -78,6 +78,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 @@ -88,7 +107,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}" ;; @@ -120,6 +139,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