#!/bin/bash
# BEGIN COPYRIGHT BLOCK
 # This Program is free software; you can redistribute it and/or modify it under
 # the terms of the GNU General Public License as published by the Free Software
 # Foundation; version 2 of the License.
 #
 # This Program is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License along with
 # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
 # Place, Suite 330, Boston, MA 02111-1307 USA.
 #
 # Copyright (C) 2005 Red Hat, Inc.
 # All rights reserved.
 # END COPYRIGHT BLOCK **/

echo "Hello from postflight."

if [ ! -a /usr/libexec/SmartCardServices/drivers/slbEGate.bundle ]
then
    rm -rf /usr/libexec/SmartCardServices/drivers/slbEGate.bundle ]
fi

if [ ! -a /Library/"Application Support"/CoolKey/PKCS11 ]
then
    mkdir -v -p /Library/"Application Support"/CoolKey/PKCS11 
fi

if [ -f "/Library/Application Support/CoolKey/PKCS11/libcoolkeypk11.dylib" ]
then
    rm -rf  "/Library/Application Support/CoolKey/PKCS11/libcoolkeypk11.dylib"
fi

ln  -f -s "/usr/local/CoolKey/lib/pkcs11/libcoolkeypk11.dylib" "/Library/Application Support/CoolKey/PKCS11/libcoolkeypk11.dylib"

rm -rf ~/Library/"Application Support"/ESC

rm -rf /Applications/Utilities/PK11Install/pk11install

ln -f -s "/usr/local/CoolKey/bin/pk11install" "/Applications/Utilities/PK11Install/pk11install"

/Applications/Utilities/PK11Install/pk11install -v "name='CoolKey Module' library='/Library/Application Support/CoolKey/PKCS11/libcoolkeypk11.dylib' NSS="slotParams={0x1=[slotFlags=PublicCerts]}""

