Add grml-exec-wrapper
[grml-scripts.git] / usr_bin / grml-exec-wrapper
1 #!/bin/bash
2 # Filename:      grml-exec-wrapper
3 # Purpose:       simple but smart program execution wrapper
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 # use Xdisplay only if present and running under X:
10 display_info() {
11 if type -a Xdialog 1>/dev/null 2>&1 && test -n "$DISPLAY" ; then
12     Xdialog --title "grml-exec-wrapper" --msgbox "$1" 0 0 0
13 else
14     print "$1">&2
15 fi
16 }
17
18 if [ -z "$1" ] ; then
19     display_info "Usage: $0 <program> [<arguments>]"
20     exit 1
21 fi
22
23 RC='0'
24 PROG="$1"
25
26 # make sure to support 'grml-exec-wrapper sudo wireshark' as well:
27 case $PROG in
28         *sudo*) PROG="$2" ;;
29 esac
30
31 if type -a "$PROG" 1>/dev/null 2>&1 ; then
32     exec $@
33 else
34     RC=1
35     display_info "Sorry: ${PROG} not available.
36
37 Looks like the grml flavour you are using does not ship ${PROG}. :(
38
39 You can search for ${PROG} executing:
40
41 apt-get update && apt-cache search ${PROG}
42     "
43 fi
44
45 exit $RC
46
47 ## END OF FILE #################################################################