-
Notifications
You must be signed in to change notification settings - Fork 24
/
autogenerate.sh
executable file
·314 lines (274 loc) · 9.63 KB
/
autogenerate.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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
# installation of the recommended dependencies
set +x
dir=`dirname $0`
remove_docker_workaround () {
l="$(echo -e "${@}" | sed -e 's/^[[:space:]]*//')"
l="$(echo -e "${l}" | sed -e 's/^if.*!.*then//' )"
l="$(echo -e "${l}" | sed -e '/^if.*docker.*then/,/else/d' )"
l="$(echo -e "${l}" | sed -e 's/^fi//')"
echo "${l}"
}
#generate the walkthrough for all supported os
function generate_all() {
values=(ubuntu2004 ubuntu2204 rocky9)
for os in "${values[@]}"; do
echo "${os}"
generate ${os}
done
}
# generate the specified walkthrough
function generate() {
OS=$1
file=walkthrough_$OS.sh
if [ -e $file ]; then
rm $file
fi
cat <<EOF > $file
#!/bin/bash
set -e -u -x
EOF
N=$OS
if [[ $OS =~ "ubuntu" ]] ; then
N="ubuntu"
elif [[ $OS =~ "rocky" ]] ; then
N="rocky"
fi
echo -en '\n' >> $file
if ! [[ $OS =~ "rocky" ]] ; then
echo "#start-step01: As root, install dependencies" >> $file
line=$(sed -n '2,$p' $dir/step01_"$N"_init.sh)
echo "$line" >> $file
fi
# install java
N=$OS
if [[ $OS =~ "ubuntu1804" ]] ; then
N="ubuntu1804"
elif [[ $OS =~ "ubuntu" ]] ; then
N="ubuntu"
fi
echo -en '\n' >> $file
echo "# install Java" >> $file
if [[ $OS =~ "rocky" ]] ; then
number=$(sed -n '/#start-recommended-java/=' $dir/step01_rocky9_deps.sh)
ns=$((number+1))
number=$(sed -n '/#end-recommended-java/=' $dir/step01_rocky9_deps.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step01_rocky9_deps.sh)
else
number=$(sed -n '/#start-recommended/=' $dir/step01_"$N"_java_deps.sh)
ns=$((number+1))
number=$(sed -n '/#end-recommended/=' $dir/step01_"$N"_java_deps.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step01_"$N"_java_deps.sh)
fi
# remove leading whitespace
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
echo -en '\n' >> $file
echo "# install dependencies" >> $file
# install dependencies
N=$OS
if [[ $OS =~ "ubuntu" ]] ; then
N="ubuntu1804"
fi
if [[ $OS =~ "rocky" ]] ; then
number=$(sed -n '/#start-general/=' $dir/step01_rocky9_deps.sh)
ns=$((number+1))
number=$(sed -n '/#end-general/=' $dir/step01_rocky9_deps.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step01_rocky9_deps.sh)
else
line=$(sed -n '2,$p' $dir/step01_"$N"_deps.sh)
fi
echo "$line" >> $file
echo "#end-step01" >> $file
# install ice
echo "# install Ice" >> $file
N=$OS
echo "#start-recommended-ice" >> $file
if [[ $OS =~ "rocky" ]] ; then
number=$(sed -n '/#start-recommended-ice/=' $dir/step01_rocky9_deps.sh)
ns=$((number+1))
number=$(sed -n '/#end-recommended-ice/=' $dir/step01_rocky9_deps.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step01_rocky9_deps.sh)
else
number=$(sed -n '/#start-recommended/=' $dir/step01_"$N"_ice_deps.sh)
ns=$((number+1))
number=$(sed -n '/#end-recommended/=' $dir/step01_"$N"_ice_deps.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step01_"$N"_ice_deps.sh)
# remove leading whitespace
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
fi
echo "$line" >> $file
echo "#end-recommended-ice" >> $file
echo -en '\n' >> $file
# install postgres
N=$OS
echo -en '\n' >> $file
echo "# install Postgres" >> $file
if [[ $OS =~ "rocky" ]] ; then
number=$(sed -n '/#start-pg-enabling/=' $dir/step01_rocky9_deps.sh)
nrs=$((number+1))
number=$(sed -n '/#end-pg-enabling/=' $dir/step01_rocky9_deps.sh)
nre=$((number-1))
line=$(sed -n ''$nrs','$nre'p' $dir/step01_rocky9_deps.sh)
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
number=$(sed -n '/#start-recommended-postgres/=' $dir/step01_rocky9_deps.sh)
nrs=$((number+1))
number=$(sed -n '/#end-recommended-postgres/=' $dir/step01_rocky9_deps.sh)
nre=$((number-1))
line=$(sed -n ''$nrs','$nre'p' $dir/step01_rocky9_deps.sh)
# remove docker conditional
line=`remove_docker_workaround "${line}"`
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
number=$(sed -n '/#start-recommended-pg-start/=' $dir/step01_rocky9_deps.sh)
nrs=$((number+1))
number=$(sed -n '/#end-recommended-pg-start/=' $dir/step01_rocky9_deps.sh)
nre=$((number-1))
line=$(sed -n ''$nrs','$nre'p' $dir/step01_rocky9_deps.sh)
# remove docker conditional
line=`remove_docker_workaround "${line}"`
else
number=$(sed -n '/#start-recommended/=' $dir/step01_"$N"_pg_deps.sh)
ns=$((number+1))
number=$(sed -n '/#end-recommended/=' $dir/step01_"$N"_pg_deps.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step01_"$N"_pg_deps.sh)
fi
N=$OS
# remove leading whitespace
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
echo "#end-step01" >> $file
echo -en '\n' >> $file
echo "#start-step02: As root, create a local omero-server system user and directory for the OMERO repository" >> $file
number=$(sed -n '/#start-create-user/=' $dir/step02_all_setup.sh)
ns=$((number+1))
number=$(sed -n '/#end-create-user/=' $dir/step02_all_setup.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step02_all_setup.sh)
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
ne=$((number+3))
line=$(sed -n ''$ne',$p' $dir/step02_all_setup.sh)
echo "$line" >> $file
echo "#end-step02" >> $file
# postgres remove section
echo "#start-step03: As root, create a database user and a database" >> $file
#find from where to start copying
start=$(sed -n '/#start-setup/=' $dir/step03_all_postgres.sh)
start=$((start+1))
line=$(sed -n ''$start',$p' $dir/step03_all_postgres.sh)
echo "$line" >> $file
echo "#end-step03" >> $file
# create virtual env and install dependencies
echo -en '\n' >> $file
echo "#start-step03bis: As root, create a virtual env and install dependencies" >> $file
number=$(sed -n '/#start-ice-py/=' $dir/step01_"$OS"_ice_venv.sh)
ns=$((number+1))
number=$(sed -n '/#end-ice-py/=' $dir/step01_"$OS"_ice_venv.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step01_"$OS"_ice_venv.sh)
echo "$line" >> $file
echo "#end-step03bis" >> $file
echo -en '\n' >> $file
echo "#start-step04-pre: As root, download the OMERO.server" >> $file
echo "#start-release-ice36" >> $file
number=$(sed -n '/#start-release-ice36/=' $dir/step04_all_omero_install.sh)
ns=$((number+1))
number=$(sed -n '/#end-release-ice36/=' $dir/step04_all_omero_install.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step04_all_omero_install.sh)
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
echo "#end-release-ice36" >> $file
number=$(sed -n '/#start-link/=' $dir/step04_all_omero_install.sh)
ns=$((number+1))
number=$(sed -n '/#end-link/=' $dir/step04_all_omero_install.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step04_all_omero_install.sh)
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
echo "#end-step04-pre" >> $file
echo -en '\n' >> $file
echo "#start-step04: As the omero-server system user, configure it" >> $file
echo "#start-copy-omeroscript" >> $file
echo "cp settings.env step04_all_omero.sh setup_omero_db.sh ~omero " >> $file
echo "#end-copy-omeroscript" >> $file
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
number=$(sed -n '/#configure/=' $dir/step04_all_omero.sh)
ns=$((number+1))
number=$(sed -n '/#start-db/=' $dir/step04_all_omero.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step04_all_omero.sh)
echo "$line" >> $file
number=$(sed -n '/#start-deb-latest/=' $dir/step04_all_omero.sh)
ns=$((number+1))
number=$(sed -n '/#end-deb-latest/=' $dir/step04_all_omero.sh)
ne=$((number-1))
line=$(sed -n ''$ns','$ne'p' $dir/step04_all_omero.sh)
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
number=$(sed -n '/#start-config/=' $dir/setup_omero_db.sh)
ns=$((number+1))
line=$(sed -n ''$ns',$p' $dir/setup_omero_db.sh)
echo "$line" >> $file
echo "#end-step04" >> $file
number=$(sed -n '/#start-seclevel/=' $dir/step04_all_omero.sh)
ns=$((number))
number=$(sed -n '/#end-seclevel/=' $dir/step04_all_omero.sh)
ne=$((number))
line=$(sed -n ''$ns','$ne'p' $dir/step04_all_omero.sh)
line=$(echo -e "${line}" | sed -e "s/\-i.bak/-i/g")
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
echo -en '\n' >> $file
echo -en '\n' >> $file
echo "#start-step06: As root, run the scripts to start OMERO automatically" >> $file
number=$(sed -n '/#start-recommended/=' $dir/step06_ubuntu_daemon.sh)
nrs=$((number+1))
number=$(sed -n '/#end-recommended/=' $dir/step06_ubuntu_daemon.sh)
nre=$((number-1))
line=$(sed -n ''$nrs','$nre'p' $dir/step06_ubuntu_daemon.sh)
echo "$line" >> $file
echo "#end-step06" >> $file
echo -en '\n' >> $file
echo "#start-step07: As root, secure OMERO" >> $file
start=$(sed -n '/#start/=' $dir/step07_all_perms.sh)
start=$((start+1))
line=$(sed -n ''$start',$p' $dir/step07_all_perms.sh)
echo "$line" >> $file
echo "#end-step07" >> $file
if [[ $OS =~ "rocky" ]]; then
echo "#start-step08: As root, configure" >> $file
number=$(sed -n '/#start-recommended/=' $dir/step08_rocky9_config.sh)
nrs=$((number+1))
number=$(sed -n '/#end-recommended/=' $dir/step08_rocky9_config.sh)
nre=$((number-1))
line=$(sed -n ''$nrs','$nre'p' $dir/step08_rocky9_config.sh)
# remove docker conditional
line=`remove_docker_workaround "${line}"`
echo "$line" >> $file
number=$(sed -n '/#start-open-omero-server-port/=' $dir/step08_rocky9_config.sh)
nrs=$((number+1))
number=$(sed -n '/#end-open-omero-server-port/=' $dir/step08_rocky9_config.sh)
nre=$((number-1))
line=$(sed -n ''$nrs','$nre'p' $dir/step08_rocky9_config.sh)
line="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//')"
echo "$line" >> $file
echo "#end-step08" >> $file
fi
}
#generate scripts for all os by default.
ALL=${ALL:-true}
OS=${OS:-rocky9}
if [ $ALL = true ]; then
generate_all
else
generate $OS
fi