-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSHELL-DRYRUN-Sample.sh
More file actions
95 lines (81 loc) · 2.02 KB
/
SHELL-DRYRUN-Sample.sh
File metadata and controls
95 lines (81 loc) · 2.02 KB
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
#!/bin/bash
shopt -s xpg_echo
function usage(){
echo "Usage: $0 -s|--service -a|--adhoc -v|--version -d|--dryrun
-s|--service: Please provide core service name(Default:-all)!
-a|--adhoc: Please provide adhoc service names(Comma seperated)!
-v|--version: Please provide the latest version you wish to set!
-d|--dryrun: Enable dryrun,Don't execute command!"
exit 1
}
[ $# -lt 1 ] && usage || true
FILE="core_image_list.txt"
function dryrun() {
printf -v cmd_str '%q ' "$@"; echo "DRYRUN: Not executing:-> $cmd_str" >&2
}
function update_version() {
image=$1
CURRENT=$(echo $image|awk -F'-' '{print $NF}')
IMAGE=$(echo $image|sed "s|$CURRENT|$VERSION|")
}
function change() {
line=$1
service=$2
update_version $line
[ -n "${OPTION}" ] && dryrun $(echo "Changing image for: $service") || echo "Changing image for: $service"
[ -n "${OPTION}" ] && dryrun $(echo "Image name is: $IMAGE") || echo "Image name is: $IMAGE"
[ -n "${OPTION}" ] && dryrun $(echo "rcx service alter --image $IMAGE $service") || rcx service alter --image $IMAGE $service
}
#Parsing Args
while [[ $1 ]];do
case $1 in
-s|--service)
SERVICE=$2
shift
;;
-a|--adhoc)
ADHOC=$2
shift
;;
-v|--version)
VERSION=$2
shift
;;
-d|--dryrun)
OPTION=true
shift
;;
esac
shift
done
function alter_image(){
while read line
do
service=$(echo $line|cut -d':' -f2|sed 's|master-||g'|cut -d'.' -f1|sed 's|-1||g')
change $line $service
done < $FILE
}
case $SERVICE in
all)
alter_image
;;
esac
function adhoc(){
while read line
do
for i in $line
do
if [ "$i" == "crud-ui" ];then
i=crud
LINE=$(grep -w $i $FILE)
[ -n "$LINE" ] && service=$(echo $LINE|cut -d':' -f2|sed 's|master-||g'|cut -d'.' -f1|sed 's|-1||g')
service=crud-ui
else
LINE=$(grep -w $i $FILE)
[ -n "$LINE" ] && service=$(echo $LINE|cut -d':' -f2|sed 's|master-||g'|cut -d'.' -f1|sed 's|-1||g')
fi
change $LINE $service
done
done < <(echo ${ADHOC//,/\\n})
}
[ -n "$ADHOC" ] && adhoc