grml-exec-wrapper: remove uneeded variable and else path
[grml-scripts.git] / usr_bin / grml-exec-wrapper
1 #!/bin/sh
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 is_installed() {
10     prog="$1"
11     [ -z "$prog" ] && return 1
12
13     ret=1
14     oifs="$IFS"
15     IFS=:
16     for dir in $PATH; do
17         [ -z "$dir" ] && continue
18         [ -x "$dir/$prog" ] && ret=0 && break
19     done
20
21     IFS="$oifs"
22     unset oifs
23     return "$ret"
24 }
25
26 # use Xdisplay only if present and running under X:
27 display_info() {
28 if is_installed Xdialog && test -n "$DISPLAY" ; then
29     Xdialog --title "grml-exec-wrapper" --msgbox "$1" 0 0 0
30 else
31     print "$1">&2
32 fi
33 }
34
35 if [ -z "$1" ] ; then
36     display_info "Usage: $0 <program> [<arguments>]"
37     exit 1
38 fi
39
40 PROG="$1"
41
42 # make sure to support 'grml-exec-wrapper sudo wireshark' as well:
43 case $PROG in
44         *sudo*) PROG="$2" ;;
45 esac
46
47 if is_installed "$PROG" ; then
48     exec "$@"
49 fi
50
51 display_info "Sorry: ${PROG} not available.
52
53 Looks like the grml flavour you are using does not ship ${PROG}. :(
54
55 You can search for ${PROG} executing:
56
57 apt-get update && apt-cache search ${PROG}
58     "
59
60 exit 1
61
62 ## END OF FILE #################################################################