site: end of line message, adesklets is not dead.
[adesklets.git] / scripting / wrapper.sh
blob85f75724744aceb639b44e148fef041b58d27d44
1 #! /bin/sh
3 # wrapper.sh
5 #-------------------------------------------------------------------------------
6 # Copyright (C) 2004, 2005, 2006 Sylvain Fourmanoit <syfou@users.sourceforge.net>
7 #
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to
10 # deal in the Software without restriction, including without limitation the
11 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 # sell copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be included in
16 # all copies of the Software and its documentation and acknowledgment shall be
17 # given in the documentation and software packages that this Software was
18 # used.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #-------------------------------------------------------------------------------
28 # Wrapper script between Makefile and other scripts. Usage:
30 # ./wrapper.sh my_script out_file
32 # Redirect my_script stdout to out_file. If script fails, remove out_file.
33 # If script is not in current working directory, script name need to be
34 # absolute. Always echo script exit status, and duplicate script stdout on
35 # ./wrapper.sh' stderr
37 #-------------------------------------------------------------------------------
38 if test "x$1" != "x" ; then
39 if test "x$2" != "x" ; then
40 SCRIPT=`echo "$1" | sed '/^\//!s/^/\.\//'`
41 if test -x "$SCRIPT" ; then
42 if ! eval "$SCRIPT" | (
43 # This is a 'tee' emulator: demux the command output
44 # both on stdout and stderr
45 while read LINE; do
46 echo "$LINE"
47 echo "$LINE" 1>&2
48 done
49 ) >$2; then
50 rm -f $2 2> /dev/null
51 exit 1
53 else
54 echo "could not execute script '$SCRIPT'" 1>&2
55 exit 1
57 else
58 echo "output file name not given" 1>&2
59 exit 1
61 else
62 echo "script name not given" 1>&2
63 exit 1