-
Notifications
You must be signed in to change notification settings - Fork 2
/
miracle.sh
387 lines (297 loc) · 10.9 KB
/
miracle.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/usr/bin/env bash
# Miracle installer v0.4.2
# Copyright (c) 2017 Paweł Kierzkowski
# License: MIT
# Home: https://github.com/4O4/miracle
# Format strings
readonly INSTALLATION_STARTED_FORMAT="\n\e[4;92m%s\e[m\n\n"
readonly INSTALLATION_FINISHED_FORMAT="\n\e[4;92m%s\e[m\n\n"
readonly CONFIRM_GROUP_FORMAT="\n %s"
readonly CONFIRM_ELEMENT_FORMAT=" - \e[96m%s\e[m"
# Ugly globals
processed_elements=0
# Trapped magic
main() {
trap 'set +x; error ${LINENO}' ERR
printf -- "--------------------------------------------------\n"
printf -- " Miracle installer v0.4.2 by PK\n"
printf -- "--------------------------------------------------\n"
if [[ -z ${username} ]] || [[ -z ${password} ]]; then
printf "Missing username or password!\n\n"
return;
fi;
if [ ${#views[@]} -gt 0 ]; then
install_with_sqlplus "${CONFIRM_GROUP_FORMAT} Do you want to install SQL views?" views[@] ";"
fi;
if [ ${#packages[@]} -gt 0 ]; then
install_with_sqlplus "${CONFIRM_GROUP_FORMAT} Do you want to install PL/SQL packages?" packages[@] "/"
fi;
if [ ${#ebs_functions[@]} -gt 0 ]; then
install_with_fndload "${CONFIRM_GROUP_FORMAT} Do you want to import EBS functions?" "afsload.lct" ebs_functions[@]
fi;
if [ ${#ebs_concurrent_programs[@]} -gt 0 ]; then
install_with_fndload "${CONFIRM_GROUP_FORMAT} Do you want to import EBS concurrent programs?" "afcpprog.lct" ebs_concurrent_programs[@]
fi;
if [ ${#ebs_profiles[@]} -gt 0 ]; then
install_with_fndload "${CONFIRM_GROUP_FORMAT} Do you want to import EBS profiles?" "afscprof.lct" ebs_profiles[@]
fi;
if [ ${#ebs_messages[@]} -gt 0 ]; then
install_ebs_messages "${CONFIRM_GROUP_FORMAT} Do you want to import EBS messages?" ebs_messages[@]
fi;
if [ ${#forms_libraries[@]} -gt 0 ]; then
if confirm "${CONFIRM_GROUP_FORMAT} Do you want to install Forms PL/SQL libraries?"; then
for i in "${forms_libraries[@]}"
do
library_path=${i}
library_full_filename=${i##*/}
library_filename=${library_full_filename%.*}
if [[ ! -z "${i}" ]] && confirm "${CONFIRM_ELEMENT_FORMAT}" "${i}"; then
printf "${INSTALLATION_STARTED_FORMAT}" "Installing ${i}..."
cp -f ${library_path} ${AU_TOP}/resource
frmcmp_batch.sh module=${AU_TOP}/resource/${library_full_filename} userid=${username}/${password} output_file=${AU_TOP}/resource/${library_filename}.plx module_type=library compile_all=special
printf "${INSTALLATION_FINISHED_FORMAT}" "Finished installing ${i}"
processed_elements=$((processed_elements + 1))
fi;
done
fi;
fi;
if [ ${#forms_modules[@]} -gt 0 ]; then
if confirm "${CONFIRM_GROUP_FORMAT} Do you want to install Forms modules?"; then
for i in "${forms_modules[@]}"
do
metadata=${i%;*}
form_language=${metadata%;*}
form_application=${metadata##*;}
form_path=${i##*;}
form_full_filename=${i##*/}
form_filename=${form_full_filename%.*}
the_top="${form_application}_TOP"
if [[ ! -z "${form_path}" ]] && confirm "${CONFIRM_ELEMENT_FORMAT}" "${form_path} (language: ${form_language}, application: ${form_application})"; then
printf "${INSTALLATION_STARTED_FORMAT}" "Installing ${form_path} (language: ${form_language}, application: ${form_application})..."
cp -f ${form_path} ${AU_TOP}/forms/${form_language}
env FORMS_PATH="${FORMS_PATH}:${AU_TOP}/forms/${form_language}" \
frmcmp_batch.sh module=${AU_TOP}/forms/${form_language}/${form_full_filename} userid=${username}/${password} output_file=${!the_top}/forms/${form_language}/${form_filename}.fmx module_type=form compile_all=special
printf "${INSTALLATION_FINISHED_FORMAT}" "Finished installing ${form_path} (language: ${form_language}, application: ${form_application})"
processed_elements=$((processed_elements + 1))
fi;
done
fi;
fi;
if [ ${#custom[@]} -gt 0 ]; then
install_custom_resources custom[@]
fi;
if [ "${processed_elements}" -gt 0 ]; then
print_stats
print_log_reminder
else
printf "\nNothing to do here, bye\n\n"
fi;
# Consider opening pull request on Github if you add or fix something, thanks!
}
confirm() {
while true; do
printf "$@"
read -p " [y/N] " yn
case ${yn} in
[Yy] ) return 0;;
* ) return 1;;
esac
done
}
print_stats() {
printf "\nProcessed ${processed_elements} elements\n"
}
print_log_reminder() {
printf "\n\n\n!!! Log saved to 'install.log' file, PLEASE ATTACH IT TO THE JIRA TASK !!!\n\n"
}
install_with_sqlplus() {
# trap 'set +x; error ${LINENO}' ERR
if [[ -z "$2" ]]; then return; fi;
local prompt_text="$1"
local config_array=("${!2}")
local command_terminator="$3"
if confirm "$1"; then
config_array=("${!2}")
for i in "${config_array[@]}"
do
if [[ ! -z "${i}" ]] && confirm "${CONFIRM_ELEMENT_FORMAT}" "${i}"; then
final_terminator="${command_terminator}"
# Avoid double command terminator
last_character="$(cat ${i} | remove_whitespace | tail -c 1)"
if [[ "${last_character}" = "${final_terminator}" ]]; then
final_terminator=""
fi;
show_errors_cmd="$(cat ${i} | remove_newline | grep -Pio 'create .*?(package|package body|view|procedure) .*?[i|a]s ' | perl -pe 's/create .*?(package body|package|view|procedure) .*?((["]?[a-z]{1,20}["]?\.)?["]?[a-zA-Z0-9_]{1,30}["]?) .*?[i|a]s /show errors \1 \2;/gi' | tr -d "\"")"
printf "MIRACLE INFO: show_errors_cmd: ${show_errors_cmd}\n\n"
printf "${INSTALLATION_STARTED_FORMAT}" "Installing ${i}..."
result=$(sqlplus -s ${username}/${password} <<-EOF
SET TERMOUT ON
SET SQLBLANKLINES ON
SET DEFINE OFF
SET ECHO ON
WHENEVER SQLERROR EXIT FAILURE
WHENEVER OSERROR EXIT FAILURE
@${i}
${final_terminator}
show errors
${show_errors_cmd}
EOF
)
sqlplus_exit_code=$?
printf "${result}"
if [[ ! ${sqlplus_exit_code} -eq 0 ]] || [[ "${result}" == *"Errors for "* ]]; then
error ${LINENO}
fi
printf "${INSTALLATION_FINISHED_FORMAT}" "Finished installing ${i}"
processed_elements=$((processed_elements + 1))
fi;
done
fi;
}
run_fnd_command_verbose() {
if [[ -z "$1" ]]; then return; fi;
local cmd="$@"
result="$(${cmd} 2>&1)"
cmd_exit_code=$?
printf "${result}\n"
log_file_name="$(echo ${result} | grep 'Log' | sed 's/Log filename : \(.*\.log\).*/\1/')"
report_file_name="$(echo ${result} | grep 'Report' | sed 's/.*Report filename : \(.*\.out\).*/\1/')"
printf "\n"
if [[ -f "${log_file_name}" ]]; then
cat "${log_file_name}"
else
printf "MIRACLE INFO: File '${log_file_name}' does not exist\n"
fi;
printf "\n"
if [[ -f "${report_file_name}" ]]; then
cat "${report_file_name}"
else
printf "MIRACLE INFO: File '${report_file_name}' does not exist\n"
fi;
if [[ ! ${cmd_exit_code} -eq 0 ]]; then
error ${LINENO}
fi;
}
install_with_fndload() {
# No trap here because FNDLOAD log files should always be cat'ed.
# Error must be raised manually.
if [[ -z "$3" ]]; then return; fi;
local prompt_text="$1"
local fndload_script_name="$2"
local config_array=("${!3}")
if confirm "${prompt_text}"; then
for i in "${config_array[@]}"
do
if [[ ! -z "${i}" ]] && confirm "${CONFIRM_ELEMENT_FORMAT}" "${i}"; then
printf "${INSTALLATION_STARTED_FORMAT}" "Installing ${i}..."
run_fnd_command_verbose \
"FNDLOAD ${username}/${password} 0 Y UPLOAD ${FND_TOP}/patch/115/import/${fndload_script_name} ${i} UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE"
printf "${INSTALLATION_FINISHED_FORMAT}" "Finished installing ${i}"
processed_elements=$((processed_elements + 1))
fi;
done
fi;
}
install_ebs_messages() {
if [[ -z "$2" ]]; then return; fi;
local prompt_text="$1"
local config_array=("${!2}")
if confirm "${prompt_text}"; then
for i in "${config_array[@]}"
do
metadata=${i%;*}
language=${metadata%;*}
application=${metadata##*;}
messages_file_path=${i##*;}
if [[ ! -z "${messages_file_path}" ]] && confirm "${CONFIRM_ELEMENT_FORMAT}" "${messages_file_path} (language: ${language}, application: ${application})"; then
printf "${INSTALLATION_STARTED_FORMAT}" "Installing ${messages_file_path} (language: ${language}, application: ${application})..."
run_fnd_command_verbose \
"FNDLOAD ${username}/${password} 0 Y UPLOAD ${FND_TOP}/patch/115/import/afmdmsg.lct ${messages_file_path} UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE"
printf "\n"
printf "${INSTALLATION_STARTED_FORMAT}" "Generating messages (DB to Runtime)..."
run_fnd_command_verbose \
"FNDMDGEN ${username}/${password} 0 Y ${language} ${application} DB_TO_RUNTIME"
printf "${INSTALLATION_FINISHED_FORMAT}" "Finished installing ${messages_file_path} (language: ${language}, application: ${application})"
processed_elements=$((processed_elements + 1))
fi;
done
fi;
}
install_custom_resources() {
if [[ -z "$1" ]]; then return; fi;
local config_array=("${!1}")
local last_group_name=""
local last_group_confirmed=1
for i in "${config_array[@]}"
do
group_name=${i%%;*}
group_name=$(trim "${group_name}")
rest=${i#*;}
element_name=${rest%%;*}
element_name=$(trim "${element_name}")
commands=${rest#*;}
if [[ ! -z "${commands}" ]] && [[ ! -z "${group_name}" ]]; then
if [ "${last_group_name}" == "${group_name}" ]; then
if [[ ${last_group_confirmed} -eq 0 ]]; then
confirmed_group=0
fi;
else
confirm "${CONFIRM_GROUP_FORMAT}" "Do you want to install ${group_name}?"
confirmed_group=$?
fi;
last_group_name="${group_name}"
last_group_confirmed=${confirmed_group}
if [[ ${confirmed_group} -eq 0 ]]; then
if [[ ${#config_array[@]} -eq 1 ]] && [[ -z "${element_name}" ]]; then
confirmed_element=0
else
confirm "${CONFIRM_ELEMENT_FORMAT}" "${element_name}"
confirmed_element=$?
fi;
if [[ ${confirmed_element} -eq 0 ]]; then
printf "${INSTALLATION_STARTED_FORMAT}" "Installing ${group_name}${element_name:+ -> ${element_name}}..."
printf "MIRACLE INFO: Commands to execute: ${commands}\n\n"
result="$(${commands} 2>&1)"
cmd_exit_code=$?
printf "${result}\n"
if [[ ! ${cmd_exit_code} -eq 0 ]]; then
error ${LINENO}
fi;
printf "${INSTALLATION_FINISHED_FORMAT}" "Finished installing ${element_name:-${group_name}}"
processed_elements=$((processed_elements + 1))
fi;
fi;
fi;
done
}
trim() {
echo "$@" | xargs
}
remove_whitespace() {
dos2unix | tr -d "[:space:]"
}
remove_newline() {
dos2unix | tr "\n" " "
}
error() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
echo -n -e "\n\n$(basename ${BASH_SOURCE[0]}): \033[0;31m"
if [[ -n "$message" ]] ; then
echo "Error near line ${parent_lineno}: ${message}; exiting with status ${code}"
else
echo "Error near line ${parent_lineno}; exiting with status ${code}"
fi
echo -e "\033[0m"
print_stats
print_log_reminder
exit "${code}"
}
# Log rotation
if [ -f "install.log" ]; then
mv "install.log" "install_$(date +%Y-%m-%d_%H-%M-%S -r install.log).log"
fi
# Stdout + logging
exec &> >(tee -a >(sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' > "install.log"))
main