summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-12-19 08:51:13 +0100
committerErich Eckner <git@eckner.net>2017-12-19 08:51:13 +0100
commitdaf87b002dd871d7d369539d9126b7d9e99b204a (patch)
treeabdbe7a420816b7c9d10d27d8afd680cf1399bdf
downloadcheck-kernel-daf87b002dd871d7d369539d9126b7d9e99b204a.tar.xz
Initial commit
-rwxr-xr-xcheck-kernel43
1 files changed, 43 insertions, 0 deletions
diff --git a/check-kernel b/check-kernel
new file mode 100755
index 0000000..5370f49
--- /dev/null
+++ b/check-kernel
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+if which pacman >/dev/null 2>&1; then
+ # arch linux
+ running=$(
+ uname -r | \
+ sed '
+ s|-ARCH$||
+ '
+ )
+ installed=$(
+ pacman -Q linux | \
+ cut -d' ' -f2
+ )
+elif which apt >/dev/null 2>&1; then
+ # debian
+ running=$(
+ uname -r
+ )
+ installed=$(
+ dpkg-query -W 'linux-image-*-?86' | \
+ cut -f1 | \
+ sed '
+ s|^linux-image-||
+ ' | \
+ sort -V | \
+ tail -n1
+ )
+else
+ >&2 printf 'Cannot determin installed kernel.\n'
+ exit 2
+fi
+
+if [ "${running}" = "${installed}" ]; then
+ >&2 printf 'The installed kernel (%s) is currently running.\n' \
+ "${installed}"
+ exit 0
+else
+ >&2 printf 'The installed (%s) and running kernel (%s) differ.\n' \
+ "${installed}" \
+ "${running}"
+ exit 1
+fi