I am implementing a shell script which will create a new self signed certificate using keytool command. Below is the command that I use to create the certificate
echo "# Creating key and Self Signed Certificate"
keytool -genkey -alias cert -keyalg RSA -storepass "${KEYSTORE_PASS}" -keypass "${KEY_PASS}" -keystore cert/keystore.jks -validity 3650 -keysize 1024 -dname "C=${CNTRY}, ST=${ST}, L=${LOC}, O=${ORG}, OU=Certificates, CN=${ORG} SEURAT Certificate Authority"
exit_on_error $?
For password and other subject information I am getting input from user. Now this command fails if alias name already exists. I can delete the alias using
keytool -delete -alias 1 -keystore cert/keystore.jks
But the above command fails if alias name doesnt present. So how can I check in shell script if alias name present then delete the certificate and create new in its name , or just create it ?
Maybe you can list the existing aliases first: