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