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 109filelist=`cat $1` 110mkdir -p $TARFILE_LOCATION/tmp 111cd $TARFILE_LOCATION/tmp 112echo $$ > fetch-running 113for i in $filelist ; do 114# echo $i 115 if [ "$i" != `echo $i | sed "s/^http:\///"` ]; then 116 tarurl=$i 117 # TODO: check for comment 118 else 119 if [ "$tarurl" != "" ]; then 120 if [ ! -f "../$i" ]; then 121 echo $i 122 if [ ! -z "$wget" ]; then 123 $wget -nv -N $tarurl/$i 2>&1 | tee -a $logfile 124 else 125 echo fetching $i 126 $curl $file_date_check -O $tarurl/$i 2>&1 | tee -a $logfile 127 fi 128 wret=$? 129 if [ $wret -ne 0 ]; then 130 mv $i ${i}_broken 131 failed="$failed $i" 132 wret=0 133 fi 134 if [ -f $i -a -n "$md5sum" ]; then 135 sum=`$md5sum $md5special $i | sed "s/ .*//"` 136 sum2=`echo $i | sed "s/-.*//"` 137 if [ "$sum" != "$sum2" ]; then 138 echo checksum failure for $i 2>&1 | tee -a $logfile 139 failed="$failed $i" 140 mv $i ${i}_broken 141 else 142 mv $i .. 143 fi 144 else 145 mv $i .. 146 fi 147 fi 148 fi 149 fi 150done 151rm $TARFILE_LOCATION/tmp/*-* 152cd $start_dir 153 154if [ ! -z "$failed" ]; then 155 echo 156 echo ERROR: failed on: 157 for i in $failed ; do 158 echo $i 159 done 160 exit 1 161fi 162 163