#!/bin/sh -e
curl --connect-timeout 20 -m 10800 -L http://dl.google.com/earth/client/current/GoogleEarthLinux.bin > GoogleEarthLinux.bin
sh GoogleEarthLinux.bin --target gearthtmp --noexec
VERSION=$(grep -a -m1 '^label=' GoogleEarthLinux.bin | gawk '{ print $NF }' | tr -d '"')
tar -tf gearthtmp/googleearth-linux-x86.tar > googleearth-files-$VERSION.list
tar -tf gearthtmp/googleearth-data.tar >> googleearth-files-$VERSION.list
echo "# start replace"
echo "%define version	$VERSION"
echo "%define md5sum	$(md5sum GoogleEarthLinux.bin | gawk '{ print $1 }')"
cd gearthtmp
mkdir xtmp
tar -C xtmp -xf googleearth-linux-x86.tar
cd xtmp
find *.so* > sos
echo "%define realrequires $(echo $(pwd)/* | /usr/lib/rpm/mandriva/find-requires / i586 2>/dev/null | grep -v '\./' | grep -v -Ff sos | xargs echo)"
cd ../..
rm -rf gearthtmp
echo "# end replace"
