-
Notifications
You must be signed in to change notification settings - Fork 28
/
sem-service-check-params
239 lines (226 loc) · 6.55 KB
/
sem-service-check-params
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env bash
params-check::mysql () {
default_params='--net=host --rm -d -v /var/tmp/mysql:/var/lib/mysql --name mysql -v /var/run/mysqld:/var/run/mysqld '
service_version="5.6"
sudo mkdir -p /var/run/mysqld && sudo chmod -R 0777 /var/run/mysqld
sudo mkdir -p /var/tmp/mysqld && sudo chmod -R 0777 /var/tmp/mysqld
params=""
local password="";
local username="";
local db=" -e MYSQL_DATABASE=test ";
if [ "${1:0:1}" == "-" ];then
params="$@"
else
service_version="${1:-$service_version}"
tmp="${@:2}"
params="${tmp:-$default_params}"
fi
if [ "$default_params" != "$params" ];then
for words in $params; do
case $words in
--username=* )
username="$(echo $words|cut -d'=' -f2)"
;;
--password=* )
password="$(echo $words|cut -d'=' -f2)"
;;
--db=* )
db=" -e MYSQL_DATABASE=$(echo $words|cut -d'=' -f2) "
;;
*)
;;
esac
done
fi
if [ "$username" = "" ] || [ "$username" = "root" ]; then
username=""
if [ "$password" ]; then
password=" -e MYSQL_ROOT_PASSWORD=$password "
else
password=" -e MYSQL_ALLOW_EMPTY_PASSWORD=yes "
fi
else
username=" -e MYSQL_USER=$username "
password=" -e MYSQL_PASSWORD=$password -e MYSQL_ALLOW_EMPTY_PASSWORD=yes "
fi
default_params="$default_params$username$password$db "
echo "$service_version $default_params"
}
params-check::postgres () {
default_params='--net=host --rm -d -e POSTGRES_PASSWORD=semaphore --name postgres -v /var/tmp/postgres:/var/lib/postgresql/data -v /var/run/postgresql:/var/run/postgresql'
service_version="9.6"
sudo mkdir -p /var/run/postgresql && sudo chmod -R 0777 /var/run/postgresql
sudo mkdir -p /var/tmp/postgres && sudo chmod -R 0777 /var/tmp/postgres
params=""
if [ "${1:0:1}" == "-" ];then
params="$@"
else
service_version="${1:-$service_version}"
tmp="${@:2}"
params="${tmp:-$default_params}"
fi
if [ "$default_params" != "$params" ];then
username=""; password=""; db=""; dbname="";
for words in $params; do
case $words in
--username=* )
username=" -e POSTGRES_USER=$(echo $words|cut -d'=' -f2) "
;;
--password=* )
password=$(echo $words|cut -d'=' -f2)
password=" -e POSTGRES_PASSWORD=${password:-'postgres'}"
;;
--db=* )
dbname=$(echo $words|cut -d'=' -f2)
;;
*)
;;
esac
done
[ "$dbname" ] && db=" -e POSTGRES_DB=$dbname"
[ "$username$password" ] && default_params="$default_params$username$password$db "
fi
echo "$service_version $default_params"
}
params-check::postgis () {
default_params='--net=host --rm -d -e POSTGRES_PASSWORD=semaphore --name postgis -v /var/tmp/postgres:/var/lib/postgresql/data -v /var/run/postgresql:/var/run/postgresql'
service_version="9.6-2.5"
sudo rm -rf /var/run/postgresql /var/tmp/postgres
sudo mkdir -p /var/run/postgresql && sudo chmod -R 0777 /var/run/postgresql
sudo mkdir -p /var/tmp/postgres && sudo chmod -R 0777 /var/tmp/postgres
params=""
if [ "${1:0:1}" == "-" ];then
params="$@"
else
service_version="${1:-$service_version}"
tmp="${@:2}"
params="${tmp:-$default_params}"
fi
if [ "$default_params" != "$params" ];then
username=""; password=""; db=""; dbname="";
for words in $params; do
case $words in
--username=* )
username=" -e POSTGRES_USER=$(echo $words|cut -d'=' -f2) "
;;
--password=* )
password=$(echo $words|cut -d'=' -f2)
password=" -e POSTGRES_PASSWORD=${password:-'semaphore'}"
;;
--db=* )
dbname=$(echo $words|cut -d'=' -f2)
;;
*)
;;
esac
done
[ "$dbname" ] && db=" -e POSTGRES_DB=$dbname"
[ "$username$password" ] && default_params="$default_params$username$password$db "
fi
echo "$service_version $default_params"
}
params-check::redis () {
default_params='--net=host --rm --name redis -d -v /var/tmp/redis:/data'
service_version="4.0"
sudo mkdir -p /var/tmp/redis && sudo chmod -R 0777 /var/tmp/redis
params=""
if [ "${1:0:1}" == "-" ];then
params="$@"
else
service_version="${1:-$service_version}"
tmp="${@:2}"
params="${tmp:-$default_params}"
fi
echo "$service_version $default_params"
}
params-check::mongodb () {
default_params='--net=host --rm --name mongodb -d -v /var/tmp/mongodb:/home/mongo'
sudo mkdir -p /var/tmp/mongodb && sudo chmod -R 0777 /var/tmp/mongodb
service_version="4.1"
params=""
if [ "${1:0:1}" == "-" ];then
params="$@"
else
service_version="${1:-$service_version}"
tmp="${@:2}"
params="${tmp:-$default_params}"
fi
if [ "$default_params" != "$params" ];then
username=""; password=""
for words in $params; do
case $words in
--username=* )
username=$(echo $words|cut -d'=' -f2)
[ "$username" ] && username=" -e MONGO_INITDB_ROOT_USERNAME=$username "
;;
--password=* )
password=$(echo $words|cut -d'=' -f2)
[ "$password" ] && password=" -e MONGO_INITDB_ROOT_PASSWORD=$password "
;;
*)
;;
esac
done
default_params="$default_params$username$password "
fi
echo "$service_version $default_params"
}
params-check::elasticsearch () {
local defaultEnv="-e 'discovery.type=single-node'"
service_version="6.5"
if [ "${1:0:1}" != "-" ];then
service_version="${1:-$service_version}"
shift
fi
defaultEnv="$defaultEnv $*"
default_params=$(echo "docker run --net=host --rm --name elasticsearch -d $defaultEnv "|base64 --wrap=0)
echo "$service_version $default_params"
}
params-check::opensearch () {
local defaultEnv="-e 'discovery.type=single-node'"
service_version="2"
if [ "${1:0:1}" != "-" ];then
service_version="${1:-$service_version}"
shift
fi
defaultEnv="$defaultEnv $*"
default_params=$(echo "docker run --net=host --rm --name opensearch -d $defaultEnv "|base64 --wrap=0)
echo "$service_version $default_params"
}
params-check::main () {
case "$1" in
"mysql" )
shift
params-check::mysql $@
;;
"postgres" )
shift
params-check::postgres $@
;;
"postgis" )
shift
params-check::postgis $@
;;
"redis" )
shift
params-check::redis $@
;;
"mongodb" )
shift
params-check::mongodb $@
;;
"elasticsearch" )
shift
params-check::elasticsearch $@
;;
"opensearch" )
shift
params-check::opensearch $@
;;
* )
shift
echo "$@"
;;
esac
}
params-check::main "$@"