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# Downloader method selection 50fetch_bin= 51fetch_args= 52 53#Look for FreeBSD's fetch(1) first 54if [ -x /usr/bin/fetch ]; then 55 fetch_bin=/usr/bin/fetch 56 fetch_args="-AFpr" 57 echo found FreeBSD fetch: $fetch_bin 58 break 2 59else 60 for wg in wget /usr/bin/wget /usr/local/bin/wget /usr/sfw/bin/wget /opt/sfw/bin/wget /opt/local/bin/wget; do 61 eval "$wg --version" > /dev/null 2>&1 62 ret=$? 63 if [ $ret -eq 0 ]; then 64 fetch_bin=$wg 65 fetch_args="-nv -N" 66 echo found wget: $fetch_bin 67 break 2 68 fi 69 done 70 if [ -z "$fetch_bin" ]; then 71 for c in curl /usr/bin/curl /usr/local/bin/curl /usr/sfw/bin/curl /opt/sfw/bin/curl /opt/local/bin/curl; do 72 # mac curl returns "2" on --version 73 # eval "$i --version" > /dev/null 2>&1 74 # ret=$? 75 # if [ $ret -eq 0 ]; then 76 if [ -x $c ]; then 77 fetch_bin=$c 78 fetch_args="$file_date_check -O" 79 echo found curl: $fetch_bin 80 break 2 81 fi 82 done 83 fi 84 if [ -z "$fetch_bin" ]; then 85 echo "ERROR: neither wget nor curl found!" 86 exit 87 fi 88fi 89 90#Checksummer selection 91md5sum= 92 93for i in md5 md5sum /usr/local/bin/md5sum gmd5sum /usr/sfw/bin/md5sum /opt/sfw/bin/gmd5sum /opt/local/bin/md5sum; do 94 if [ "$i" = "md5" ]; then 95 eval "$i -x" > /dev/null 2>&1 96 else 97 eval "$i --version" > /dev/null 2>&1 98 fi 99 ret=$? 100 if [ $ret -eq 0 ]; then 101 md5sum=$i 102 echo found md5sum: $md5sum 103 break 2 104 fi 105done 106 107if [ "$md5sum" = "md5" ]; then 108 md5special=-r 109fi 110 111if [ -z "$md5sum" ]; then 112 echo "Warning: no md5sum: found!" 113fi 114 115start_dir=`pwd` 116logfile=$TARFILE_LOCATION/fetch.log 117date >> $logfile 118 119# Create and go to a temporary directory under the tar file destination. 120mkdir -p $TARFILE_LOCATION/tmp 121cd $TARFILE_LOCATION/tmp 122 123if [ -n "$DMAKE_URL" -a ! -x "$SOLARENV/$OUTPATH/bin/dmake$EXEEXT" ]; then 124 # Determine the name of the downloaded file. 125 dmake_package_name=`echo $DMAKE_URL | sed "s/^\(.*\/\)//"` 126 127 if [ ! -f "../$dmake_package_name" ]; then 128 # Fetch the dmake source 129 echo fetching $DMAKE_URL to $TARFILE_LOCATION/tmp 130 $fetch_bin $fetch_args $DMAKE_URL 2>&1 | tee -a $logfile 131 wret=$? 132 133 # When the download failed then remove the remains, otherwise 134 # move the downloaded file up to TARFILE_LOCATION 135 if [ $wret -ne 0 ]; then 136 echo "download failed. removing $dmake_package_name" 137 rm "$dmake_package_name" 138 failed="$failed $i" 139 wret=0 140 else 141 mv "$dmake_package_name" .. 142 echo "successfully downloaded $dmake_package_name" 143 fi 144 else 145 echo "found $dmake_package_name, no need to download it again" 146 fi 147fi 148 149 150#Special handling of epm 151if [ -n "$EPM_URL" -a ! -x "$SOLARENV/$OUTPATH/bin/epm$EXEEXT" ]; then 152 # Determine the name of the downloaded file. 153 epm_package_name=`echo $EPM_URL | sed "s/^\(.*\/\)//"` 154 epm_package=`echo $epm_package_name | sed "s/-source//"` 155 epm_wildcard_package_name="*-$epm_package" 156 157 epmtest=$(find .. -type f -name "$epm_wildcard_package_name") 158 159 # check with wildcard for the renamed package, md5 160 if [ -z "$epmtest" ]; then 161 # Fetch the epm source 162 echo fetching $EPM_URL to $TARFILE_LOCATION/tmp 163 $fetch_bin $fetch_args $EPM_URL 2>&1 | tee -a $logfile 164 165 wret=$? 166 167 # When the download failed then remove the remains, otherwise 168 # move the downloaded file up to TARFILE_LOCATION and rename it 169 # according our naing convention for external tar balls. 170 if [ $wret -ne 0 ]; then 171 echo "download failed. removing $epm_package_name" 172 rm "$epm_package_name" 173 failed="$failed $i" 174 wret=0 175 else 176 #mv "$epm_package_name" .. 177 epm_md5_sum=`$md5sum $md5special $epm_package_name | sed "s/ .*//"` 178 epm_md5_package_name="$epm_md5_sum-$epm_package" 179 180 rm -f ../$epm_md5_package_name && \ 181 cp -pRP $epm_package_name ../$epm_md5_package_name && \ 182 rm -rf $epm_package_name 183 echo "successfully downloaded $epm_package_name and renamed to $epm_md5_package_name" 184 fi 185 else 186 echo "found $epmtest, no need to download it again" 187 fi 188fi 189# end special 190 191 192cd $TARFILE_LOCATION/tmp 193filelist=`cat $1` 194echo $$ > fetch-running 195for i in $filelist ; do 196# echo $i 197 if [ "$i" != `echo $i | sed "s/^http:\///"` ]; then 198 tarurl=$i 199 # TODO: check for comment 200 else 201 if [ "$tarurl" != "" ]; then 202 if [ ! -f "../$i" ]; then 203 echo $i 204 echo fetching $i 205 $fetch_bin $fetch_args $tarurl/$i 2>&1 | tee -a $logfile 206 wret=$? 207 if [ $wret -ne 0 ]; then 208 mv $i ${i}_broken 209 failed="$failed $i" 210 wret=0 211 fi 212 if [ -f $i -a -n "$md5sum" ]; then 213 sum=`$md5sum $md5special $i | sed "s/ .*//"` 214 sum2=`echo $i | sed "s/-.*//"` 215 if [ "$sum" != "$sum2" ]; then 216 echo checksum failure for $i 2>&1 | tee -a $logfile 217 failed="$failed $i" 218 mv $i ${i}_broken 219 else 220 mv $i .. 221 fi 222 else 223 mv $i .. 224 fi 225 fi 226 fi 227 fi 228done 229rm $TARFILE_LOCATION/tmp/*-* 230cd $start_dir 231 232if [ ! -z "$failed" ]; then 233 echo 234 echo ERROR: failed on: 235 for i in $failed ; do 236 echo $i 237 done 238 exit 1 239fi 240 241