#!/bin/sh

# Fetch URL for latest suspend2 patch
PATCHES=$(curl -q "http://www.suspend2.net/" 2>/dev/null | egrep -o "/downloads/all/.+?\.bz2")

# Check if the patch already exists
# If so, cancel
for patch in $PATCHES
do
	[ -e $(basename $patch .bz2) ] && exit 0
done

# Remove old patches
rm -f suspend2-*.patch 2>/dev/null

# Ask the user which patch to download
echo " A new version of the suspend2 patch has been found. Please select the download which "
echo " suits best for you:"
echo
select patch in $PATCHES; do break; done
echo

# Download the patch
echo " Downloading patch"
PATCH="http://www.suspend2.net/$patch"
FILE=$(basename $PATCH .bz2)
curl -q $PATCH 2>/dev/null | bzip2 -d > $FILE || exit 1
echo " Finished"

# Finished
exit 0
