-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayreturn.sh
More file actions
184 lines (153 loc) · 3.93 KB
/
arrayreturn.sh
File metadata and controls
184 lines (153 loc) · 3.93 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
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
#!/bin/bash
# Get PORD_SCRIPT
# GET AUT_SCRIPT
# SIZE_OF
REGION="uat aut.sh,prod.sh^r1.sh\n"
ERROR_STATUS=0
SUCCESS_STATUS=1
#*********************************
# Check if a file exists or not.#
#********************************
function file_exist(){
args="$#"
# check if parameter is provided or not
if (( $args < 1 ))
then
return "${ERROR_STATUS}"
fi
local filename="$1"
# check if the file exists
if [ -e "$filename" ]
then
return "${SUCCESS_STATUS}"
fi
return "${ERROR_STATUS}"
}
#****************************************
# @brief
# the function will get the basename of the file
# @param filename
# @author Obaro I. Johnson
#****************************************
function get_bash_file_basename(){
local filename="$1"
# check if the filename is set or not
if [ ! -z "$filename" ]
then
# trim out the extension .sh from the from of string
filename="${filename%%.sh}"
# trim out other rest of the parts until the last '/'
filename="${filename##*/}"
echo "$filename"
return "${SUCCESS_STATUS}"
fi
return "${ERROR_STATUS}"
}
#***********************************
# @brief
# The function take two parameters filename and the an associate array for out.
# @param filename takes the path to the region_map_file
# @param arr an associate array for output
# @return 0 if the function failed otherwise 1#
#************************************
function parse_region_map_from_file(){
nParams="$#"
if (( $nParams < 2 ))
then
echo "@error: expecting 2 parameter , but $nParams provided"
return "${ERROR_STATUS}" && exit
fi
local filename="$1"
declare -n region_scripts=$2
#check if the file exists or not
file_exist "$filename"
local status=$?
if (($status == $SUCCESS_STATUS))
then
# file exist , read and parse it
# read file data
# we want leading space to be trim , therefore remove IFS=
while read -r line
do
if [ ! -z "$line" ]
then
#split into two array
arr=(`echo $line | sed 's/ /\n/g'`)
region="${arr[0]}"
scripts="${arr[1]}"
region_scripts["$region"]="$scripts"
fi
done < "$filename"
return "${SUCCESS_STATUS}"
else
return "${ERROR_STATUS}"
fi
}
#Function check if the is presented.
function does_region_exist(){
local -n regions0="$1"
local region="$2"
for key in "${!regions0[@]}"
do
if [ "$key" == "$region" ]
then
return "${SUCCESS_STATUS}"
fi
done
return "${ERROR_STATUS}"
}
function parse_region_scripts(){
local nargs="$#"
if ((nargs <= 1))
then
return "${ERROR_STATUS}"
fi
local scripts="$1"
local index=0
declare -n local_scripts_array="$2"
if [ ! -z $scripts ]
then
scripts=$(echo $scripts | tr "^" ",")
while read -d ',' part
do
local_scripts_array["$index"]="$part"
index=$(($index + 1))
done <<< "$scripts"
if [ ! -z "$part" ]
then
local_scripts_array["$index"]="$part"
fi
fi
return "${SUCCESS_STATUS}"
}
REGION='usa'
function build_region_scripts(){
declare -A regions;
filename="./releaseconfig/regions.map"
parse_region_map_from_file "$filename" regions
status=$?
if (($status == $SUCCESS_STATUS))
then
does_region_exist regions "$REGION"
status=$?
if (($status == $SUCCESS_STATUS))
then
scripts="${regions[$REGION]}"
#create an output script_array that contains the prod, and the uat scripts in order of inputs
declare -a scripts_array
parse_region_scripts "$scripts" scripts_array
for script in "${scripts_array[@]}"
do
# check if the files exists or not
# build aut scripts
if [ "$script" == *"prod"* ]
then
echo "Process Production $script"
else
echo "Process aut $script"
fi
done
fi
fi
}
build_region_scripts