-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash-nw.sh
280 lines (235 loc) · 9.32 KB
/
bash-nw.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
#! bin/bash
####### PATH SECTION #######
path="/mnt/c/Users/luigi/Desktop/bash-scripts/"
modules="module1 module2 module3"
pom="/pom.xml"
############################
#### DEPENDENCY SECTION ####
dependency="<artifactId>jaxb-api</artifactId>"
############################
bak="/pom.xml.bak"
echo -e "\n
_ _ _ ______ _____ ______ _ _ _
| | | | | | _ (_____ \ / ___ \| ___ \ | | | | |
| | | |____ _ | | ____| |_ ____ _____) ) | | | | _ | | ___| | _ ____| | |
| | | | _ \ / || |/ _ | _)/ _ ) | ____/| | | | || || | /___) || \ / _ ) | |
| |___| | | | ( (_| ( ( | | |_( (/ / | | | |___| | || || | |___ | | | ( (/ /| | |
\______| ||_/ \____|\_||_|\___)____) |_| \_____/|_||_||_| (___/|_| |_|\____)_|_|
|_|
v0.0.001\n"
echo -e "\e[35mPlease select an option:\n\e[39m"
options=("Select one module" "Review all modules")
select option in "${options[@]}"
do
echo -e "\e[39m"
case $option in
"Select one module")
for input in $option
do
echo -e "\e[35mThese are the available modules on which you can make changes:\e[39m"
for module in $modules
do
echo $module
done
echo -e "\n\e[96mWrite the name of the module you want to work on:\n\e[39m"
read select_m
pth="$path${select_m}$pom"
opt1_lines=$(grep -n $dependency $pth | awk -F ":" '{print $1}')
opt1_count=$(grep -o "$dependency" $pth | wc -l)
if (( $opt1_count == 0 )); then
echo -e "\e[91mDependency of type $dependency not found"
elif (( $opt1_count == 1 )); then
echo -e "\n*******\n\n\e[95mYou are working on: \e[103m\e[30m $select_m \e[49m"
echo -e "\n\e[97mFound dependency of type \e[93m$dependency\e[97m at line: \n\n$opt1_lines"
opt1_x=$((($opt1_lines)+1))
opt1_space=$(($opt1_lines))
version=$(head -n $opt1_x $pth | tail -n 1)
echo -e "\n\e[97mCheck current dependency version: \n\n\e[93m$version\n\e[97m"
opt1_check="$path${select_m}$bak"
opt1_upd_f="$opt1_check"
echo -e "\e[96m>\e[93m "$select_m "\n"
opt1_overwrite="$path${select_m}$pom"
opt1_ow="$opt1_overwrite"
change_selected() {
while true;
do
read -r -n 1 -p "${1:-Do you want to proceed and make changes?} [y/n]: " change_selected
case $change_selected in
[yY]) echo -e ; return 0 ;;
[nN]) echo ; return 1 ;;
*) printf " \033[31m %s \n\033[0m" "Invalid input"
esac
done
}
change_selected
if [ "$change_selected" == "y" ]; then
declare updates="Updating $select_m"
echo -e "\e[96mWaiting for a new dependency version..."
echo -e "\e[97mInsert new version: "
read opt1_bump
space=$(head -n $opt1_x $pth | grep -c -oP '(?<=\t).*?(?=<version>)')
_space=${space}
numLines=${_space}
addSpace=$(printf "%*s%s" $numLines '' "$addSpace")
opt1_sed=$(sed "${opt1_x}s~$version~$addSpace<version>$opt1_bump</version>~g" $pth > $pth.bak)
eval $opt1_sed
echo -e "Done! \e[92mUpdated dependency to version $opt1_bump \e[39m"
elif [[ -z "$pth" ]]; then
exit 0
elif [ "$change_selected" == "n" ]; then
continue
else
echo -e "\e[96mProcess finished"
exit 0
fi
changes_confirm_selected() {
while true; do
read -r -n 1 -p "${1:-Do you want to confirm the changes you made by overwriting the pom?} [y/n]: " confirm_selected
case $confirm_selected in
[yY]) echo -e ; return 0 ;;
[nN]) echo ; return 1 ;;
*) printf " \033[31m %s \n\033[0m" "Invalid input"
esac
done
}
changes_confirm_selected
if [ "$confirm_selected" == "y" ]; then
if [[ -f $opt1_upd_f ]]; then
echo -e "\e[96mYour changes are being processed..."
mv $opt1_upd_f $opt1_ow
echo -e "\e[92mDone!\n \e[39m"
continue
else
echo -e "\e[91mYou have not made changes on this module\e[39m"
continue
fi
elif [ "$confirm_selected" == "n" ]; then
continue
else
echo -e "\e[96mProcess finished"
exit 0
fi
else
echo -e "Found $opt1_count dependencies of type $dependency at lines: \n $opt1_lines"
fi
done
;;
"Review all modules")
review_all() {
while true; do
read -r -n 1 -p "${1:-Do you want to proceed with reviewing all modules?} [y/n]: " review_all
case $review_all in
[yY]) echo -e ; return 0 ;;
[nN]) echo ; return 0 ;;
*) printf " \033[31m %s \n\033[0m" "Invalid input"
esac
done
}
review_all
if [ "$review_all" == "n" ]; then
echo -e "\e[96mProcess finished"
exit 0
fi
for mod_x in $modules
do
files="$path${mod_x}$pom"
file="$files"
lines=$(grep -n $dependency $files | awk -F ":" '{print $1}')
count=$(grep -o "$dependency" $files | wc -l)
for file_x in $files
do
if (( $count == 0 )); then
echo -e "\e[91mDependency of type $dependency not found"
elif (( $count == 1 )); then
echo -e "\n*******\n\n\e[95mYou are working on: \e[103m\e[30m $mod_x \e[49m"
echo -e "\n\e[97mFound dependency of type \e[93m$dependency\e[97m at line: \n\n$lines"
x=$((($lines)+1))
version=$(head -n $x $files | tail -n 1)
echo -e "\n\e[97mCheck current dependency version: \n\n\e[93m$version\n\e[97m"
changes_list() {
while true; do
read -r -n 1 -p "${1:-Do you want to proceed?} [y/n]: " change_list
case $change_list in
[yY]) echo -e ; return 0 ;;
[nN]) echo ; return 1 ;;
*) printf " \033[31m %s \n\033[0m" "Invalid input"
esac
done
}
changes_list
if [ "$change_list" == "y" ]; then
declare updates="Updating $mod_x"
echo -e "\e[96mWaiting for a new dependency version..."
echo -e "\e[97mInsert new version: "
read bump_to
sed=$(sed "${x}s~$version~ <version>$bump_to</version>~g" $files > $files.bak)
eval $sed
echo -e "Done! \e[92mUpdated dependency to version $bump_to\e[39m"
elif [[ -z "$files" ]]; then
exit 0
elif [ "$change_list" == "n" ]; then
continue
else
echo -e "\e[96mProcess finished"
exit 0
fi
else
echo -e "Found $count dependencies of type $dependency at lines: \n $lines"
fi
done
done
proceed() {
while true; do
read -r -p "${1:-Do you want to proceed with saving the changes?} [y/n]: " proceed
case $proceed in
[yY]) echo -e ; return 0 ;;
[nN]) echo ; return 1 ;;
*) printf " \033[31m %s \n\033[0m" "Invalid input"
esac
done
}
proceed
if [ "$proceed" == "n" ]; then
echo -e "\e[96mProcess finished"
exit 1
fi
echo -e "\n\e[96mYou have made changes to the following modules:\n \e[39m"
for upd_m in $modules
do
check="$path${upd_m}$bak"
upd_f="$check"
echo -e "\e[96m>\e[93m "$upd_m "\n"
overwrite="$path${upd_m}$pom"
ow="$overwrite"
changes_confirm() {
while true; do
read -r -p "${1:-Do you want to confirm the changes you made by overwriting the pom?} [y/n]: " confirm
case $confirm in
[yY]) echo -e ; return 0 ;;
[nN]) echo ; return 1 ;;
*) printf " \033[31m %s \n\033[0m" "Invalid input"
esac
done
}
changes_confirm
if [ "$confirm" == "y" ]; then
if [[ -f $upd_f ]]; then
echo -e "\e[96mYour changes are being processed..."
mv $upd_f $ow
echo -e "\e[92mDone!\n"
else
echo -e "\e[91mYou have not made changes on this module \e[39m"
continue
fi
elif [ "$confirm" == "n" ]; then
continue
else
echo -e "\e[96mProcess finished"
echo -e "\e[39m"
exit 0
fi
done
;;
esac
echo "Choose option: [1/2]"
done