Merge debian/changelog
authorMichael Prokop <mika@grml.org>
Sat, 4 Apr 2009 17:51:08 +0000 (19:51 +0200)
committerMichael Prokop <mika@grml.org>
Sat, 4 Apr 2009 17:51:08 +0000 (19:51 +0200)
debian/changelog
usr_bin/grml-exec-wrapper [new file with mode: 0755]

index ba8a04d..8caf1f6 100644 (file)
@@ -4,6 +4,7 @@ grml-scripts (1.1.18) UNRELEASED; urgency=low
   * blacklist: use /etc/modprobe.d/grml.conf instead of
     /etc/modprobe.d/grml. New module-init-tools will
     use only files using the .conf suffix.
+  * Add new script grml-exec-wrapper.
 
  -- Michael Prokop <mika@grml.org>  Tue, 03 Mar 2009 10:35:12 +0100
 
diff --git a/usr_bin/grml-exec-wrapper b/usr_bin/grml-exec-wrapper
new file mode 100755 (executable)
index 0000000..6973b70
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/sh
+# Filename:      grml-exec-wrapper
+# Purpose:       simple but smart program execution wrapper
+# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# Bug-Reports:   see http://grml.org/bugs/
+# License:       This file is licensed under the GPL v2 or any later version.
+################################################################################
+
+usage() {
+  printf "Usage: $0 <program> [<arguments>]
+
+Available options:
+
+  -h | --help   display this usage information
+  -p <program>  check specified argument instead of default args, like:
+               $(basename $0) -p aumix xterm -T aumix -e aumix
+"
+}
+
+is_installed() {
+    prog="$(basename $1)"
+    [ -z "$prog" ] && return 1
+
+    ret=1
+    oifs="$IFS"
+    IFS=:
+    for dir in $PATH; do
+        [ -z "$dir" ] && continue
+        [ -x "$dir/$prog" ] && ret=0 && break
+    done
+
+    IFS="$oifs"
+    unset oifs
+    return "$ret"
+}
+
+# use Xdisplay only if present and running under X:
+display_info() {
+if is_installed xterm && test -n "$DISPLAY" ; then
+    xterm -T 'Sorry :(' -e "dialog --msgbox \"$1\" 0 0"
+else
+    printf '%s\n' "$1">&2
+fi
+}
+
+if [ -z "$1" -o "$1" = '-h' -o "$1" = '--help' ] ; then
+    usage
+    exit 1
+fi
+
+if [ "$1" = '-p' ] ; then
+    if [ -z "$2" ] ; then
+         usage
+        exit 1
+    else
+         PROG="$2"
+        shift ; shift
+    fi
+else
+    PROG="$1"
+    # make sure to support 'grml-exec-wrapper sudo wireshark' as well:
+    case $PROG in
+      *sudo*) PROG="$2" ;;
+    esac
+fi
+
+if is_installed "$PROG" ; then
+    exec "$@"
+fi
+
+display_info "Sorry: ${PROG} not available.
+
+Looks like the grml flavour you are using does not ship ${PROG}. :(
+
+You can search for ${PROG} executing:
+
+apt-get update && apt-cache search $(basename ${PROG})
+    "
+
+exit 1
+
+## END OF FILE #################################################################