2010-08-03

Automatic FlightGear Scenario Downloader

FlightGear is a very nice open source flight simulator software. A major component of any flight simulator is the world scenery. The FlightGear project provides scenery files for the complete world on their FTP server. Unfortunately, the world scenery consists of more than 500 files. Each file approx 50 to 70 mega bytes in size.

A manual download of these files would require much endurance, as the server only permits four parallel downloads at the same time.

Therefore, I developed a script for automatic scenario downloading. Now, my computer can download the whole world scenery without any user interaction.

The script provides two interesting features:

It extracts a download list from the MD5SUM file that is available on the webserver. Thus, the downloader automatically detects which files are available. Later the MD5 sums are used to verify if the download was successful or not.

Furthermore, the scipt checks if files have been downloaded in the past. It skips these files to prevent downloading files twice. This way the user can easily interrupt and continue the downloading process.


#!/bin/bash

# Permission is hereby granted, free of charge,
# to any person obtaining a copy of this software
# and associated documentation files (the
# "Software"), to deal in the Software without
# restriction, including without limitation the
# rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom
# the Software is furnished to do so, subject
# to the following conditions:
#
# This permission notice shall be included in
# all copies or substantial portions of
# the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT
# WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.


URL="ftp://ftp.ibiblio.org/pub/mirrors/flightgear/ftp/Scenery-1.0.1/"
MD5SUM="MD5SUM"

WGET="/usr/bin/wget"
MD5="/usr/bin/md5sum"

if [ ! -f $MD5SUM ]
then
echo "### Downloading MD5SUM file"
wget "$URL$MD5SUM"
fi

if [ -f $MD5SUM ]
then
FILELIST=$(cat $MD5SUM | awk '{print $2}')
MD5LIST=$(cat $MD5SUM | awk '{print $1}')
CNT=1;

for FILE in $FILELIST
do
if [ ! -f $FILE ]
then
echo "### Downloading $FILE"
wget "$URL$FILE"

MD5ORIG=$(echo $MD5LIST | cut -d ' ' -f $CNT)
MD5FILE=$($MD5 $FILE | awk '{print $1}')

if [ $MD5ORIG == $MD5FILE ]
then
echo "### Success"
else
echo "### Error"
fi
else
echo "### File $FILE exists!"
fi

let CNT=$CNT+1
done


else
echo "### ERROR: Can not find file $MD5SUM"
fi


If you are not interested in FlightGear, you maybe use this scipt to download other files based on a MD5SUM file provided on a Web or FTP site.