Use test tools from release that is under test
[integration/test.git] / tools / deployment / search.sh
1 # Search the specified directory (parameter $1) for the specified items (the
2 # remaining parameters). The "item" is expected to be a directory located
3 # somewhere along the directory tree at which $1 points. This directory must
4 # have exactly 1 subdirectory and that subdirectory's name is considered to
5 # be the version number we are looking for.
6 #
7 # This tool searches for these items in the order specified and emits the
8 # first version number it finds. Using an one-line shell script for this task
9 # turned out to be pretty impossible as the algorithm is quite complicated
10 # (the "items" may move around the directory tree between releases and even
11 # some of them might disappear and the others appear) so a full blown utility
12 # is necessary.
13
14 exec 2>&1
15 set -e
16 directory=$1
17 shift
18 if test -d $directory; then :; else
19   echo "Path '$directory' does not exist or is not a directory"
20   exit 1
21 fi
22 if test -d $directory/org/opendaylight; then :; else
23   echo "Path '$directory' does not look like OpenDaylight System directory"
24   exit 1
25 fi
26 file_list=`pwd`/filelist.tmp
27 trap "rm -f $file_list" EXIT
28 version_found="n/a"
29 finish=false
30 for Thing in $@; do
31   cd $directory
32   find . -name $Thing -type d -print >$file_list
33   exec <$file_list
34   while read -r directory_to_check; do
35     cd $directory_to_check
36     for file_in_checked_directory in *; do
37       if test -d $file_in_checked_directory; then
38         if test "$version_found" = "n/a"; then
39           version_found=$file_in_checked_directory
40           where_found=$directory_to_check
41           finish=true
42         else
43           version_found="n/a"
44           finish=false
45           break
46         fi
47       fi
48     done
49     if $finish; then
50       break
51     fi
52   done
53   if $finish; then
54     break
55   fi
56 done
57 if $finish; then
58   echo $version_found
59   dirname $where_found | cut -b 3-
60 else
61   echo "None of the supplied components were found."
62   exit 1
63 fi