#!/bin/bash
#
# Copyright (C) 2005-2006 Trusted Network Technologies, Inc.  
# All rights reserved.
#
 
CERT=mgrcert.pem
INSTALLDIR=/opt/tnt/var/drivers/branded
 
#
# Cleanup before we start branding...
#
rm -f $INSTALLDIR/install-connectorID-Key-*-winStandard.exe
rm -f $INSTALLDIR/install-connectorID-Key-*-winStandard.msi

#
# Rename and move the installer files
#
STD_IN="/opt/tnt/var/drivers/nps32/install-connectorID-Key-*-winStandard.*"

cp -f $STD_IN $INSTALLDIR/

# copy the cert to the installdir so the mgrcert gets put into root directory of the archive when we add it

# if cached cert doesn't exist yet, cache it from DB
if [ ! -f /opt/tnt/var/backend/activation.crt ]; then
	/opt/tnt/bin/showactcert > /opt/tnt/var/backend/activation.crt
	chown vsservice /opt/tnt/var/backend/activation.crt
fi
cp /opt/tnt/var/backend/activation.crt $INSTALLDIR/$CERT

#
# Brand the EXEs
# Requires p7zip package to be installed

/usr/bin/7za a $INSTALLDIR/install-connectorID-Key-*-winStandard.exe $INSTALLDIR/$CERT
/opt/tnt/bin/signFile $INSTALLDIR/install-connectorID-Key-*-winStandard.exe

#remove temp cert file

rm -f $INSTALLDIR/$CERT

chmod 644 $INSTALLDIR/install-connectorID-Key-*-winStandard.exe $INSTALLDIR/*.msi 
