summaryrefslogtreecommitdiffstats
path: root/00-base/functions.sh
blob: 8523da7608d99c0ac5395ede9ce250c67be7c434 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash

exec 3>&1

function check_var() {
    if [ -z "$(eval "echo \$$1")" ]; then
        echo "$1 not defined."
        return 1
    fi

    return 0
}

function check_vars() {
    retval=0

    while [ $# -gt 0 ]; do
        retval=$(( $(check_var $1 >&3; echo $?) + ${retval} ))
        shift
    done

    return ${retval}
}

function domain_to_root_dn() {
    echo "dc=$(echo $1 | sed -e 's/\./,dc=/g')"
}

function persist() {
    while [ $# -gt 0 ]; do
        if [ ! -d "/data$(dirname $1)" ]; then
            mkdir -p "/data$(dirname $1)"
        fi

        echo -n "mv: "; mv -v $1 "/data$(dirname $1)"
        echo -n "ln: "; ln -svf "/data$1" "$(dirname $1)/$(basename $1)"

        shift
    done
}