#!/bin/bash
set -x

##  PKI Silent Admin Variables
##  (e. g. - Import Admin Certificate into PKI Silent "browser" database)
pki_silent_admin_user=admin
pki_silent_admin_password=testpasswd
pki_silent_admin_email=pki-ocsp-admin@test.com


##  PKI Subsystem Host (computed by default)
pki_host=`hostname`

# PKI Subsystem Instance Names
ocsp_instance_name=pki-ocsp

#  PKI Silent Security Database Variables
pki_silent_security_database_repository=/tmp/testdb
pki_silent_security_database_password=testpasswd


# PKI Subsystem Instance PINS
ocsp_preop_pin=`cat /var/lib/${ocsp_instance_name}/conf/CS.cfg \
        | grep preop.pin | grep -v grep | awk -F= '{print $2}'`


##  PKI Security Domain Variables
##  (e. g. - Security Domain Login Panel)
pki_security_domain_name=silentdom
pki_security_domain_host=`hostname`
pki_security_domain_admin_name=admin
pki_security_domain_admin_password=testpasswd

##  PKI Internal LDAP Database Variables
pki_ldap_host=localhost
pki_ldap_port=389
pki_bind_dn="cn=Directory\ Manager"
pki_bind_password=Secret123


##  PKI Instance-Specific Token Variables
ocsp_token_name=internal
ocsp_token_password=testpasswd


## CA ports
ca_nonssl_port=9180
ca_agent_port=9443
ca_ee_port=9444
ca_admin_port=9445

## OCSP ports
ocsp_nonssl_port=11180
ocsp_agent_port=11443
ocsp_ee_port=11444
ocsp_admin_port=11445

##  PKI Subsystem Name
ocsp_subsystem_name="OCSP\ Responder"
pki_silent_ocsp_log=/tmp/pki-silent-ocsp.log


##  Miscellaneous OCSP Variables
ocsp_agent_name="OCSP\ Administrator\ of\ Instance\ ${ocsp_instance_name}\'s\ ${pki_security_domain_name}\ ID"
ocsp_agent_key_size=2048
ocsp_agent_key_type=rsa
ocsp_agent_cert_subject="cn=OCSP\ Administrator\ of\ Instance\ ${ocsp_instance_name},uid=admin,e=${pki_silent_admin_email},o=${pki_security_domain_name}"
ocsp_base_dn="dc=${pki_host}-${ocsp_instance_name}"
ocsp_db_name="${pki_host}-${ocsp_instance_name}"
ocsp_key_size=2048
ocsp_key_type=rsa
ocsp_backup_password=testpasswd


ocsp_sign_cert_subject_name="cn=OCSP\ Signing\ Certificate,o=${pki_security_domain_name}"
ocsp_subsystem_cert_subject_name="cn=OCSP\ Subsystem\ Certificate,o=${pki_security_domain_name}"
ocsp_server_cert_subject_name="cn=${pki_host},o=${pki_security_domain_name}"
ocsp_audit_signing_cert_subject_name="cn=OCSP\ Audit\ Signing\ Certificate,o=${pki_security_domain_name}"
########################################################################################################

##  Configure OCSP
	printf "'${pki_silent_script}':  Configuring '${ocsp_instance_name}' . . .\n"
	pkisilent ConfigureOCSP \
		-cs_hostname "${pki_host}" \
		-cs_port ${ocsp_admin_port} \
		-sd_hostname "${pki_security_domain_host}" \
		-sd_ssl_port ${ca_ee_port} \
		-sd_agent_port ${ca_agent_port} \
		-sd_admin_port ${ca_admin_port} \
		-sd_admin_name "${pki_security_domain_admin_name}" \
		-sd_admin_password ${pki_security_domain_admin_password} \
		-ca_hostname ${pki_security_domain_host} \
		-ca_port ${ca_nonssl_port} \
		-ca_ssl_port ${ca_ee_port} \
		-client_certdb_dir ${pki_silent_security_database_repository} \
		-client_certdb_pwd ${pki_silent_security_database_password} \
		-preop_pin ${ocsp_preop_pin} \
		-domain_name "${pki_security_domain_name}" \
		-admin_user ${pki_silent_admin_user} \
		-admin_password ${pki_silent_admin_password} \
		-admin_email "${pki_silent_admin_email}" \
		-agent_name ${ocsp_agent_name} \
		-ldap_host ${pki_ldap_host} \
		-ldap_port ${pki_ldap_port} \
		-bind_dn "${pki_bind_dn}" \
		-bind_password ${pki_bind_password} \
		-base_dn "${ocsp_base_dn}" \
		-db_name "${ocsp_db_name}" \
		-key_size ${ocsp_key_size} \
		-key_type ${ocsp_key_type} \
		-token_name ${ocsp_token_name} \
		-token_pwd ${ocsp_token_password} \
        -agent_key_size ${ocsp_agent_key_size} \
        -agent_key_type ${ocsp_agent_key_type} \
        -agent_cert_subject "${ocsp_agent_cert_subject}" \
        -subsystem_name ${ocsp_subsystem_name} \
        -backup_pwd ${ocsp_backup_password} \
        -ocsp_sign_cert_subject_name "${ocsp_sign_cert_subject_name}" \
        -ocsp_subsystem_cert_subject_name "${ocsp_subsystem_cert_subject_name}" \
        -ocsp_server_cert_subject_name "${ocsp_server_cert_subject_name}" \
        -ocsp_audit_signing_cert_subject_name \
        "${ocsp_audit_signing_cert_subject_name}" \
        | tee ${pki_silent_ocsp_log}
