#!/bin/sh

version=260117
SCRIPT=$(readlink -f $0)
SCRIPTNAME=$(basename $SCRIPT)
SCRIPTDIR=$(dirname $SCRIPT)
BASEDIR=$(dirname $SCRIPTDIR)

pkg="tpl-w11-0.vmdk"
url="https://fs.aadme.de/tpl-w11/$pkg"
#https://svzone.de/files/srv/scripts/esxi-packages/bcmlwa/vmware-lwmd_008.015.010.000-01.zip
params="--no-check-certificate"

#The upgrade process is similar to a new install as the same command upgrades
#the component to a newer, if the prior version is already installed on ESXi server.
#esxcli software component apply -d {Component_File}

hash esxcli &>/dev/null
if [ $? != 0 ] ; then echo "this is not an esxi system"; exit 1; fi

echo -n "checking if image $pkg exists: "
if [ -e "$SCRIPTDIR/$pkg" ] ; then
        echo "yes";
	echo -n "checking if esxi converted version exists: "
	if [ -e "$SCRIPTDIR/esxi-tpl.vmdk" ] ; then
		echo "yes"
	else
		echo "converting..."
		vmkfstools -i "$SCRIPTDIR/$pkg" "$SCRIPTDIR/esxi-tpl.vmdk"
	fi
else
        echo "no";
	if [ ! -e "$SCRIPTDIR/$pkg" ] ; then
		echo "no template package found, trying to get it: $url"
                wget "$url" $params
	fi
fi

exit
