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