1#!/bin/bash 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 29file_list_name=$1 30 31if [ -z "$TARFILE_LOCATION" ]; then 32 echo "ERROR: no destination defined! please set TARFILE_LOCATION!" 33 exit 34fi 35 36if [ ! -d "$TARFILE_LOCATION" ]; then 37 mkdir $TARFILE_LOCATION 38fi 39if [ ! -d "$TARFILE_LOCATION" ]; then 40 echo "ERROR: can't create" 41 exit 42fi 43 44if [ -z "$1" ]; then 45 echo "ERROR: parameter missing!" 46 echo "usage: $0 <fetch list>" 47 echo "first line must define the base url." 48 exit 49fi 50 51# Downloader method selection 52fetch_bin= 53fetch_args= 54 55#Look for FreeBSD's fetch(1) first 56if [ -x /usr/bin/fetch ]; then 57 fetch_bin=/usr/bin/fetch 58 fetch_args="-AFpr" 59 echo found FreeBSD fetch: $fetch_bin 60 break 2 61else 62 for wg in wget /usr/bin/wget /usr/local/bin/wget /usr/sfw/bin/wget /opt/sfw/bin/wget /opt/local/bin/wget; do 63 eval "$wg --version" > /dev/null 2>&1 64 ret=$? 65 if [ $ret -eq 0 ]; then 66 fetch_bin=$wg 67 fetch_args="-nv -N" 68 echo found wget at `which $fetch_bin` 69 break 2 70 fi 71 done 72 if [ -z "$fetch_bin" ]; then 73 for c in curl /usr/bin/curl /usr/local/bin/curl /usr/sfw/bin/curl /opt/sfw/bin/curl /opt/local/bin/curl; do 74 # mac curl returns "2" on --version 75 # eval "$i --version" > /dev/null 2>&1 76 # ret=$? 77 # if [ $ret -eq 0 ]; then 78 if [ -x $c ]; then 79 fetch_bin=$c 80 fetch_args="$file_date_check -O" 81 echo found curl at `which $fetch_bin` 82 break 2 83 fi 84 done 85 fi 86 if [ -z "$fetch_bin" ]; then 87 echo "ERROR: neither wget nor curl found!" 88 exit 89 fi 90fi 91 92#Checksummer selection 93md5sum= 94 95for i in md5 md5sum /usr/local/bin/md5sum gmd5sum /usr/sfw/bin/md5sum /opt/sfw/bin/gmd5sum /opt/local/bin/md5sum; do 96 if [ "$i" = "md5" ]; then 97 eval "$i -x" > /dev/null 2>&1 98 else 99 eval "$i --version" > /dev/null 2>&1 100 fi 101 ret=$? 102 if [ $ret -eq 0 ]; then 103 md5sum=$i 104 echo found md5sum at `which $md5sum` 105 break 2 106 fi 107done 108 109if [ "$md5sum" = "md5" ]; then 110 md5special=-r 111fi 112 113if [ -z "$md5sum" ]; then 114 echo "Warning: no md5sum: found!" 115fi 116 117start_dir=`pwd` 118logfile=$TARFILE_LOCATION/fetch.log 119date >> $logfile 120 121# Create and go to a temporary directory under the tar file destination. 122mkdir -p $TARFILE_LOCATION/tmp 123cd $TARFILE_LOCATION/tmp 124 125 126function basename () 127{ 128 echo $1 | sed "s/^\(.*\/\)//" 129} 130 131 132# 133# Download a file from a URL and add its md5 checksum to its name. 134# 135function download () 136{ 137 local URL=$1 138 139 if [ -n "$URL" ]; then 140 local basename=$(basename $URL) 141 local candidate=$(find "$TARFILE_LOCATION" -type f -name "*-$basename") 142 if [ -n "$candidate" ]; then 143 echo "$basename is already present ($candidate)" 144 else 145 echo fetching $basename 146 $fetch_bin $fetch_args $URL 2>&1 | tee -a $logfile 147 148 if [ $? -ne 0 ]; then 149 echo "download failed" 150 mv $basename ${basename}_broken 151 failed="$failed $i" 152 elif [ -f "$basename" -a -n "$md5sum" ]; then 153 local sum=`$md5sum $md5special $basename | sed "s/ .*//"` 154 mv $basename "$TARFILE_LOCATION/$sum-$basename" 155 echo "added md5 sum $sum" 156 fi 157 fi 158 fi 159} 160 161# 162# Download a file from a URL and check its md5 sum to the one that is part of its name. 163# 164function download_and_check () 165{ 166 local URL=$1 167 168 if [ -n "$URL" ]; then 169 local basename=$(basename $URL) 170 if [ -f "$TARFILE_LOCATION/$basename" ]; then 171 echo "$basename is already present" 172 else 173 echo "fetching $basename" 174 $fetch_bin $fetch_args $URL 2>&1 | tee -a $logfile 175 176 if [ $? -ne 0 ]; then 177 echo "download failed" 178 mv $basename ${basename}_broken 179 failed="$failed $i" 180 elif [ -f "$basename" -a -n "$md5sum" ]; then 181 local sum=`$md5sum $md5special $basename | sed "s/ .*//"` 182 local sum_in_name=`echo $basename | sed "s/-.*//"` 183 if [ "$sum" != "$sum_in_name" ]; then 184 echo checksum failure for $basename 2>&1 | tee -a $logfile 185 failed="$failed $basename" 186 mv $basename ${basename}_broken 187 fi 188 mv $basename "$TARFILE_LOCATION/$basename" 189 fi 190 fi 191 fi 192} 193 194echo "downloading tar balls to $TARFILE_LOCATION" 195 196while read line ; do 197 # Remove leading and trailing space and comments 198 line=`echo $line | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/[[:space:]]*#.*$//'` 199 case $line in 200 # Ignore empty lines. 201 '') 202 ;; 203 204 # When a URL ends in a / then it is taken as a partial URL 205 # to which the following lines will be appended. 206 ftp:\/\/*\/ | http:\/\/*\/) 207 UrlHead=$line 208 echo $UrlHead 209 ;; 210 211 # A full URL represents a single file which is downloaded. 212 ftp:\/\/* | http:\/\/*) 213 download $line 214 ;; 215 216 # Any other line is interpreted as the second part of a partial URL. 217 # It is appended to UrlHead and then downloaded. 218 *) 219 download_and_check $UrlHead$line 220 ;; 221 esac 222done < "$file_list_name" 223 224 225# Special handling of dmake 226if [ -n "$DMAKE_URL" -a ! -x "$SOLARENV/$OUTPATH/bin/dmake$EXEEXT" ]; then 227 download $DMAKE_URL 228fi 229 230# Special handling of epm-3.7 231# Basically just a download of the epm archive. 232# When its name contains "-source" than that part is removed. 233epm_archive_tail=`echo $(basename $EPM_URL) | sed 's/-source//'` 234epm_archive_name=$(find "$TARFILE_LOCATION" -type f -name "*-$epm_archive_tail") 235if [ -n "$EPM_URL" -a ! -x "$SOLARENV/$OUTPATH/bin/epm$EXEEXT" -a -z "$epm_archive_name" ]; then 236 download $EPM_URL 237 archive_name=$(find "$TARFILE_LOCATION" -type f -name "*-epm-3.7-source*") 238 if [ -n "$archive_name" ]; then 239 epm_archive_name=`echo $archive_name | sed 's/-source//'` 240 mv "$archive_name" "$epm_archive_name" 241 fi 242fi 243 244if [ ! -z "$failed" ]; then 245 echo 246 echo ERROR: failed on: 247 for i in $failed ; do 248 echo $i 249 done 250 exit 1 251fi 252 253