xref: /AOO41X/main/fetch_tarballs.sh (revision b6b3385459af7139cffa75aaf0c7a2a4cd3067dd)
1a6ff3988SAndre Fischer#!/bin/bash
2cdf0e10cSrcweir#*************************************************************************
3cdf0e10cSrcweir#
4cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5cdf0e10cSrcweir#
6cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
7cdf0e10cSrcweir#
8cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
9cdf0e10cSrcweir#
10cdf0e10cSrcweir# This file is part of OpenOffice.org.
11cdf0e10cSrcweir#
12cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
13cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
14cdf0e10cSrcweir# only, as published by the Free Software Foundation.
15cdf0e10cSrcweir#
16cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
17cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
18cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
20cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
21cdf0e10cSrcweir#
22cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
23cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
24cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
25cdf0e10cSrcweir# for a copy of the LGPLv3 License.
26cdf0e10cSrcweir#
27cdf0e10cSrcweir#*************************************************************************
28cdf0e10cSrcweir
29a6ff3988SAndre Fischerfile_list_name=$1
30a6ff3988SAndre Fischer
31cdf0e10cSrcweirif [ -z "$TARFILE_LOCATION" ]; then
32cdf0e10cSrcweir    echo "ERROR: no destination defined! please set TARFILE_LOCATION!"
33cdf0e10cSrcweir    exit
34cdf0e10cSrcweirfi
35cdf0e10cSrcweir
36cdf0e10cSrcweirif [ ! -d "$TARFILE_LOCATION" ]; then
37cdf0e10cSrcweir    mkdir $TARFILE_LOCATION
38cdf0e10cSrcweirfi
39cdf0e10cSrcweirif [ ! -d "$TARFILE_LOCATION" ]; then
40cdf0e10cSrcweir    echo "ERROR: can't create"
41cdf0e10cSrcweir    exit
42cdf0e10cSrcweirfi
43cdf0e10cSrcweir
44cdf0e10cSrcweirif [ -z "$1" ]; then
45cdf0e10cSrcweir    echo "ERROR: parameter missing!"
46cdf0e10cSrcweir    echo "usage: $0 <fetch list>"
47cdf0e10cSrcweir    echo "first line must define the base url."
48cdf0e10cSrcweir    exit
49cdf0e10cSrcweirfi
50cdf0e10cSrcweir
51bd677bc4SPedro Giffuni# Downloader method selection
52bd677bc4SPedro Giffunifetch_bin=
539d275db6SAndre Fischerfetch_args=
54cdf0e10cSrcweir
55bd677bc4SPedro Giffuni#Look for FreeBSD's fetch(1) first
56bd677bc4SPedro Giffuniif [ -x /usr/bin/fetch ]; then
57bd677bc4SPedro Giffuni    fetch_bin=/usr/bin/fetch
58bd677bc4SPedro Giffuni    fetch_args="-AFpr"
59bd677bc4SPedro Giffuni    echo found FreeBSD fetch: $fetch_bin
60bd677bc4SPedro Giffuni    break 2
61bd677bc4SPedro Giffunielse
62bd677bc4SPedro Giffuni  for wg in wget /usr/bin/wget /usr/local/bin/wget /usr/sfw/bin/wget /opt/sfw/bin/wget /opt/local/bin/wget; do
639d275db6SAndre Fischer    eval "$wg --version" > /dev/null 2>&1
64cdf0e10cSrcweir    ret=$?
65cdf0e10cSrcweir    if [ $ret -eq 0 ]; then
66bd677bc4SPedro Giffuni        fetch_bin=$wg
67bd677bc4SPedro Giffuni	    fetch_args="-nv -N"
68a6ff3988SAndre Fischer        echo found wget at `which $fetch_bin`
69cdf0e10cSrcweir        break 2
70cdf0e10cSrcweir    fi
71cdf0e10cSrcweir  done
72bd677bc4SPedro Giffuni  if [ -z "$fetch_bin" ]; then
73bd677bc4SPedro Giffuni    for c in curl /usr/bin/curl /usr/local/bin/curl /usr/sfw/bin/curl /opt/sfw/bin/curl /opt/local/bin/curl; do
74cdf0e10cSrcweir    # mac curl returns "2" on --version
75cdf0e10cSrcweir    #    eval "$i --version" > /dev/null 2>&1
76cdf0e10cSrcweir    #    ret=$?
77cdf0e10cSrcweir    #    if [ $ret -eq 0 ]; then
789d275db6SAndre Fischer        if [ -x $c ]; then
79bd677bc4SPedro Giffuni            fetch_bin=$c
80bd677bc4SPedro Giffuni	        fetch_args="$file_date_check -O"
81a6ff3988SAndre Fischer            echo found curl at `which $fetch_bin`
82cdf0e10cSrcweir            break 2
83cdf0e10cSrcweir        fi
84cdf0e10cSrcweir    done
85cdf0e10cSrcweir  fi
86bd677bc4SPedro Giffuni  if [ -z "$fetch_bin" ]; then
87cdf0e10cSrcweir    echo "ERROR: neither wget nor curl found!"
88cdf0e10cSrcweir    exit
89cdf0e10cSrcweir  fi
90bd677bc4SPedro Giffunifi
91bd677bc4SPedro Giffuni
92bd677bc4SPedro Giffuni#Checksummer selection
93bd677bc4SPedro Giffunimd5sum=
94cdf0e10cSrcweir
95cdf0e10cSrcweirfor i in md5 md5sum /usr/local/bin/md5sum gmd5sum /usr/sfw/bin/md5sum /opt/sfw/bin/gmd5sum /opt/local/bin/md5sum; do
96cdf0e10cSrcweir    if [ "$i" = "md5" ]; then
97cdf0e10cSrcweir        eval "$i -x" > /dev/null 2>&1
98cdf0e10cSrcweir    else
99cdf0e10cSrcweir        eval "$i --version" > /dev/null 2>&1
100cdf0e10cSrcweir    fi
101cdf0e10cSrcweir    ret=$?
102cdf0e10cSrcweir    if [ $ret -eq 0 ]; then
103cdf0e10cSrcweir        md5sum=$i
104a6ff3988SAndre Fischer        echo found md5sum at `which $md5sum`
105cdf0e10cSrcweir        break 2
106cdf0e10cSrcweir    fi
107cdf0e10cSrcweirdone
108cdf0e10cSrcweir
109cdf0e10cSrcweirif [ "$md5sum" = "md5" ]; then
110cdf0e10cSrcweir    md5special=-r
111cdf0e10cSrcweirfi
112cdf0e10cSrcweir
113cdf0e10cSrcweirif [ -z "$md5sum" ]; then
114cdf0e10cSrcweir    echo "Warning: no md5sum: found!"
115cdf0e10cSrcweirfi
116cdf0e10cSrcweir
117cdf0e10cSrcweirstart_dir=`pwd`
118cdf0e10cSrcweirlogfile=$TARFILE_LOCATION/fetch.log
119cdf0e10cSrcweirdate >> $logfile
120cdf0e10cSrcweir
121fb6b49d1SJürgen Schmidt# Create and go to a temporary directory under the tar file destination.
122cdf0e10cSrcweirmkdir -p $TARFILE_LOCATION/tmp
123cdf0e10cSrcweircd $TARFILE_LOCATION/tmp
124fb6b49d1SJürgen Schmidt
125fb6b49d1SJürgen Schmidt
126a6ff3988SAndre Fischerfunction basename ()
127a6ff3988SAndre Fischer{
128a6ff3988SAndre Fischer    echo $1 | sed "s/^\(.*\/\)//"
129a6ff3988SAndre Fischer}
130fb6b49d1SJürgen Schmidt
131a6ff3988SAndre Fischer
132a6ff3988SAndre Fischer#
133a6ff3988SAndre Fischer# Download a file from a URL and add its md5 checksum to its name.
134a6ff3988SAndre Fischer#
135a6ff3988SAndre Fischerfunction download ()
136a6ff3988SAndre Fischer{
137a6ff3988SAndre Fischer    local URL=$1
138a6ff3988SAndre Fischer
139a6ff3988SAndre Fischer    if [ -n "$URL" ]; then
140a6ff3988SAndre Fischer        local basename=$(basename $URL)
141a6ff3988SAndre Fischer        local candidate=$(find "$TARFILE_LOCATION" -type f -name "*-$basename")
142a6ff3988SAndre Fischer        if [ -n "$candidate" ]; then
143a6ff3988SAndre Fischer            echo "$basename is already present ($candidate)"
144a6ff3988SAndre Fischer        else
145a6ff3988SAndre Fischer		    echo fetching $basename
146a6ff3988SAndre Fischer	        $fetch_bin $fetch_args $URL 2>&1 | tee -a $logfile
147a6ff3988SAndre Fischer
148a6ff3988SAndre Fischer            if [ $? -ne 0 ]; then
149a6ff3988SAndre Fischer                echo "download failed"
150a6ff3988SAndre Fischer                mv $basename ${basename}_broken
151fb6b49d1SJürgen Schmidt                failed="$failed $i"
152a6ff3988SAndre Fischer            elif [ -f "$basename" -a -n "$md5sum" ]; then
153a6ff3988SAndre Fischer                local sum=`$md5sum $md5special $basename | sed "s/ .*//"`
154a6ff3988SAndre Fischer                mv $basename "$TARFILE_LOCATION/$sum-$basename"
155a6ff3988SAndre Fischer                echo "added md5 sum $sum"
156fb6b49d1SJürgen Schmidt            fi
157fb6b49d1SJürgen Schmidt        fi
158a6ff3988SAndre Fischer    fi
159a6ff3988SAndre Fischer}
160fb6b49d1SJürgen Schmidt
161a6ff3988SAndre Fischer#
162a6ff3988SAndre Fischer# Download a file from a URL and check its md5 sum to the one that is part of its name.
163a6ff3988SAndre Fischer#
164a6ff3988SAndre Fischerfunction download_and_check ()
165a6ff3988SAndre Fischer{
166a6ff3988SAndre Fischer    local URL=$1
167a6ff3988SAndre Fischer
168a6ff3988SAndre Fischer    if [ -n "$URL" ]; then
169a6ff3988SAndre Fischer        local basename=$(basename $URL)
170a6ff3988SAndre Fischer        if [ -f "$TARFILE_LOCATION/$basename" ]; then
171a6ff3988SAndre Fischer            echo "$basename is already present"
172a6ff3988SAndre Fischer        else
173a6ff3988SAndre Fischer		    echo "fetching $basename"
174a6ff3988SAndre Fischer	        $fetch_bin $fetch_args $URL 2>&1 | tee -a $logfile
175a6ff3988SAndre Fischer
176a6ff3988SAndre Fischer            if [ $? -ne 0 ]; then
177a6ff3988SAndre Fischer                echo "download failed"
178a6ff3988SAndre Fischer                mv $basename ${basename}_broken
179a6ff3988SAndre Fischer                failed="$failed $i"
180a6ff3988SAndre Fischer            elif [ -f "$basename" -a -n "$md5sum" ]; then
181a6ff3988SAndre Fischer                local sum=`$md5sum $md5special $basename | sed "s/ .*//"`
182a6ff3988SAndre Fischer                local sum_in_name=`echo $basename | sed "s/-.*//"`
183a6ff3988SAndre Fischer                if [ "$sum" != "$sum_in_name" ]; then
184a6ff3988SAndre Fischer                    echo checksum failure for $basename 2>&1 | tee -a $logfile
185a6ff3988SAndre Fischer                    failed="$failed $basename"
186a6ff3988SAndre Fischer                    mv $basename ${basename}_broken
187a6ff3988SAndre Fischer                fi
188a6ff3988SAndre Fischer                mv $basename "$TARFILE_LOCATION/$basename"
189a6ff3988SAndre Fischer            fi
190a6ff3988SAndre Fischer        fi
191a6ff3988SAndre Fischer    fi
192a6ff3988SAndre Fischer}
193a6ff3988SAndre Fischer
194a6ff3988SAndre Fischerecho "downloading tar balls to $TARFILE_LOCATION"
195a6ff3988SAndre Fischer
196a6ff3988SAndre Fischerwhile read line ; do
197a6ff3988SAndre Fischer    # Remove leading and trailing space and comments
198a6ff3988SAndre Fischer    line=`echo $line | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/[[:space:]]*#.*$//'`
199a6ff3988SAndre Fischer    case $line in
200a6ff3988SAndre Fischer        # Ignore empty lines.
201a6ff3988SAndre Fischer        '')
202a6ff3988SAndre Fischer            ;;
203a6ff3988SAndre Fischer
204a6ff3988SAndre Fischer        # When a URL ends in a / then it is taken as a partial URL
205a6ff3988SAndre Fischer        # to which the following lines will be appended.
206a6ff3988SAndre Fischer        ftp:\/\/*\/ | http:\/\/*\/)
207a6ff3988SAndre Fischer            UrlHead=$line
208a6ff3988SAndre Fischer            echo $UrlHead
209a6ff3988SAndre Fischer            ;;
210a6ff3988SAndre Fischer
211a6ff3988SAndre Fischer        # A full URL represents a single file which is downloaded.
212a6ff3988SAndre Fischer        ftp:\/\/* | http:\/\/*)
213a6ff3988SAndre Fischer            download $line
214a6ff3988SAndre Fischer            ;;
215a6ff3988SAndre Fischer
216a6ff3988SAndre Fischer        # Any other line is interpreted as the second part of a partial URL.
217a6ff3988SAndre Fischer        # It is appended to UrlHead and then downloaded.
218a6ff3988SAndre Fischer        *)
219a6ff3988SAndre Fischer            download_and_check $UrlHead$line
220a6ff3988SAndre Fischer            ;;
221a6ff3988SAndre Fischer    esac
222a6ff3988SAndre Fischerdone < "$file_list_name"
223a6ff3988SAndre Fischer
224a6ff3988SAndre Fischer
225a6ff3988SAndre Fischer# Special handling of dmake
226a6ff3988SAndre Fischerif [ -n "$DMAKE_URL" -a ! -x "$SOLARENV/$OUTPATH/bin/dmake$EXEEXT" ]; then
227a6ff3988SAndre Fischer    download $DMAKE_URL
228a6ff3988SAndre Fischerfi
229fb6b49d1SJürgen Schmidt
230*b6b33854SAndre Fischer# Special handling of epm-3.7
231*b6b33854SAndre Fischer# Basically just a download of the epm archive.
232*b6b33854SAndre Fischer# When its name contains "-source" than that part is removed.
233*b6b33854SAndre Fischerepm_archive_tail=`echo $(basename $EPM_URL) | sed 's/-source//'`
234*b6b33854SAndre Fischerepm_archive_name=$(find "$TARFILE_LOCATION" -type f -name "*-$epm_archive_tail")
235*b6b33854SAndre Fischerif [ -n "$EPM_URL" -a ! -x "$SOLARENV/$OUTPATH/bin/epm$EXEEXT" -a -z "$epm_archive_name" ]; then
236a6ff3988SAndre Fischer    download $EPM_URL
237*b6b33854SAndre Fischer    archive_name=$(find "$TARFILE_LOCATION" -type f -name "*-epm-3.7-source*")
238*b6b33854SAndre Fischer    if [ -n "$archive_name" ]; then
239*b6b33854SAndre Fischer        epm_archive_name=`echo $archive_name | sed 's/-source//'`
240*b6b33854SAndre Fischer        mv "$archive_name" "$epm_archive_name"
241a6ff3988SAndre Fischer    fi
242*b6b33854SAndre Fischerfi
243cdf0e10cSrcweir
244cdf0e10cSrcweirif [ ! -z "$failed" ]; then
245cdf0e10cSrcweir    echo
246cdf0e10cSrcweir    echo ERROR: failed on:
247cdf0e10cSrcweir    for i in $failed ; do
248cdf0e10cSrcweir        echo $i
249cdf0e10cSrcweir    done
250cdf0e10cSrcweir    exit 1
251cdf0e10cSrcweirfi
252cdf0e10cSrcweir
253