Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Follow 302 Redirects with Curl #27

Merged
merged 1 commit into from

2 participants

@kenmazaika

The url for freetype redirects to a mirror.

Unfortunately this mirror changes every few minutes.

I made this patch a few minutes ago: kenmazaika@3fc660d. I double checked the script still worked 15 minutes after I made that change, and it did not. It redirected to a different location.

I figured it made sense to follow redirects so when mirrors redirect to a new valid url, this script will automatically pick it up. This can be done using the -L option in curl.

Initial Script Output

bulletproof:ImageMagick-sl ken$ bash install_im.sh 
---------------------------------------------------------------------
ImageMagick installation started.
Please note that there are incompatibilies with MacPorts.
Read: http://github.com/masterkain/ImageMagick-sl/issues/#issue/1 - reported by Nico Ritsche
---------------------------------------------------------------------
Downloading http://heanet.dl.sourceforge.net/project/gs-fonts/gs-fonts/8.11%20%28base%2035%2C%20GPL%29/ghostscript-fonts-std-8.11.tar.gz
######################################################################## 100.0%
Downloading http://heanet.dl.sourceforge.net/project/wvware/libwmf/0.2.8.4/libwmf-0.2.8.4.tar.gz
######################################################################## 100.0%
Downloading http://www.ijg.org/files/jpegsrc.v8d.tar.gz
######################################################################## 100.0%
Downloading http://download.osgeo.org/libtiff/tiff-4.0.1.tar.gz
######################################################################## 100.0%
Downloading http://heanet.dl.sourceforge.net/project/lcms/lcms/2.3/lcms2-2.3.tar.gz
######################################################################## 100.0%
Downloading ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.5.10.tar.gz
######################################################################## 100.0%
######################################################################## 100.0%Downloading http://download.savannah.gnu.org/releases/freetype/freetype-2.4.9.tar.gz
######################################################################## 100.0%
Failed download: http://download.savannah.gnu.org/releases/freetype/freetype-2.4.9.tar.gz, size: 356B, aborting.

Debugging the issue:

bulletproof:im ken$ ls
bulletproof:im ken$ curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.4.9.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   356  100   356    0     0   2434      0 --:--:-- --:--:-- --:--:-- 12714
bulletproof:im ken$ cat freetype-2.4.9.tar.gz 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://download.savannah.gnu.org/releases-redirect/freetype/freetype-2.4.9.tar.gz">here</a>.</p>
<hr>
<address>Apache/2.2.16 (Debian) Server at download.savannah.gnu.org Port 80</address>
</body></html>
bulletproof:im ken$ echo "d'oh"
d'oh
bulletproof:im ken$ curl -O -L http://download.savannah.gnu.org/releases/freetype/freetype-2.4.9.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1955k  100 1955k    0     0   797k      0  0:00:02  0:00:02 --:--:-- 1005k
bulletproof:im ken$ ls -ltr
total 3912
-rw-r--r--  1 ken  wheel  2002410 Apr 10 18:56 freetype-2.4.9.tar.gz
bulletproof:im ken$ 

@masterkain masterkain merged commit f27eabe into masterkain:master
@masterkain
Owner

thanks @kenmazaika

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2012
  1. @kenmazaika
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  install_im.sh
View
2  install_im.sh
@@ -31,7 +31,7 @@ function try_download () {
file_name=`echo "$1" | ruby -ruri -e 'puts File.basename(gets.to_s.chomp)'` # I cheated.
rm -f $file_name # Cleanup in case of retry.
echo "Downloading $1"
- curl --fail --progress-bar -O --url $1
+ curl --fail --progress-bar -O -L --url $1
result=$? # Store the code of the last action, should be 0 for a successfull download.
file_size=`ls -l "$file_name" | awk '{print $5}'`
# We check for normal errors, otherwise check the file size.
Something went wrong with that request. Please try again.