blob: d4f6b460924ed8e1247a0ec2095368ce72952930 [file] [log] [blame]
david_williams438e2082009-06-07 05:59:09 +00001#!/bin/bash
2
3# Simple script to count number of mirrors available for a particular URL
4
5# Copyright (c) 2009 IBM
6# All rights reserved. This program and the accompanying materials
7# are made available under the terms of the Eclipse Public License v1.0
8# which is available at
9# http://www.eclipse.org/legal/epl-v10.html
10#
11# Contributors:
12# David Williams - initial API and implementation
13
14
15function usage() {
16 printf "\n\tSimple script to count number of mirrors available for a particular URL" >&2
17 printf "\n\tUsage: %s [-h] | [-v] [-f] [-p] [-t number] urls" $(basename $0) >&2
18 printf "\n\t\t%s" "where h==help, v==verbose, f==only ftp mirrors, p==only http mirrors, t==test against 'number' " >&2
19 printf "\n\t\t%s" "and urls is space delimited list of URL parameters," >&2
20 printf "\n\t\t%s\n" "such as /ganymede/releases/site.xml" >&2
21}
22
23function checkMirrorsForURL() {
24
25 if [ -z $1 ]
26 then
27 echo "Error: internal funtion requires mirror url parameter";
28 exit 3;
29 else
30 mirrorURL=$1
31 fi
32 if [ -z $2 ]
33 then
34 protocol=
35 pword="http and ftp"
36 else
37 protocolarg="&protocol=$2"
38 pword="$2"
39 fi
40
41 nMirrors=$(wget -q -O - "http://www.eclipse.org/downloads/download.php?file=${mirrorURL}&format=xml${protocolarg}" | grep \<mirror\ | wc -l)
42 echo " number of" ${pword} "mirrors: " ${nMirrors} " for" ${mirrorURL}
43 exit $nMirrors
44}
45
46function minvalue() {
47ref=$1
48comp=$2
49result=
50#echo "ref: $ref \r";
51#echo "comp: " $comp "\r"
52if [ -z $ref ]
53then
54 #echo "no ref\r"
55 result=$comp
56else
57 if [ $ref -lt $comp ]
58 then
59 #echo "ref lt comp\r"
60 result=$ref
61 else
62 #echo "comp <= ref\r"
63 result=$comp
64 fi
65fi
66echo $result
67}
68
69
70urls=
71ftponly=0
72httponly=0
73protocol=
74while getopts 'hvfpt:' OPTION
75do
76 case $OPTION in
77 h) usage
78 exit 1
79 ;;
80 f) ftponly=1
81 ;;
82 p) httponly=1
83 ;;
84 v) verbose=1
85 ;;
86 t) testNumber=$OPTARG
87 ;;
88 ?) usage
89 exit 2
90 ;;
91 esac
92done
93
94shift $(($OPTIND - 1))
95
96urls="$@"
97
98if [ $ftponly == 1 ]
99then
100 protocol="ftp"
101fi
102if [ $httponly == 1 ]
103then
104 protocol="http"
105fi
106if [ $ftponly == 1 -a $httponly == 1 ]
107then
108 protocol=
109fi
110
111if [ $verbose ]
112then
113 echo "ftponly: " $ftponly " httponly: " $httponly
114 echo "protocol: " $protocol
115 echo "urls: " $urls
116fi
117
118minimumMirrors=
119if [ "${urls}" ]
120then
121 echo
122 for mirrorURL in ${urls}
123 do
124 nm=checkMirrorsForURL $mirrorURL $protocol
125 minimumMirrors=min $minimumMirrors $nm
126 done
127 echo
128else
129 usage
130fi
131
132if [ -z $testNumber ]
133then
134 if [ $verbose ]
135 then
136 echo "no test mode"
137 fi
138 exit 0
139else
140 result=$($testNumber - $minimumMirrors)
141 if [ $result <= 0 ]
142 then
143 if [ $verbose ]
144 then
145 echo "minimum mirrors was greater than or equal to criteria"
146 fi
147 exit 0
148 else
149 if [ $verbose ]
150 then
151 echo "minimum mirrors was not as large as criteria"
152 fi
153 exit result
154 fi
155fi