-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunListUpdate.sh
236 lines (214 loc) · 9.62 KB
/
RunListUpdate.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
#!/bin/bash
#SQLLoops Update tool
#This script automates the application of SQL patches and scripts in active instances to Postgres
#Created by Robson Messias
#Last update date: 27/11/2019
export stag=$(hostname)
export env=$(hostname | cut -c -2)
export hostname=$(hostname)
declare -a DataBaseName
echo ""
echo "SQLLoops Runlists and database patches Update"
echo ""
if [ -e "./runlist" ]; then
echo "Checking if the folder runlist exist..."
echo "Folder runlist ---------------------------------------------------------> [ok]"
echo ""
else
echo "Something is wrong! The folder runlist does not exist or is empty!"
echo "Please, execute the SQLLoops.sh to create the runlist folder."
echo ""
exit 1
fi
echo -e '\033[36m'
echo -e "╔════════════════════════════════════════════════╗"
echo -e "║ Donwloading the runlists from Git Repository...║"
echo -e "╚════════════════════════════════════════════════╝"
echo -e '\033[0;0m'
TotalVar=$(cat DBnames | wc -l)
#Check if exist updates for the runlits in the git repository
if [[ $stag == "qadbstag9" ]] || [[ $stag == "qadbstag" ]]; then
if [[ $stag == "qadbstag" ]]; then
a=1
while [[ $a -le $TotalVar ]]; do
PreName=$(cat DBnames | sed -n "$a"'p')
DataBaseName[$a]=$PreName
checksumold=$(sha1sum runlist/${DataBaseName[$a]}.runlist)
echo -e "Updating runlist ${DataBaseName[$a]}\033[32m"
/usr/bin/curl -k --progress-bar --header "PRIVATE-TOKEN: Insert the private token here " https://pr-gb-ops-gitlab-01.stanleybet.com/DevOps/configcent/raw/galileoservice/scripts/runlist/stag/qadbstag/${DataBaseName[$a]}.runlist -o runlist/${DataBaseName[$a]}.runlist
checksumNew=$(sha1sum runlist/${DataBaseName[$a]}.runlist)
if [[ $checksumold == $checksumNew ]]; then
echo -e "\033[31m No changes detected on ${DataBaseName[$a]}.runlist \033[0;0m"
echo ""
else
echo -e "The file ${DataBaseName[$a]}.runlist was successfully updated! \033[0;0m"
echo ""
fi
((a++))
done
else
a=1
while [[ $a -le $TotalVar ]]; do
PreName=$(cat DBnames | sed -n "$a"'p')
DataBaseName[$a]=$PreName
checksumold=$(sha1sum runlist/${DataBaseName[$a]}.runlist)
echo -e "Updating runlist ${DataBaseName[$a]}\033[32m"
/usr/bin/curl -k --progress-bar --header "PRIVATE-TOKEN: Insert the private token here " https://pr-gb-ops-gitlab-01.stanleybet.com/DevOps/configcent/raw/galileoservice/scripts/runlist/stag/qadbstag9/${DataBaseName[$a]}.runlist -o runlist/${DataBaseName[$a]}.runlist
checksumNew=$(sha1sum runlist/${DataBaseName[$a]}.runlist)
if [[ $checksumold == $checksumNew ]]; then
echo -e "\033[31m No changes detected on ${DataBaseName[$a]}.runlist \033[0;0m"
echo ""
else
echo -e "The file ${DataBaseName[$a]}.runlist was successfully updated! \033[0;0m"
echo ""
fi
((a++))
done
fi
if [ -e "./patches" ]; then
echo "Checking if the folder patches exist..."
echo "Folder patches -----------------------------------------------------------> [ok]"
echo ""
else
echo "Something is wrong! The folder patches does not exist or is empty!"
echo "Please, execute the SQLLoops.sh to create the folder patches"
echo ""
exit 1
fi
#Procedure to update the patches
echo -e '\033[36m'
echo -e "╔════════════════════════════════════════════════╗"
echo -e "║ Donwloading the patches from Git Repository... ║"
echo -e "╚════════════════════════════════════════════════╝"
echo -e '\033[0;0m'
b=1
while [[ $b -le $TotalVar ]]; do
PreName=$(cat ./DBnames | sed -n "$b"'p')
cat runlist/$PreName.runlist >>list_tmp
echo -e "\n" >>list_tmp
((b++))
done
cat list_tmp | sed '/^$/d' | sort | uniq -d >list
cat list_tmp | sed '/^$/d' | sort | uniq --u >>list
chmod 755 list
rm list_tmp
Totalpatches=$(cat list | wc -l)
c=1
while [[ $c -le $Totalpatches ]]; do
patchesName=$(cat list | sed -n "$c"'p')
echo $patchesName
ChecksumOldPatch=$(sha1sum ./patches/$patchesName)
/usr/bin/curl -k --progress-bar --header "PRIVATE-TOKEN: Insert the private token here " https://pr-gb-ops-gitlab-01.stanleybet.com/DevOps/configcent/raw/galileoservice/scripts/patchs/$patchesName -o patches/$patchesName
ChecksumNewPatch=$(sha1sum ./patches/$patchesName)
if [ -e "./patches/$patchesName" ]; then
if [[ $ChecksumOldPatch == $ChecksumNewPatch ]]; then
echo -e "\033[31m No changes detected on $patchesName \033[0;0m"
echo ""
else
echo -e "\033[32m Patch successfully downloaded \033[0;0m"
fi
else
echo -e "\033[31m Error... the patch $patchesName not found \033[0;0m"
echo ""
fi
((c++))
done
exit 1
fi
if [[ $env == "pr" ]] || [[ $env == "PR" ]] || [[ $env == "qa" ]] || [[ $env == "at" ]]; then
if [[ $env == "PR" ]]; then
env="pr"
fi
if [[ $env == "at" ]]; then
env="pr"
fi
a=1
while [[ $a -le $TotalVar ]]; do
PreName=$(cat DBnames | sed -n "$a"'p')
DataBaseName[$a]=$PreName
checksumold=$(sha1sum runlist/${DataBaseName[$a]}.runlist)
echo -e "Updating runlist ${DataBaseName[$a]}\033[32m"
/usr/bin/curl -k --progress-bar --header "PRIVATE-TOKEN: Insert the private token here " https://pr-gb-ops-gitlab-01.stanleybet.com/DevOps/configcent/raw/galileoservice/scripts/runlist/$env/$hostname/${DataBaseName[$a]}.runlist -o runlist/${DataBaseName[$a]}.runlist
checksumNew=$(sha1sum runlist/${DataBaseName[$a]}.runlist)
if [[ $checksumold == $checksumNew ]]; then
echo -e "\033[31m No changes detected on ${DataBaseName[$a]}.runlist \033[0;0m"
echo ""
else
echo -e "The file ${DataBaseName[$a]}.runlist was successfully updated! \033[0;0m"
echo ""
fi
((a++))
done
fi
if [[ $env == "st" ]]; then
env="stag"
a=1
while [[ $a -le $TotalVar ]]; do
PreName=$(cat DBnames | sed -n "$a"'p')
DataBaseName[$a]=$PreName
checksumold=$(sha1sum runlist/${DataBaseName[$a]}.runlist)
echo -e "Updating runlist ${DataBaseName[$a]}\033[32m"
/usr/bin/curl -k --progress-bar --header "PRIVATE-TOKEN: Insert the private token here " https://pr-gb-ops-gitlab-01.stanleybet.com/DevOps/configcent/raw/galileoservice/scripts/runlist/$env/$hostname/${DataBaseName[$a]}.runlist -o runlist/${DataBaseName[$a]}.runlist
checksumNew=$(sha1sum runlist/${DataBaseName[$a]}.runlist)
if [[ $checksumold == $checksumNew ]]; then
echo -e "\033[31m No changes detected on ${DataBaseName[$a]}.runlist \033[0;0m"
echo ""
else
echo -e "The file ${DataBaseName[$a]}.runlist was successfully updated! \033[0;0m"
echo ""
fi
((a++))
done
fi
if [ -e "./patches" ]; then
echo "Checking if the folder patches exist..."
echo "Folder patches -----------------------------------------------------------> [ok]"
echo ""
else
echo "Something is wrong! The folder patches does not exist or is empty!"
echo "Please, execute the SQLLoops.sh to create the folder patches"
echo ""
exit 1
fi
#Procedure to update the patches
echo -e '\033[36m'
echo "╔════════════════════════════════════════════════╗"
echo "║ Donwloading the patches from Git Repository... ║"
echo "╚════════════════════════════════════════════════╝"
echo -e '\033[0;0m'
b=1
while [[ $b -le $TotalVar ]]; do
PreName=$(cat ./DBnames | sed -n "$b"'p')
cat runlist/$PreName.runlist >>list_tmp
echo -e "\n" >>list_tmp
((b++))
done
cat list_tmp | sed '/^$/d' | sort | uniq -d >list
cat list_tmp | sed '/^$/d' | sort | uniq --u >>list
chmod 755 list
rm list_tmp
Totalpatches=$(cat list | wc -l)
c=1
while [[ $c -le $Totalpatches ]]; do
patchesName=$(cat list | sed -n "$c"'p')
echo $patchesName
if [ -e "./patches/$patchesName" ]; then
ChecksumOldPatch=$(sha1sum ./patches/$patchesName)
else
ChecksumOldPatch=0
fi
/usr/bin/curl -k --progress-bar --header "PRIVATE-TOKEN: Insert the private token here " https://pr-gb-ops-gitlab-01.stanleybet.com/DevOps/configcent/raw/galileoservice/scripts/patchs/$patchesName -o patches/$patchesName
ChecksumNewPatch=$(sha1sum ./patches/$patchesName)
if [ -e "./patches/$patchesName" ]; then
if [[ $ChecksumOldPatch == $ChecksumNewPatch ]]; then
echo -e "\033[31m No changes detected on $patchesName \033[0;0m"
echo ""
else
echo -e "\033[32m Patch successfully downloaded \033[0;0m"
fi
else
echo -e "\033[31m Error... the patch $patchesName not found \033[0;0m"
echo ""
fi
((c++))
done