summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmkinitcpio29
-rw-r--r--mkinitcpio.d/example.preset2
2 files changed, 29 insertions, 2 deletions
diff --git a/mkinitcpio b/mkinitcpio
index 897ce1d..8cf8859 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -80,6 +80,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
@@ -90,7 +109,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}" ;;
@@ -122,6 +141,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)