1cdf0e10cSrcweir#!/bin/sh 2cdf0e10cSrcweir#************************************************************************* 3cdf0e10cSrcweir# 4cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5cdf0e10cSrcweir# 6cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 7cdf0e10cSrcweir# 8cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 9cdf0e10cSrcweir# 10cdf0e10cSrcweir# This file is part of OpenOffice.org. 11cdf0e10cSrcweir# 12cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 13cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 14cdf0e10cSrcweir# only, as published by the Free Software Foundation. 15cdf0e10cSrcweir# 16cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 17cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 18cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 20cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 21cdf0e10cSrcweir# 22cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 23cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 24cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 25cdf0e10cSrcweir# for a copy of the LGPLv3 License. 26cdf0e10cSrcweir# 27cdf0e10cSrcweir#************************************************************************* 28cdf0e10cSrcweir 29cdf0e10cSrcweirif [ -z "$TARFILE_LOCATION" ]; then 30cdf0e10cSrcweir echo "ERROR: no destination defined! please set TARFILE_LOCATION!" 31cdf0e10cSrcweir exit 32cdf0e10cSrcweirfi 33cdf0e10cSrcweir 34cdf0e10cSrcweirif [ ! -d "$TARFILE_LOCATION" ]; then 35cdf0e10cSrcweir mkdir $TARFILE_LOCATION 36cdf0e10cSrcweirfi 37cdf0e10cSrcweirif [ ! -d "$TARFILE_LOCATION" ]; then 38cdf0e10cSrcweir echo "ERROR: can't create" 39cdf0e10cSrcweir exit 40cdf0e10cSrcweirfi 41cdf0e10cSrcweir 42cdf0e10cSrcweirif [ -z "$1" ]; then 43cdf0e10cSrcweir echo "ERROR: parameter missing!" 44cdf0e10cSrcweir echo "usage: $0 <fetch list>" 45cdf0e10cSrcweir echo "first line must define the base url." 46cdf0e10cSrcweir exit 47cdf0e10cSrcweirfi 48cdf0e10cSrcweir 49cdf0e10cSrcweir# check for wget and md5sum 50cdf0e10cSrcweirwget= 51cdf0e10cSrcweirmd5sum= 52cdf0e10cSrcweircurl= 53cdf0e10cSrcweir 54cdf0e10cSrcweirfor i in wget /usr/bin/wget /usr/local/bin/wget /usr/sfw/bin/wget /opt/sfw/bin/wget /opt/local/bin/wget; do 55cdf0e10cSrcweir eval "$i --version" > /dev/null 2>&1 56cdf0e10cSrcweir ret=$? 57cdf0e10cSrcweir if [ $ret -eq 0 ]; then 58cdf0e10cSrcweir wget=$i 59cdf0e10cSrcweir echo found wget: $wget 60cdf0e10cSrcweir break 2 61cdf0e10cSrcweir fi 62cdf0e10cSrcweirdone 63cdf0e10cSrcweir 64cdf0e10cSrcweirif [ -z "$wget" ]; then 65cdf0e10cSrcweir for i in curl /usr/bin/curl /usr/local/bin/curl /usr/sfw/bin/curl /opt/sfw/bin/curl /opt/local/bin/curl; do 66cdf0e10cSrcweir # mac curl returns "2" on --version 67cdf0e10cSrcweir # eval "$i --version" > /dev/null 2>&1 68cdf0e10cSrcweir # ret=$? 69cdf0e10cSrcweir # if [ $ret -eq 0 ]; then 70cdf0e10cSrcweir if [ -x $i ]; then 71cdf0e10cSrcweir curl=$i 72cdf0e10cSrcweir echo found curl: $curl 73cdf0e10cSrcweir break 2 74cdf0e10cSrcweir fi 75cdf0e10cSrcweir done 76cdf0e10cSrcweirfi 77cdf0e10cSrcweir 78cdf0e10cSrcweirif [ -z "$wget" -a -z "$curl" ]; then 79cdf0e10cSrcweir echo "ERROR: neither wget nor curl found!" 80cdf0e10cSrcweir exit 81cdf0e10cSrcweirfi 82cdf0e10cSrcweir 83cdf0e10cSrcweirfor i in md5 md5sum /usr/local/bin/md5sum gmd5sum /usr/sfw/bin/md5sum /opt/sfw/bin/gmd5sum /opt/local/bin/md5sum; do 84cdf0e10cSrcweir if [ "$i" = "md5" ]; then 85cdf0e10cSrcweir eval "$i -x" > /dev/null 2>&1 86cdf0e10cSrcweir else 87cdf0e10cSrcweir eval "$i --version" > /dev/null 2>&1 88cdf0e10cSrcweir fi 89cdf0e10cSrcweir ret=$? 90cdf0e10cSrcweir if [ $ret -eq 0 ]; then 91cdf0e10cSrcweir md5sum=$i 92cdf0e10cSrcweir echo found md5sum: $md5sum 93cdf0e10cSrcweir break 2 94cdf0e10cSrcweir fi 95cdf0e10cSrcweirdone 96cdf0e10cSrcweir 97cdf0e10cSrcweirif [ "$md5sum" = "md5" ]; then 98cdf0e10cSrcweir md5special=-r 99cdf0e10cSrcweirfi 100cdf0e10cSrcweir 101cdf0e10cSrcweirif [ -z "$md5sum" ]; then 102cdf0e10cSrcweir echo "Warning: no md5sum: found!" 103cdf0e10cSrcweirfi 104cdf0e10cSrcweir 105cdf0e10cSrcweirstart_dir=`pwd` 106cdf0e10cSrcweirlogfile=$TARFILE_LOCATION/fetch.log 107cdf0e10cSrcweirdate >> $logfile 108cdf0e10cSrcweir 109*fb6b49d1SJürgen Schmidt# Create and go to a temporary directory under the tar file destination. 110cdf0e10cSrcweirmkdir -p $TARFILE_LOCATION/tmp 111cdf0e10cSrcweircd $TARFILE_LOCATION/tmp 112*fb6b49d1SJürgen Schmidt 113*fb6b49d1SJürgen Schmidtif [ -n "$DMAKE_URL" -a ! -x "$SOLARENV/$OUTPATH/bin/dmake$EXEEXT" ]; then 114*fb6b49d1SJürgen Schmidt # Determine the name of the downloaded file. 115*fb6b49d1SJürgen Schmidt dmake_package_name=`echo $DMAKE_URL | sed "s/^\(.*\/\)//"` 116*fb6b49d1SJürgen Schmidt 117*fb6b49d1SJürgen Schmidt if [ ! -f "../$dmake_package_name" ]; then 118*fb6b49d1SJürgen Schmidt # Fetch the dmake source 119*fb6b49d1SJürgen Schmidt if [ ! -z "$wget" ]; then 120*fb6b49d1SJürgen Schmidt echo fetching $DMAKE_URL with wget to $TARFILE_LOCATION/tmp 121*fb6b49d1SJürgen Schmidt $wget -nv -N $DMAKE_URL 2>&1 | tee -a $logfile 122*fb6b49d1SJürgen Schmidt else 123*fb6b49d1SJürgen Schmidt echo fetching $DMAKE_URL with curl to $TARFILE_LOCATION/tmp 124*fb6b49d1SJürgen Schmidt $curl $file_date_check -O $DMAKE_URL 2>&1 | tee -a $logfile 125*fb6b49d1SJürgen Schmidt fi 126*fb6b49d1SJürgen Schmidt wret=$? 127*fb6b49d1SJürgen Schmidt 128*fb6b49d1SJürgen Schmidt # When the download failed then remove the remains, otherwise 129*fb6b49d1SJürgen Schmidt # move the downloaded file up to TARFILE_LOCATION 130*fb6b49d1SJürgen Schmidt if [ $wret -ne 0 ]; then 131*fb6b49d1SJürgen Schmidt echo "download failed. removing $dmake_package_name" 132*fb6b49d1SJürgen Schmidt rm "$dmake_package_name" 133*fb6b49d1SJürgen Schmidt failed="$failed $i" 134*fb6b49d1SJürgen Schmidt wret=0 135*fb6b49d1SJürgen Schmidt else 136*fb6b49d1SJürgen Schmidt mv "$dmake_package_name" .. 137*fb6b49d1SJürgen Schmidt echo "successfully downloaded $dmake_package_name" 138*fb6b49d1SJürgen Schmidt fi 139*fb6b49d1SJürgen Schmidt else 140*fb6b49d1SJürgen Schmidt echo "found $dmake_package_name, no need to download it again" 141*fb6b49d1SJürgen Schmidt fi 142*fb6b49d1SJürgen Schmidtfi 143*fb6b49d1SJürgen Schmidt 144*fb6b49d1SJürgen Schmidt 145*fb6b49d1SJürgen Schmidt 146*fb6b49d1SJürgen Schmidtcd $TARFILE_LOCATION/tmp 147*fb6b49d1SJürgen Schmidtfilelist=`cat $1` 148cdf0e10cSrcweirecho $$ > fetch-running 149cdf0e10cSrcweirfor i in $filelist ; do 150cdf0e10cSrcweir# echo $i 151cdf0e10cSrcweir if [ "$i" != `echo $i | sed "s/^http:\///"` ]; then 152cdf0e10cSrcweir tarurl=$i 153cdf0e10cSrcweir # TODO: check for comment 154cdf0e10cSrcweir else 155cdf0e10cSrcweir if [ "$tarurl" != "" ]; then 156cdf0e10cSrcweir if [ ! -f "../$i" ]; then 157cdf0e10cSrcweir echo $i 158cdf0e10cSrcweir if [ ! -z "$wget" ]; then 159cdf0e10cSrcweir $wget -nv -N $tarurl/$i 2>&1 | tee -a $logfile 160cdf0e10cSrcweir else 161cdf0e10cSrcweir echo fetching $i 162cdf0e10cSrcweir $curl $file_date_check -O $tarurl/$i 2>&1 | tee -a $logfile 163cdf0e10cSrcweir fi 164cdf0e10cSrcweir wret=$? 165cdf0e10cSrcweir if [ $wret -ne 0 ]; then 166cdf0e10cSrcweir mv $i ${i}_broken 167cdf0e10cSrcweir failed="$failed $i" 168cdf0e10cSrcweir wret=0 169cdf0e10cSrcweir fi 170cdf0e10cSrcweir if [ -f $i -a -n "$md5sum" ]; then 171cdf0e10cSrcweir sum=`$md5sum $md5special $i | sed "s/ .*//"` 172cdf0e10cSrcweir sum2=`echo $i | sed "s/-.*//"` 173cdf0e10cSrcweir if [ "$sum" != "$sum2" ]; then 174cdf0e10cSrcweir echo checksum failure for $i 2>&1 | tee -a $logfile 175cdf0e10cSrcweir failed="$failed $i" 176cdf0e10cSrcweir mv $i ${i}_broken 177cdf0e10cSrcweir else 178cdf0e10cSrcweir mv $i .. 179cdf0e10cSrcweir fi 180cdf0e10cSrcweir else 181cdf0e10cSrcweir mv $i .. 182cdf0e10cSrcweir fi 183cdf0e10cSrcweir fi 184cdf0e10cSrcweir fi 185cdf0e10cSrcweir fi 186cdf0e10cSrcweirdone 187cdf0e10cSrcweirrm $TARFILE_LOCATION/tmp/*-* 188cdf0e10cSrcweircd $start_dir 189cdf0e10cSrcweir 190cdf0e10cSrcweirif [ ! -z "$failed" ]; then 191cdf0e10cSrcweir echo 192cdf0e10cSrcweir echo ERROR: failed on: 193cdf0e10cSrcweir for i in $failed ; do 194cdf0e10cSrcweir echo $i 195cdf0e10cSrcweir done 196cdf0e10cSrcweir exit 1 197cdf0e10cSrcweirfi 198cdf0e10cSrcweir 199