#!/bin/sh

PATCHDIR="/PATH/TO/YOUR/DEPOT"
pwd=`pwd`

# Create temp dir
tmp=`mktemp -d`
cd $tmp

# get contents.zip
wget http://download3.vmware.com/software/esx/ESX-3.5.0-contents.zip
unzip ESX-3.5.0-contents.zip

# copy contents.xml to $PATCHDIR
cp contents.xml contents.xml.sig $PATCHDIR

cd $PATCHDIR

for f in $(grep folder contents.xml | awk -F\" '{print($2)}'); do
    # Check in PATCHDIR if patch exists
    ls $PATCHDIR | grep $f
    if [ $? != 0 ]; then
	# if not, try first download location
        wget -P $PATCHDIR "http://download3.vmware.com/software/vi/${f}.zip"
        if [ $? != 0 ]; then
	    # if first location fails, try second
            wget -P $PATCHDIR "http://download3.vmware.com/software/esx/${f}.zip"
	fi
	# unzip package
	unzip ${f}.zip
    fi
done

cd $pwd
rm -rf $tmp
