[arch-projects] [mkinitcpio][PATCH 3/4] mkinitcpio: ensure get_kernver always returns a kver
Dave Reisner
d at falconindy.com
Sun Oct 16 11:53:34 EDT 2011
- 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 <dreisner at archlinux.org>
---
mkinitcpio | 29 +++++++++++++++++------------
1 files 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
--
1.7.7
More information about the arch-projects
mailing list