grml-exec-wrapper: add double quotes around $@
[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 RC='0'
41 PROG="$1"
42
43 # make sure to support 'grml-exec-wrapper sudo wireshark' as well:
44 case $PROG in
45         *sudo*) PROG="$2" ;;
46 esac
47
48 if is_installed "$PROG" ; then
49     exec "$@"
50 else
51     RC=1
52     display_info "Sorry: ${PROG} not available.
53
54 Looks like the grml flavour you are using does not ship ${PROG}. :(
55
56 You can search for ${PROG} executing:
57
58 apt-get update && apt-cache search ${PROG}
59     "
60 fi
61
62 exit $RC
63
64 ## END OF FILE #################################################################