#!/bin/sh

yesno=`/usr/bin/defaults read com.techspansion.visualhub update`

if [ $yesno == 0 ]
then
exit 0
else
ver=$1

/usr/bin/curl http://www.techspansion.com/vhversion.txt > /tmp/visualhub_ver

newver=`/bin/cat /tmp/visualhub_ver | /usr/bin/head -1`

if [ $newver -gt $ver ]
then
	answer=`/usr/bin/osascript -l AppleScript -e 'tell application "VisualHub" to button returned of (display dialog "Hey, there'\''s a new version of VisualHub: " & (do shell script "/bin/cat /tmp/visualhub_ver | tail -1") buttons {"Stop asking", "Cancel", "Download"} default button "Download")'`
	if [ "$answer"  == "Download" ]
		then
		/usr/bin/open http://www.visualhub.net
	fi
	if [ "$answer"  == "Stop asking" ]
		then
		/usr/bin/defaults write com.techspansion.visualhub update 0
	fi
fi

fi
