masterkain/ImageMagick-sl — pull request #27 by kenmazaika (2012-04-10 23:07:14+00:00)
Title: Follow 302 Redirects with Curl

The url for freetype redirects to a mirror.

Unfortunately this mirror changes every few minutes.

I made this patch a few minutes ago: https://github.com/kenmazaika/ImageMagick-sl/commit/3fc660d067be2c33c43237858fd2e31685962d84. 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

302 Found

Found

The document has moved here.

Apache/2.2.16 (Debian) Server at download.savannah.gnu.org Port 80

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$

```