cecho changes in UML scripts
[strongswan.git] / testing / scripts / function.sh
1 #!/bin/bash
2 # provides some general-purpose script functions
3 #
4 # Copyright (C) 2004 Eric Marchionni, Patrik Rayo
5 # Zuercher Hochschule Winterthur
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
16 #
17 # RCSID $Id: function.sh,v 1.3 2005/02/16 22:20:52 as Exp $
18
19
20 ############################################
21 # print output in color
22 #
23
24 function cecho {
25 echo -e "\033[1;31m$1\033[0m"
26 }
27
28 function cecho-n {
29 echo -en "\033[1;31m$1\033[0m"
30 }
31
32
33 #############################################
34 # output all args to stderr and exit with
35 # return code 1
36 #
37
38 die() {
39 echo $* 1>&2
40 exit 1
41 }
42
43 #############################################
44 # search and replace strings throughout a
45 # whole directory
46 #
47
48 function searchandreplace {
49
50 SEARCHSTRING="$1"
51 REPLACESTRING="$2"
52 DESTDIR="$3"
53
54 [ -d "$DESTDIR" ] || die "$DESTDIR is not a directory!"
55
56
57 #########################
58 # create a temporary file
59 #
60
61 TMPFILE="/tmp/sr.$$"
62
63
64 ###########################################
65 # search and replace in each found file the
66 # given string
67 #
68
69 for eachfoundfile in `find $DESTDIR -type f`
70 do
71 sed -e "s/$SEARCHSTRING/$REPLACESTRING/g" "$eachfoundfile" > "$TMPFILE"
72 cp -f "$TMPFILE" "$eachfoundfile"
73 done
74
75
76 ###########################
77 # delete the temporary file
78 #
79
80 rm -f "$TMPFILE"
81
82 }