michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: download_mars () { michael@0: update_url="$1" michael@0: only="$2" michael@0: test_only="$3" michael@0: michael@0: echo "Using $update_url" michael@0: wget --no-check-certificate -q -O update.xml $update_url michael@0: michael@0: mkdir -p update/ michael@0: if [ -z $only ]; then michael@0: only="partial complete" michael@0: fi michael@0: for patch_type in $only michael@0: do michael@0: line=`fgrep "patch type=\"$patch_type" update.xml` michael@0: grep_rv=$? michael@0: michael@0: if [ 0 -ne $grep_rv ]; then michael@0: echo "FAIL: no $patch_type update found for $update_url" michael@0: return 1 michael@0: fi michael@0: michael@0: command=`echo $line | sed -e 's/^.*.*$::' -e 's:\&:\&:g'` michael@0: eval "export $command" michael@0: michael@0: if [ "$test_only" == "1" ] michael@0: then michael@0: echo "Testing $URL" michael@0: curl -k -s -I -L $URL michael@0: return michael@0: else michael@0: wget --no-check-certificate -nv -O update/$patch_type.mar $URL 2>&1 michael@0: fi michael@0: if [ "$?" != 0 ]; then michael@0: echo "Could not download $patch_type!" michael@0: echo "from: $URL" michael@0: fi michael@0: actual_size=`perl -e "printf \"%d\n\", (stat(\"update/$patch_type.mar\"))[7]"` michael@0: actual_hash=`openssl dgst -$hashFunction update/$patch_type.mar | sed -e 's/^.*= //'` michael@0: michael@0: if [ $actual_size != $size ]; then michael@0: echo "FAIL: $patch_type from $update_url wrong size" michael@0: echo "FAIL: update.xml size: $size" michael@0: echo "FAIL: actual size: $actual_size" michael@0: return 1 michael@0: fi michael@0: michael@0: if [ $actual_hash != $hashValue ]; then michael@0: echo "FAIL: $patch_type from $update_url wrong hash" michael@0: echo "FAIL: update.xml hash: $hashValue" michael@0: echo "FAIL: actual hash: $actual_hash" michael@0: return 1 michael@0: fi michael@0: michael@0: cp update/$patch_type.mar update/update.mar michael@0: michael@0: done michael@0: }