Add rpmbuild utility scripts.
[integration.git] / packaging / rpm / util / checkint.sh
1 #!/bin/bash
2 #set -vx
3
4 options=$1
5 gitdir=$2
6
7 function usage {
8     local rc=$1
9     local outstr=$2
10
11     if [ "$outstr" != "" ]; then
12         echo "$outstr"
13         echo
14     fi
15
16     echo "This script is used to validate the rpm builds for each edition."
17     echo "The script will compare the different editions against each other"
18     echo "to identify the proper filters when starting the controller,"
19     echo "list the dependencies in the different editions and identify"
20     echo "any inconsistencies between the edition poms and the project specs."
21     echo
22     echo "Usage: `basename $0` [OPTION...]"
23     echo
24     echo "Test options:"
25     echo "  --options OPTIONS  List of test options. Available options:"
26     echo "                     integration: compare integration editions"
27     echo "                     pom: get pom dependencies from integration poms"
28     echo "                     spec: compare projects specs against the pom dependencies"
29     echo "  --gitdir DIR       git root directory where projects are cloned"
30     echo
31     echo "Help options:"
32     echo "  -?, -h, --h, --help  Display this help and exit"
33     echo
34
35     exit $rc
36 }
37
38 function parse_options {
39     while true ; do
40         case "$1" in
41         --options)
42             shift; options="$1"; shift
43             ;;
44
45          --gitdir)
46             shift; gitdir="$1"; shift
47             if [ "$gitdir" = "" ]; then
48                 usage 1 "Missing directory.";
49             fi
50             ;;
51
52         -? | -h | --h | --help)
53             usage 0
54             ;;
55         "")
56             break
57             ;;
58         *)
59             echo "Ignoring unknown option: $1"; shift;
60         esac
61     done
62 }
63
64 function array_contains () {
65     local array="$1[@]"
66     local seeking=$2
67     local in=1
68     for element in "${!array}"; do
69         if [ $element = $seeking ]; then
70             in=0
71             break
72         fi
73     done
74     return $in
75 }
76
77
78 function compare_integration () {
79     local gitdir=$1
80
81     echo
82     echo "========================================================================="
83     echo "                          Comparing dirs"
84     echo "========================================================================="
85
86     cd $gitdir/integration
87
88     rm -rf /tmp/base/*
89     basezip=$(find . -name "*distributions-base*.zip")
90     unzip -qd /tmp/base $basezip
91
92     rm -rf /tmp/virt/*
93     virtzip=$(find . -name "*distributions-virtualization*.zip")
94     unzip -qd /tmp/virt $virtzip
95
96     rm -rf /tmp/sp/*
97     spzip=$(find . -name "*distributions-serviceprovider*.zip")
98     unzip -qd /tmp/sp $spzip
99
100     # Compare one edition against another.
101
102     echo
103     echo "Compare base and virt:"
104     echo "-------------------------------------------------------------------------"
105     diff -qr /tmp/base/opendaylight/ /tmp/virt/opendaylight/
106     echo
107     echo "Compare base and sp:"
108     echo "-------------------------------------------------------------------------"
109     diff -qr /tmp/base/opendaylight/ /tmp/sp/opendaylight/
110     echo
111     echo "Compare virt and sp:"
112     echo "-------------------------------------------------------------------------"
113     diff -qr /tmp/virt/opendaylight/ /tmp/sp/opendaylight/
114
115     # Compare one edition against the other two.
116
117     rm -rf /tmp/base_virt
118     mkdir /tmp/base_virt
119     cp -rf /tmp/base/* /tmp/base_virt/
120     cp -rf /tmp/virt/* /tmp/base_virt/
121
122     rm -rf /tmp/base_sp
123     mkdir /tmp/base_sp
124     cp -rf /tmp/base/* /tmp/base_sp/
125     cp -rf /tmp/sp/* /tmp/base_sp/
126
127     rm -rf /tmp/virt_sp
128     mkdir /tmp/virt_sp
129     cp -rf /tmp/virt/* /tmp/virt_sp/
130     cp -rf /tmp/sp/* /tmp/virt_sp/
131
132     echo
133     echo
134     echo "Compare base and virt_sp."
135     echo "-------------------------------------------------------------------------"
136     diff -qr /tmp/base/opendaylight/ /tmp/virt_sp/opendaylight/
137     echo
138     echo "Compare virt and base_sp. Useful to see what virt pulls in - look for Only in /tmp/virt."
139     echo "-------------------------------------------------------------------------"
140     diff -qr /tmp/virt/opendaylight/ /tmp/base_sp/opendaylight/
141     echo
142     echo "Compare sp and base_virt. Useful to see what sp pulls in - look for Only in /tmp/sp."
143     echo "-------------------------------------------------------------------------"
144     diff -qr /tmp/sp/opendaylight/ /tmp/base_virt/opendaylight/
145 }
146
147 function check_affinity () {
148 #       allaffinity=$(find /tmp/virt -name "*affinity.*.jar")
149 #       while read line; do
150 #               if [ "line" ]
151     echo "here"
152 }
153
154 function read_dom () {
155     local IFS=\>
156     read -d \< ENTITY CONTENT
157 }
158
159 function read_poms () {
160     local gitdir="$1"
161     local distribution="$2"
162     local pomfile=$gitdir/integration/distributions/$distribution/pom.xml
163     local FILE=$pomfile
164     local i=$pomcnt
165     local groupy=0
166     local state="null"
167
168     echo
169     echo "read_poms $gitdir $distribution"
170     echo "-------------------------------------------------------------------------"
171
172     while read_dom; do
173         case "$state" in
174         null)
175             if [ "$ENTITY" = "dependencies" ]; then
176                 state="dependencies"
177             fi
178             ;;
179
180         dependencies)
181             case "$ENTITY" in
182             groupId)
183                 groupIds[i]=$CONTENT
184                 groups=1
185                 editions[i]=$distribution
186                 ;;
187
188             artifactId)
189                 if [ $groups -eq 1 ]; then
190                     artifactIds[i]=$CONTENT
191                 fi
192                 ;;
193
194             version)
195                 if [ $groups -eq 1 ]; then
196                     versions[i]=$CONTENT
197                     groups=0
198                     ((i++))
199                 fi
200                 ;;
201
202             /dependencies)
203                 state="done"
204                 break
205                 ;;
206             esac
207             ;;
208         esac
209     done < "$pomfile"
210
211     end=$((i-1))
212     for index in `seq $pomcnt $end`; do
213         echo "$index artifact: ${groupIds[$index]}.${artifactIds[$index]}-${versions[$index]}"
214     done
215
216     pomcnt=$i
217 }
218
219 function check_poms () {
220     local gitdir=$1
221     pomcnt=0
222
223     echo
224     echo "========================================================================="
225     echo "                          Checking poms"
226     echo "========================================================================="
227
228     read_poms "$gitdir" "base"
229     read_poms "$gitdir" "serviceprovider"
230     read_poms "$gitdir" "virtualization"
231 }
232
233 function read_spec () {
234     local gitdir="$1"
235     local project="$2"
236     local specfile=$gitdir/integration/packaging/rpm/opendaylight-$project.spec
237     local FILE=$specfile
238     local state="null"
239     local i=0
240
241     unset specarts
242
243     echo
244     echo "read_spec $gitdir $project"
245     echo "-------------------------------------------------------------------------"
246
247     while read line; do
248         case "$state" in
249         null)
250             if [ "$line" = "done <<'.'" ]; then
251                 state="artifacts"
252             fi
253             ;;
254
255         artifacts)
256             if [ "$line" = "." ]; then
257                 state="done"
258                 break
259             else
260                 specarts[i]=$line
261                 ((i++))
262             fi
263             ;;
264         esac
265     done < "$specfile"
266
267     for index in ${!specarts[*]}; do
268         echo "$index spec artifact: ${specarts[$index]}"
269     done
270 }
271
272
273 function check_project () {
274     local gitdir=$1
275     local project=$2
276     local specfile=$gitdir/integration/packaging/rpm/opendaylight-$project.specfile
277     local k=0
278
279     unset notfoundarts
280     unset notfoundeds
281
282     echo
283     echo "check_project $gitdir $project"
284     echo "-------------------------------------------------------------------------"
285
286     read_spec "$gitdir" "$project"
287
288     for i in ${!groupIds[*]}; do
289         if [ ${groupIds[$i]} = "org.opendaylight.$project" ]; then
290             found=0
291             for j in ${!specarts[*]}; do
292                 specart=$(echo ${specarts[$j]} | sed -e "s/-\*.*//")
293                 artifactId=${artifactIds[$i]}
294                 if [ "$specart" = "$artifactId" ]; then
295                     found=1
296                     break
297                 fi
298             done
299
300             if [ $found -eq 0 ]; then
301                 notfoundeds[k]=${editions[$i]}
302                 notfoundarts[k]=${artifactIds[$i]}
303                 ((k++))
304             fi
305         fi
306     done
307
308     for index in ${!notfoundarts[*]}; do
309         echo ">>>>> $index missing artifact: ${notfoundeds[$index]}: ${notfoundarts[$index]}"
310     done
311 }
312
313 function check_specs () {
314     local gitdir=$1
315
316     echo
317     echo "========================================================================="
318     echo "                          Checking specs"
319     echo "========================================================================="
320
321     check_project "$gitdir" "affinity"
322     check_project "$gitdir" "bgpcep"
323     check_project "$gitdir" "lispflowmapping"
324     check_project "$gitdir" "snmp4sdn"
325     check_project "$gitdir" "yangtools"
326 }
327
328 function main () {
329     parse_options "$@"
330
331     if [ ! -d "$dir" ]; then
332         usage 1 "Invalid path."
333     fi
334
335 }
336
337 main "$@"
338
339 exit 0