forked from edseymour/ose-auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
executable file
·159 lines (117 loc) · 3.51 KB
/
functions.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
config_file=.config/ose-auto.config
function parse_value {
param=$1
value=$2
case $param in
-c | --config)
config_file=$value
echo "using configuration: $value"
;;
-t | --target)
target=$value
echo "using specific target: $target"
;;
*)
if [[ ! "$value" == "" ]] && [[ "$param" == "--"* ]] ; then
eval "${param#-*-}='$value'"
echo "setting ${param#-*-}=$value"
else
echo "unknown command $param"
show_help
fi
;;
esac
}
function show_help {
echo "Usage: $0 [options]
-c, --config <file> path to configuration file
-h, --help this message
-t, --target <fqdn> fully qualified domain name for a specific target server
--master <host> hostname of an OpenShift master, can be short name if --domain is also specified
--domain <zone> common public domain name of hosts
--hosts \"host1...\" list of OpenShift hostnames, can be short names if --domain is also specified
Default configuration file is $config_file
Configuration file format:
# --------------------------------
ident=<path to aws certificate>
rhnu=<rhn user id>
rhnp=<rhn password>
pool=<subscription pool id>
ssh_user=<user name, e.g. ec2-user>
domain=<EC2 domain>
master=\"<master>\"
hosts=\"<host1> <host2> ... <hostn>\"
# --------------------------------"
}
function validate_config
{
param=$1
eval value=\$"$param"
[ "$value" == "" ] && echo "No value for $param provided, pass value --$param=<value> $2" && exit 1
}
function optional_config
{
echo "Note: optional configuration option --$1 - $2"
}
function validate_config_rhn()
{
[ "$rhnu" == "" ] && echo "No RHN user id provided" && show_help && exit 1
[ "$rhnp" == "" ] && echo "No RHN password provided" && show_help && exit 1
[ "$pool" == "" ] && echo "No RHN pool provided" && show_help && exit 1
}
function validate_config_default()
{
[ "$ssh_user" == "" ] && echo "No ssh user id provided" && show_help && exit 1
[ "$domain" == "" ] && echo "Warning: no domain provided, expect hosts with FQDN"
[ "$hosts" == "" ] && echo "Warning: No hosts provided, use --hosts, or --target"
}
function validate_config_master()
{
[ "$master" == "" ] && echo "No master host provided" && show_help && exit 1
}
function scmd {
ssh -n -i $ident -o IPQoS=throughput -tt -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=QUIET "$@"
}
function sscp {
scp -i $ident -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=QUIET "$@"
}
function gen_fqdn {
if [ "${domain}" == "" ]
then
fqdn=$1
else
fqdn="$1.$domain"
fi
echo $fqdn
}
for var in "$@"
do
if [[ $var == -* ]]; then
if [[ "$var" == *"="* ]]; then
param=$(echo ${var} | cut -d "=" -f 1)
val=$(echo ${var} | cut -d "=" -f 2)
parse_value ${param} "${val}"
else
case $var in
-h | --help) show_help
;;
*) last=$var
esac
fi
else
if [ "$last" == "" ] ; then
echo "unknown command: $var"
show_help
else
parse_value ${last} "${var}"
fi
last=
fi
done
[ ! -f $config_file ] && echo "No configuration found $config_file" && show_help && exit 1
source "$config_file"
validate_config_default
echo "***********************************************************************
Starting process "$(date)"
"