-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.lib.sh
executable file
·74 lines (62 loc) · 2.09 KB
/
config.lib.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
################################################################################
# config.lib.sh - Bash library functions related to config validation
################################################################################
#
# Copyright (C) 2013 stepping stone GmbH
# Bern, Switzerland
# http://www.stepping-stone.ch
#
# Authors:
# Christian Affolter <[email protected]>
#
# Licensed under the EUPL, Version 1.1.
#
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://www.osor.eu/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
################################################################################
# The path to the lib directory.
# The default value only works if not sourced or executed from within $PATH
LIB_DIR=${LIB_DIR:="$(readlink -f ${0%/*})"}
source "${LIB_DIR}/input-output.lib.sh"
function configLoadConfig ()
{
local configPath="$1"
if [ ! -f "${configPath}" ]; then
die "Missing config file: ${configPath}"
fi
if [ ! -r "${configPath}" ]; then
die "Not enough permissions to read config file: ${configPath}"
fi
debug "Loading variables from ${configPath}"
source "${configPath}"
}
function configIsParameterValuePresent ()
{
local parameterName="$1"
debug "Check if parameter '${parameterName}' is present"
local parameterValue="${!parameterName}"
debug "Value of ${parameterName}: '${parameterValue}'"
test -n "$parameterValue"
return $?
}
function configDieIfValueNotPresent ()
{
local parameterName="$1"
if ! configIsParameterValuePresent "${parameterName}"; then
die "Missing config parameter '${parameterName}', unable to proceed"
fi
}