add support for quiet mode and -nc to suppress colour
Signed-off-by: nickboldt <nboldt@redhat.com>
diff --git a/scripts/fetch-SHAs.sh b/scripts/fetch-SHAs.sh
index ebd5c76..9ba1922 100755
--- a/scripts/fetch-SHAs.sh
+++ b/scripts/fetch-SHAs.sh
@@ -13,7 +13,38 @@
red="\033[1;31m"
branch=master
-for d in common servertools jsdt sourceediting javaee dali jsf webservices; do
+quiet=0 # flag which only returns status of 0/"" (if pass) or 1 (if fail)
+projects="common servertools jsdt sourceediting javaee dali jsf webservices"
+
+# read commandline args
+while [[ "$#" -gt 0 ]]; do
+ case $1 in
+ '-b') branch="$2"; shift 1;;
+ '-q') quiet=1; shift 0;;
+ '-nc') red=$norm; green=$norm; shift 0;; # disable colour
+ *) projects="$projects $1";;
+ esac
+ shift 1
+done
+
+if [[ ! $branch ]]; then
+ echo "branch is not set!"; exit 1
+fi
+if [[ ! $projects ]]; then
+ echo "no project(s) selected!"; exit 1
+fi
+
+log ()
+{
+ if [[ $quiet == 0 ]]; then echo -e "$1"; fi
+}
+logn ()
+{
+ if [[ $quiet == 0 ]]; then echo -e -n "$1"; fi
+}
+
+returnCode=0
+for d in ${projects}; do
if [[ ${d} == "common" ]]; then
gitURL="http://git.eclipse.org/c/webtools-common/webtools.common.git/commit/?h=${branch}"
elif [[ ${d} == "javaee" ]]; then
@@ -24,16 +55,22 @@
jobURL="https://ci.eclipse.org/webtools/view/webtools_R3_10/job/webtools-${d}_R3_10/lastStableBuild/api/xml?xpath=//lastBuiltRevision/SHA1"
jobSHA=$(wget -q ${jobURL} -O- | sed -e "s#.*<SHA1>\(.\+\)</SHA1>.*#\1#")
- echo -n $d :: $jobSHA
+ logn "$d :: $jobSHA"
gitSHA=$(wget -q ${gitURL} -O- | grep "<th>commit</th>" | sed -e "s#.*?id=\(.\+\)'>.*#\1#")
if [[ ${gitSHA} != ${jobSHA} ]]; then
- echo -e " :: ${red}ERROR${norm}"
+ returnCode=1
+ log " :: ${red}ERROR${norm}"
if [[ ${gitSHA} ]]; then
- echo ": $gitSHA"
+ log ": $gitSHA"
else
- echo ": $gitURL"
+ log ": $gitURL"
fi
else
- echo -e " :: ${green}OK${norm}"
+ log " :: ${green}OK${norm}"
fi
-done
\ No newline at end of file
+done
+
+if [[ ${returnCode} != "0" ]]; then
+ echo ${returnCode}
+ exit ${returnCode}
+fi
\ No newline at end of file