diff options
author | Erich Eckner <git@eckner.net> | 2018-01-08 09:26:49 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-01-08 09:26:49 +0100 |
commit | fe5e1099ae5b010ee16e050198db041da50f35da (patch) | |
tree | ddc4f80e9cf9eed431ddc6d9e0c5c0d25bc0d40e /check-kernel.in | |
parent | daf87b002dd871d7d369539d9126b7d9e99b204a (diff) | |
download | check-kernel-fe5e1099ae5b010ee16e050198db041da50f35da.tar.xz |
Makefile
Diffstat (limited to 'check-kernel.in')
-rw-r--r-- | check-kernel.in | 91 |
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 |