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