#!/bin/bash
URL_DOWN="http://ppa.launchpad.net/nemh/gambas3/ubuntu/pool/main/g/gambas3/"
wget -c $URL_DOWN
arch=$(uname -m)
if [ "$arch" == 'x86_64' ]
then
    ARCHITECTURE=amd64
else
    ARCHITECTURE=i386
fi
GB3_GB_IMAGE=$(cat ./index.html | egrep gambas3-gb-image_ | egrep saucy | egrep $ARCHITECTURE.deb | sed -n '1p' | awk {'print $6'} | cut -d ">" -f 2 | cut -d '<' -f 1)

GB3_GB_GTK=$(cat ./index.html | egrep gambas3-gb-gtk_ | egrep saucy | egrep $ARCHITECTURE.deb | sed -n '1p' | awk {'print $6'} | cut -d ">" -f 2 | cut -d '<' -f 1)

GB3_GB_FORM=$(cat ./index.html | egrep gambas3-gb-form_ | egrep saucy | egrep all.deb | sed -n '1p' | awk {'print $6'} | cut -d ">" -f 2 | cut -d '<' -f 1)

GB3_GB_DESKTOP=$(cat ./index.html | egrep gambas3-gb-desktop_ | egrep saucy | egrep $ARCHITECTURE.deb | sed -n '1p' | awk {'print $6'} | cut -d ">" -f 2 | cut -d '<' -f 1)

GB3_GB_FORM_STOCK=$(cat ./index.html | egrep gambas3-gb-form-stock_ | egrep saucy | egrep all.deb | sed -n '1p' | awk {'print $6'} | cut -d ">" -f 2 | cut -d '<' -f 1)

GB3_RUNTIME=$(cat ./index.html | egrep gambas3-runtime_ | egrep saucy | egrep $ARCHITECTURE.deb | sed -n '1p' | awk {'print $6'} | cut -d ">" -f 2 | cut -d '<' -f 1)

GB3_GB_QT4=$(cat ./index.html | egrep gambas3-gb-qt4_ | egrep saucy | egrep $ARCHITECTURE.deb | sed -n '1p' | awk {'print $6'} | cut -d ">" -f 2 | cut -d '<' -f 1)

#GB3_GB_WEB=$(cat ./index.html | egrep gambas3-gb-web_ | egrep saucy | egrep all.deb | sed -n '1p' | awk {'print $6'} | cut -d ">" -f 2 | cut -d '<' -f 1)

wget -c "$URL_DOWN$GB3_GB_IMAGE"
wget -c "$URL_DOWN$GB3_GB_GTK"
wget -c "$URL_DOWN$GB3_GB_FORM"
wget -c "$URL_DOWN$GB3_GB_DESKTOP"
wget -c "$URL_DOWN$GB3_GB_FORM_STOCK"
wget -c "$URL_DOWN$GB3_RUNTIME"
wget -c "$URL_DOWN$GB3_GB_GUI"
wget -c "$URL_DOWN$GB3_GB_QT4"

echo $GB3_GB_IMAGE
echo $GB3_GB_GTK
echo $GB3_GB_FORM
echo $GB3_GB_DESKTOP
echo $GB3_GB_FORM_STOCK
echo $GB3_RUNTIME
echo $GB3_GB_GUI
echo $GB3_GB_QT4

ar x $GB3_GB_IMAGE
tar -zxvf data.tar.gz -C ./
rm data.tar.gz control.tar.gz debian-binary
ar x $GB3_GB_GTK
tar -zxvf data.tar.gz -C ./
rm data.tar.gz control.tar.gz debian-binary
ar x $GB3_GB_FORM
tar -zxvf data.tar.gz -C ./
rm data.tar.gz control.tar.gz debian-binary
ar x $GB3_GB_DESKTOP
tar -zxvf data.tar.gz -C ./
rm data.tar.gz control.tar.gz debian-binary
ar x $GB3_GB_FORM_STOCK
tar -zxvf data.tar.gz -C ./
rm data.tar.gz control.tar.gz debian-binary
ar x $GB3_RUNTIME
tar -zxvf data.tar.gz -C ./
rm data.tar.gz control.tar.gz debian-binary
ar x $GB3_GB_QT4
tar -zxvf data.tar.gz -C ./
rm data.tar.gz control.tar.gz debian-binary

make

