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