#!/bin/sh

NOW=`date +%Y%m%dT%H%M`

SVCADM=/usr/sbin/svcadm
SVCCFG=/usr/sbin/svccfg
GREP=/usr/bin/grep
USERDEL=/usr/sbin/userdel
GROUPDEL=/usr/sbin/groupdel
iciFmri="svc:/application/network/icinga:default"
idoFmri="svc:/application/network/icinga-db:default"

icihome=`grep '^icinga:' /etc/passwd | cut -d: -f6`

if [ ! -z "$icihome" ]
then
  tarball=/tmp/preremove-icinga-config-${NOW}.tar
  echo "WARNING: No Icinga home directory.  Saving configuration to \"$tarball\"."
else
  tarball=${icihome}/preremove-icinga-config-${NOW}.tar
  echo "Saving Icinga configuration to \"$tarball\"."
fi

a=`pwd`
cd /etc
tar -cf ${tarball} icinga
cd $a

${SCVADM} disable -f ${fmri}
${SVCCFG} delete -f ${fmri}

${SVCADM} disable -f ${idoFmri}
${SVCCFG} delete -f ${idoFmri}

exit 0
