summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-05-04 16:00:00 +0200
committerDave Reisner <dreisner@archlinux.org>2012-05-16 23:55:54 +0200
commitac88b257483372e709baac83066704b8fb484504 (patch)
tree2b52488e52458bc01297d49b7075e7fab9babaf2
parent3af39a17e9e110f1612626386672efe9469f1872 (diff)
downloadmkinitcpio-ac88b257483372e709baac83066704b8fb484504.tar.gz
mkinitcpio-ac88b257483372e709baac83066704b8fb484504.tar.xz
mkinitcpio: separate logic to resolve kernel version
Rename get_kernelver -> resolve_kernelver, and ensure that it only does what it's name advertises. Introduce find_moduledir to locate the corresponding module directory in /usr/lib or /lib. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rwxr-xr-xmkinitcpio30
1 files changed, 22 insertions, 8 deletions
diff --git a/mkinitcpio b/mkinitcpio
index 4fb48e4..74de0c2 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -73,7 +73,7 @@ cleanup() {
exit ${1:0}
}
-get_kernver() {
+resolve_kernver() {
local kernver= kernel=$1
if [[ -z $kernel ]]; then
@@ -87,17 +87,30 @@ get_kernver() {
fi
if [[ ! -e $kernel ]]; then
- error "Specified kernel image does not exist: \`%s'" "$kernel"
+ error "specified kernel image does not exist: \`%s'" "$kernel"
return 1
fi
- read _ kernver < <(file -Lb "$kernel" | grep -o 'version [^ ]\+')
- if [[ $kernver && -e /lib/modules/$kernver ]]; then
- echo "$kernver"
+ if file -Lb "$kernel" | grep -oP '(?<=version )[^ ]+'; then
return 0
fi
- error "invalid kernel specifier: \`%s'" "$optkver"
+ error "invalid kernel specified: \`%s'" "$optkver"
+
+ return 1
+}
+
+find_moduledir() {
+ local d
+
+ for d in {/usr,}/lib/modules; do
+ if [[ -d $d/$1/ ]]; then
+ printf '%s' "$d/$1/"
+ return 0
+ fi
+ done
+
+ error "unable to locate module directory for kernel \`%s'" "$1"
return 1
}
@@ -219,7 +232,7 @@ readonly NC BOLD BLUE GREEN RED YELLOW
[[ -e /proc/self/mountinfo ]] || die "/proc must be mounted!"
[[ -e /dev/fd ]] || die "/dev must be mounted!"
-KERNELVERSION=$(get_kernver "$optkver") || cleanup 1
+KERNELVERSION=$(resolve_kernver "$optkver") || cleanup 1
if [[ $TMPDIR ]]; then
if [[ ! -d $TMPDIR ]]; then
@@ -311,7 +324,8 @@ if (( ${#hooks[*]} == 0 )); then
die "Invalid config: No hooks found"
fi
-MODULEDIR=/lib/modules/$KERNELVERSION/
+MODULEDIR=$(find_moduledir "$KERNELVERSION") || cleanup 1
+
if [[ ! -d $MODULEDIR ]]; then
die "'$MODULEDIR' is not a valid kernel module directory"
fi