summaryrefslogtreecommitdiffstats
path: root/00-base/functions.sh
blob: ea910f33139bdc9345ca054226d7a7b942433aab (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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 configure_timezone() {
    if [ -f "/usr/share/zoneinfo/$1" ]; then
        timezone=$1
    else
        echo "WARNING: Invalid timezone $1, using UTC"
        timezone="UTC"
    fi

    ln -vf \
        /usr/share/zoneinfo/${timezone} \
        /etc/localtime

    if [ -f "/etc/php.ini" ]; then
        sed -i -r \
            -e '/^date.timezone/d' \
            -e '/^;date.timezone/d' \
            -e "s|\[Date\]|[Date]\ndate.timezone = ${timezone}|g" \
            /etc/php.ini
    fi
}

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
}