summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-01-08 09:26:49 +0100
committerErich Eckner <git@eckner.net>2018-01-08 09:26:49 +0100
commitfe5e1099ae5b010ee16e050198db041da50f35da (patch)
treeddc4f80e9cf9eed431ddc6d9e0c5c0d25bc0d40e
parentdaf87b002dd871d7d369539d9126b7d9e99b204a (diff)
downloadcheck-kernel-fe5e1099ae5b010ee16e050198db041da50f35da.tar.xz
Makefile
-rw-r--r--.gitignore2
-rw-r--r--Makefile57
-rwxr-xr-xcheck-kernel43
-rw-r--r--check-kernel.in91
4 files changed, 150 insertions, 43 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9e1d00b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.1
+check-kernel
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..83a64e4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,57 @@
+#
+# check-kernel - check if the installed kernel is currently running
+#
+# Copyright (c) 2018 Erich Eckner <opensource at eckner dot net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+#
+
+DESTDIR =
+ETCDIR = /etc
+BINDIR = /usr/bin
+MANDIR = /usr/share/man
+
+VERSION = 0.0
+
+all: check-kernel
+
+%: %.in
+ sed " \
+ s/#VERSION#/$(VERSION)/; \
+ s@#BINDIR#@$(BINDIR)@; \
+ s@#ETCDIR#@$(ETCDIR)@; \
+ s@#HELPTEXT#\(\s\+\)#@ --help \1display this help and exit\n --version\1display version and exit@; \
+ " $< > $@
+ [ "$@" = "check-kernel" ] && chmod +x "$@" || true
+
+.PHONY: install dist clean
+
+install: all
+ install -D -m0755 check-kernel $(DESTDIR)$(BINDIR)/check-kernel
+
+clean:
+ ls -A | \
+ grep "^\($(shell sed 's|\.|\\.|; s|\*|.*|; s|$$|\\|' .gitignore | tr '\n' '\|')\)\$$" | \
+ xargs -r rm
+
+dist: clean
+ git status --porcelain 2> /dev/null | grep -q "\S" && (git add .; git commit -m"neue Version: $(VERSION)") || true
+ ! git tag -d v$(VERSION) 2> /dev/null
+ git tag v$(VERSION)
+ git push
+ git push --tags
+
+# End of file
diff --git a/check-kernel b/check-kernel
deleted file mode 100755
index 5370f49..0000000
--- a/check-kernel
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/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
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