#!/bin/sh

############
# CHANGELOG
#===========
# 2010/12/23    crms00282384   Creation  Claire Dechriste
#
# 2011/02/28    crms00295884   Claire Dechriste
#
# 2011/02/28    crms00302064   Claire Dechriste
#               use dmconfig clean, do not clean external ts
################

CTL_FILE=`getICTinfo -d PKI CTL`
#CTL_PATH=`getICTinfo PATH TS_CTL`

Usage()
{
    echo "ctl [erase]"
}

ctl_info()
{
    if [ -f $CTL_FILE ]; then
        #crms00295884
        cat $CTL_FILE
    else
        echo "no CTL file"
    fi
}

ctl_erase()
{
    if [ -f $CTL_FILE ]; then
        rm -f $CTL_FILE
        #rebuild main CA
        rm -f /etc/trust_store/ca.pem
        /usr/sbin/cert/buildCA
        #force the reload of the config file at next reboot
        #crms00302064
        /etc/init.d/dmconfig clean
        echo "CTL removed"
    else
        echo "no CTL file"
    fi

    #crms00302064 +
    #remove web app trusted certificates and users certificates
    #rm -rf /etc/external_trust_store/*
    #rm -rf /etc/external_key_store/*
    #echo "external stores cleaned"
    #crms00302064 -

    echo "Don't forget to reboot the terminal"
}
                          
exit_ko()
{
	echo "CTL KO"
	exit 1
}


exit_ok()
{
	echo "CTL OK"
	exit 0
}

[ $# -ne 0 ] || {  ctl_info ; exit_ok;}

if [ $1 == "erase" ]; then
   ctl_erase
   exit_ok
else
   echo "Unknown command"
   Usage
   exit_ko
fi


