#!/bin/bash
#
#       UpdateWine.sh
#
#       Version: 0.0.1
#
#       Copyright 2011 Claudio Giordano <claudio.giordano@autistici.org>
#
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 3 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

clear

BaseUrl="http://dev.carbon-project.org/debian/wine-unstable/"
if [ $(arch) == "x86_64" ]
then
	Arch="amd64"
else
	Arch="i386"
fi

TempDir=`mktemp --directory`

echo -n "Download index file from site..."
wget -q $BaseUrl -O $TempDir"/index.php"
echo " done."

for file in $(grep "href=\".*$Arch.deb\"" -o $TempDir"/index.php" | egrep -v "dbg|dev")
do
	echo -n "Download file "${file:6:-1}
	wget wget -q $BaseUrl${file:6:-1} -O $TempDir"/"${file:6:-1}
	echo " done."
done
echo "Download complete."

echo "Install downloaded packages..."
dpkg -i $TempDir"/"*.deb
echo "Install complete."

echo -n "Removing temp dir..."
rm -rf $TempDir
echo " done."

exit 0
