summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2011-10-10 22:33:11 +0200
committerDave Reisner <dreisner@archlinux.org>2011-10-16 23:43:21 +0200
commitea3ba8b3e470736ed6970652bc0c7f516a8dafff (patch)
tree5c01761d1afcad81ccfb34cf7f7122a47d765f66
parent71e960e95f880e02cb735faa14d28565b6312f7c (diff)
downloadmkinitcpio-ea3ba8b3e470736ed6970652bc0c7f516a8dafff.tar.gz
mkinitcpio-ea3ba8b3e470736ed6970652bc0c7f516a8dafff.tar.xz
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 <dreisner@archlinux.org>
-rwxr-xr-xmkinitcpio29
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