r3562@krups: intrigeri | 2005-11-16 20:20:16 +0100
[matthijs/upstream/backupninja.git] / lib / tools.in
1 #!@BASH@
2
3 # This file contains functions shared between ninjahelper and backupninja.
4
5 #####################################################
6 ## MISC FUNCTIONS
7
8 #
9 # create a temporary file in a secure way.
10 #
11 function maketemp() {
12         if [ -x /bin/mktemp ]
13         then
14                 local tempfile=`mktemp /tmp/$1.XXXXXXXX`
15         else
16                 DATE=`date`
17                 sectmp=`echo $DATE | /usr/bin/md5sum | cut -d- -f1`
18                 local tempfile=/tmp/$1.$sectmp
19         fi
20         echo $tempfile
21 }
22
23 #####################################################
24 ## CONFIG-FILE RELATED FUNCTIONS
25
26 function setfile() {
27         CURRENT_CONF_FILE=$1
28 }
29
30 function setsection() {
31         CURRENT_SECTION=$1
32 }
33
34 #
35 # sets a global var with name equal to $1
36 # to the value of the configuration parameter $1
37 # $2 is the default.
38
39 function getconf() {
40         CURRENT_PARAM=$1
41         ret=`awk -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE`
42         # if nothing is returned, set the default
43         if [ "$ret" == "" -a "$2" != "" ]; then
44                 ret="$2"
45         fi
46
47         # replace * with %, so that it is not globbed.
48         ret="${ret//\\*/__star__}"
49
50         # this is weird, but single quotes are needed to 
51         # allow for returned values with spaces. $ret is still expanded
52         # because it is in an 'eval' statement.
53         eval $1='$ret'
54 }