forked from bmoffit/coda_scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
coda_conf_functions
104 lines (86 loc) · 2.23 KB
/
coda_conf_functions
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*-Shell-script-*-
#
# coda_conf_functions
# This file contains functions to be used to parse a coda component
# config file.
#
# Currently parses
# CODA_COMPONENT_TABLE
# Provides variables
# CODA_COMPONENT_NAME
# CODA_COMPONENT_OPTION
# CODA_HOSTMAME_LIST
#
#
if [ -z $CODA ]; then
echo "ERROR: CODA environment variable not defined!"
exit -1
fi
if [ -z $CODA_COMPONENT_TABLE ]; then
echo "ERROR: CODA_COMPONENT_TABLE environment variable not defined!"
exit -1
fi
# check for the existance of the config CODA_COMPONENT_TABLE
if [ ! -f $CODA_COMPONENT_TABLE ]; then
echo "ERROR: CODA_COMPONENT_TABLE not found!"
exit -1
fi
#
# codaconf_get_component_name hostname type
#
# return the component name
#
codaconf_get_component_name() {
local component_hostname=$1
local component_type=$2
local component_name=
CODA_COMPONENT_NAME=
component_name=$(sed -n -r \
"s/^$component_hostname\s+$component_type\s+(\S*).*$/\1/p" \
$CODA_COMPONENT_TABLE)
if [ -n "$component_name" ]; then
CODA_COMPONENT_NAME=$component_name
return 1
fi
echo ERROR: Component Name not found for hostname=$component_hostname, type=$component_type
return 0
}
#
# codaconf_get_name_option hostname name
#
# return the component name's option
#
codaconf_get_name_option() {
local component_hostname=$1
local component_name=$2
local component_option=
CODA_COMPONENT_OPTION=
component_option=$(sed -n -r \
"s/^$component_hostname\s+\S+\s+$component_name\s+(.*)$/\1/p" \
$CODA_COMPONENT_TABLE)
if [ -n "$component_option" ]; then
CODA_COMPONENT_OPTION=$component_option
return 1
fi
# echo ERROR: Component Option not found for hostname=$component_hostname, name=$component_name
return 0
}
#
# coda_conf_get_component_list type
#
# return a list (array) of hostnames matching type
#
coda_conf_get_component_list() {
local component_type=$1
local hostname_list=
CODA_HOSTMAME_LIST=
hostname_list=$(sed -n -r \
"s/^(\S+)\s+$component_type\s+.*$/\1/p" \
$CODA_COMPONENT_TABLE)
if [ -n "$hostname_list" ]; then
CODA_HOSTNAME_LIST=($hostname_list)
return 1
fi
# echo ERROR: Hostnames not found for type=$component_type
return 0
}