#!/bin/sh
# +-----------------------------------------------------+
# | HP Insight Manager Agents unattend install Script   |
# |                                                     |
# | Version : 1.0                                       |
# | Author  : Arnim van Lieshout                        |
# +-----------------------------------------------------+

# +-----------------------------------------------------+
# | Setting some variables                              |
# +-----------------------------------------------------+

HPPACKAGE=hpmgmt-8.1.1-vmware3x.tgz
HBAPACKAGE=qlapi_vmw-v4.00build23.tgz
HPVERSION=811
HPCONFIG=hpmgmt${HPVERSION}.conf
HPSMHCONFIG=smhpd${HPVERSION}.xml

# +-----------------------------------------------------+
# | Download files                                      |
# +-----------------------------------------------------+

/usr/sbin/esxcfg-firewall --allowOutgoing

lwp-download http://repository.mydomain.com/hpagents/$HPPACKAGE /tmp/$HPPACKAGE
lwp-download http://repository.mydomain.com/hpagents/$HBAPACKAGE /tmp/$HBAPACKAGE
lwp-download http://repository.mydomain.com/hpagents/$HPCONFIG /tmp/$HPCONFIG
lwp-download http://repository.mydomain.com/hpagents/$HPSMHCONFIG /tmp/$HPSMHCONFIG

/usr/sbin/esxcfg-firewall --blockOutgoing

# +-----------------------------------------------------+
# | Unpack archives                                     |
# +-----------------------------------------------------+

cd /tmp
tar -zxvf $HPPACKAGE
mkdir /tmp/hbaapi
tar -C /tmp/hbaapi -zxvf $HBAPACKAGE
cp /tmp/$HPSMHCONFIG /tmp/hpmgmt/$HPVERSION/smhpd.xml

# +-----------------------------------------------------+
# | Uninstall old packages                              |
# +-----------------------------------------------------+

cd /tmp/hpmgmt/$HPVERSION
echo -e 'y\ny' | ./installvm${HPVERSION}.sh --uninstall
cd /tmp/hbaapi
./Remove.sh

# +-----------------------------------------------------+
# | Install new packages                                |
# +-----------------------------------------------------+

cd /tmp/hbaapi
./Install.sh
cd /tmp/hpmgmt/$HPVERSION
./installvm${HPVERSION}.sh --silent --inputfile /tmp/$HPCONFIG

# +-------------------------------------------------------------+
# | For some apparent reason there is some sort of timing issue |
# | in the installation. restarting hpasm is a workaround       |
# +-------------------------------------------------------------+

service hpasm restart

