From ea3ba8b3e470736ed6970652bc0c7f516a8dafff Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 10 Oct 2011 16:33:11 -0400 Subject: mkinitcpio: ensure get_kernver always returns a kver - Always call this function. At worst, just return the current kver. - Do all our error reporting from within the function. - Add an additional check for existance prior to allow for a more appropriate error message when we encounter a situation such as /boot not being mounted. Signed-off-by: Dave Reisner --- mkinitcpio | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index db62d92..8d3a67f 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -13,7 +13,6 @@ shopt -s extglob # Settings -KERNELVERSION=$(uname -r) FUNCTIONS=functions CONFIG=mkinitcpio.conf HOOKDIR=hooks @@ -45,7 +44,7 @@ usage: ${0##*/} [options] -g IMAGE Generate a cpio image as IMAGE. default: no -H HOOKNAME Output help for hook 'HOOKNAME'. -h Display this message. - -k KERNELVERSION Use KERNELVERSION. default: $KERNELVERSION + -k KERNELVERSION Use KERNELVERSION. default: $(uname -r) -L List all available hooks. -M Display modules found via autodetection. -n Disable colorized output messages. @@ -76,19 +75,30 @@ cleanup() { get_kernver() { local kernver= kernel=$1 - if [[ "${kernel:0:1}" != / ]]; then - echo $kernel + if [[ -z $kernel ]]; then + uname -r return 0 fi - [[ -r "$BASEDIR$kernel" ]] || return 1 + if [[ ${kernel:0:1} != / ]]; then + echo "$kernel" + return 0 + fi + + if [[ ! -e $BASEDIR$kernel ]]; then + error "Specified kernel image does not exist: \`%s'" "$BASEDIR$kernel" + return 1 + fi read _ kernver < <(file -b "$BASEDIR$kernel" | grep -o 'version [^ ]\+') - if [[ "$kernver" && -e "$BASEDIR/lib/modules/$kernver" ]]; then + if [[ $kernver && -e $BASEDIR/lib/modules/$kernver ]]; then echo "$kernver" return 0 fi + [[ ${optkver:0:1} == / ]] && optkver=$BASEDIR$optkver + error "invalid kernel specifier: \`%s'" "$optkver" + return 1 } @@ -172,12 +182,7 @@ if [[ $BASEDIR ]]; then popd &>/dev/null fi -if [[ $optkver ]]; then - if ! KERNELVERSION=$(get_kernver "$optkver"); then - [[ ${optkver:0:1} == / ]] && optkver=$BASEDIR$optkver - die "invalid kernel specifier: \`%s'" "$optkver" - fi -fi +KERNELVERSION=$(get_kernver "$optkver") || cleanup 1 if [[ $TMPDIR ]]; then if [[ ! -d $TMPDIR ]]; then -- cgit v1.2.3-24-g4f1b