xref: /AOO41X/main/fetch_tarballs.sh (revision 8f3b6ea49fbe2807ff26926b4a8ffaaa1efbfeda)
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#Special handling of epm
146if [ -n "$EPM_URL" -a ! -x "$SOLARENV/$OUTPATH/bin/epm$EXEEXT" ]; then
147    # Determine the name of the downloaded file.
148    epm_package_name=`echo $EPM_URL | sed "s/^\(.*\/\)//"`
149    epm_package=`echo $epm_package_name | sed "s/-source//"`
150    epm_wildcard_package_name="*-$epm_package"
151
152    epmtest=$(find .. -type f -name "$epm_wildcard_package_name")
153
154    # check with wildcard for the renamed package, md5
155    if [ -z "$epmtest" ]; then
156        # Fetch the epm source
157        if [ ! -z "$wget" ]; then
158            echo fetching $EPM_URL with wget to $TARFILE_LOCATION/tmp
159            $wget -nv -N $EPM_URL 2>&1 | tee -a $logfile
160        else
161            echo fetching $EPM_URL with curl to $TARFILE_LOCATION/tmp
162            $curl $file_date_check -O $EPM_URL 2>&1 | tee -a $logfile
163        fi
164        wret=$?
165
166        # When the download failed then remove the remains, otherwise
167        # move the downloaded file up to TARFILE_LOCATION and rename it
168	# according our naing convention for external tar balls.
169        if [ $wret -ne 0 ]; then
170            echo "download failed. removing $epm_package_name"
171            rm "$epm_package_name"
172            failed="$failed $i"
173            wret=0
174        else
175            #mv "$epm_package_name" ..
176	    epm_md5_sum=`$md5sum $md5special $epm_package_name | sed "s/ .*//"`
177	    epm_md5_package_name="$epm_md5_sum-$epm_package"
178
179	    rm -f ../$epm_md5_package_name && \
180		cp -pRP $epm_package_name ../$epm_md5_package_name && \
181		rm -rf $epm_package_name
182            echo "successfully downloaded $epm_package_name and renamed to $epm_md5_package_name"
183        fi
184    else
185        echo "found $epmtest, no need to download it again"
186    fi
187fi
188# end special
189
190
191cd $TARFILE_LOCATION/tmp
192filelist=`cat $1`
193echo $$ > fetch-running
194for i in $filelist ; do
195#    echo $i
196    if [ "$i" != `echo $i | sed "s/^http:\///"` ]; then
197        tarurl=$i
198    # TODO: check for comment
199    else
200        if [ "$tarurl" != "" ]; then
201            if [ ! -f "../$i" ]; then
202                echo $i
203                if [ ! -z "$wget" ]; then
204                    $wget -nv -N $tarurl/$i 2>&1 | tee -a $logfile
205                else
206                    echo fetching $i
207                    $curl $file_date_check -O $tarurl/$i 2>&1 | tee -a $logfile
208                fi
209                wret=$?
210                if [ $wret -ne 0 ]; then
211                    mv $i ${i}_broken
212                    failed="$failed $i"
213                    wret=0
214                fi
215                if [ -f $i -a -n "$md5sum" ]; then
216                    sum=`$md5sum $md5special $i | sed "s/ .*//"`
217                    sum2=`echo $i | sed "s/-.*//"`
218                    if [ "$sum" != "$sum2" ]; then
219                        echo checksum failure for $i 2>&1 | tee -a $logfile
220                        failed="$failed $i"
221                        mv $i ${i}_broken
222                    else
223                        mv $i ..
224                    fi
225                else
226                    mv $i ..
227                fi
228            fi
229        fi
230    fi
231done
232rm $TARFILE_LOCATION/tmp/*-*
233cd $start_dir
234
235if [ ! -z "$failed" ]; then
236    echo
237    echo ERROR: failed on:
238    for i in $failed ; do
239        echo $i
240    done
241    exit 1
242fi
243
244