summaryrefslogtreecommitdiff
path: root/check-kernel.in
diff options
context:
space:
mode:
Diffstat (limited to 'check-kernel.in')
-rw-r--r--check-kernel.in91
1 files changed, 91 insertions, 0 deletions
diff --git a/check-kernel.in b/check-kernel.in
new file mode 100644
index 0000000..2354345
--- /dev/null
+++ b/check-kernel.in
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+# check-kernel #VERSION#
+
+verwendung() {
+ >&2 echo 'check-kernel checks if the installed kernel is currently running'
+ >&2 echo ''
+ >&2 echo 'Usage: sendmailadvanced [OPTIONS]'
+ >&2 echo ' -r,--reboot reboot system if installed kernel is not yet running'
+ >&2 echo \
+'#HELPTEXT# #'
+ exit 1
+}
+
+eval set -- "$(
+ getopt -o eh:i:st \
+ --long encrypt \
+ --long help \
+ --long version \
+ -n "$(basename "$0")" -- "$@" \
+ || echo verwendung
+)"
+
+reboot=false
+while true; do
+ case "$1" in
+ -r|--reboot)
+ shift
+ reboot=true
+ ;;
+ --help)
+ verwendung 0
+ ;;
+ --version)
+ echo '#VERSION#'
+ exit 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ >&2 echo "FEHLER: Verstehe Option \"$1\" doch nicht! Ich beende."
+ verwendung
+ ;;
+ esac
+ shift
+done
+
+
+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