1download_mars () { 2 update_url="$1" 3 only="$2" 4 test_only="$3" 5 to_build_id="$4" 6 to_app_version="$5" 7 to_display_version="$6" 8 9 max_tries=5 10 try=1 11 # retrying until we get offered an update 12 while [ "$try" -le "$max_tries" ]; do 13 echo "Using $update_url" 14 # retrying until AUS gives us any response at all 15 cached_download update.xml "${update_url}" 16 17 echo "Got this response:" 18 cat update.xml 19 # If the first line after <updates> is </updates> then we have an 20 # empty snippet. Otherwise we're done 21 if [ "$(grep -A1 '<updates>' update.xml | tail -1)" != "</updates>" ]; then 22 break; 23 fi 24 echo "Empty response, sleeping" 25 sleep 5 26 try=$(($try+1)) 27 done 28 29 echo; echo; # padding 30 31 update_line=`fgrep "<update " update.xml` 32 grep_rv=$? 33 if [ 0 -ne $grep_rv ]; then 34 echo "TEST-UNEXPECTED-FAIL: no <update/> found for $update_url" 35 return 1 36 fi 37 command=`echo $update_line | sed -e 's/^.*<update //' -e 's:>.*$::' -e 's:\&:\&:g'` 38 eval "export $command" 39 40 if [ ! -z "$to_build_id" -a "$buildID" != "$to_build_id" ]; then 41 echo "TEST-UNEXPECTED-FAIL: expected buildID $to_build_id does not match actual $buildID" 42 return 1 43 fi 44 45 if [ ! -z "$to_display_version" -a "$displayVersion" != "$to_display_version" ]; then 46 echo "TEST-UNEXPECTED-FAIL: expected displayVersion $to_display_version does not match actual $displayVersion" 47 return 1 48 fi 49 50 if [ ! -z "$to_app_version" -a "$appVersion" != "$to_app_version" ]; then 51 echo "TEST-UNEXPECTED-FAIL: expected appVersion $to_app_version does not match actual $appVersion" 52 return 1 53 fi 54 55 mkdir -p update/ 56 if [ -z $only ]; then 57 only="partial complete" 58 fi 59 for patch_type in $only 60 do 61 line=`fgrep "patch type=\"$patch_type" update.xml` 62 grep_rv=$? 63 64 if [ 0 -ne $grep_rv ]; then 65 echo "TEST-UNEXPECTED-FAIL: no $patch_type update found for $update_url" 66 return 1 67 fi 68 69 command=`echo $line | sed -e 's/^.*<patch //' -e 's:/>.*$::' -e 's:\&:\&:g'` 70 eval "export $command" 71 72 if [ "$test_only" == "1" ] 73 then 74 echo "Testing $URL" 75 curl -s -I -L $URL 76 return 77 else 78 cached_download "update/${patch_type}.mar" "${URL}" 79 fi 80 if [ "$?" != 0 ]; then 81 echo "Could not download $patch_type!" 82 echo "from: $URL" 83 fi 84 actual_size=`perl -e "printf \"%d\n\", (stat(\"update/$patch_type.mar\"))[7]"` 85 actual_hash=`openssl dgst -$hashFunction update/$patch_type.mar | sed -e 's/^.*= //'` 86 87 if [ $actual_size != $size ]; then 88 echo "TEST-UNEXPECTED-FAIL: $patch_type from $update_url wrong size" 89 echo "TEST-UNEXPECTED-FAIL: update.xml size: $size" 90 echo "TEST-UNEXPECTED-FAIL: actual size: $actual_size" 91 return 1 92 fi 93 94 if [ $actual_hash != $hashValue ]; then 95 echo "TEST-UNEXPECTED-FAIL: $patch_type from $update_url wrong hash" 96 echo "TEST-UNEXPECTED-FAIL: update.xml hash: $hashValue" 97 echo "TEST-UNEXPECTED-FAIL: actual hash: $actual_hash" 98 return 1 99 fi 100 101 cp update/$patch_type.mar update/update.mar 102 echo $actual_size > update/$patch_type.size 103 104 done 105} 106