shell script to import certificate in cacerts of JDK
#!/bin/bash
# Set the path to the cacerts file
CACERTS_FILE="${JAVA_HOME}/jre/lib/security/cacerts"
# Prompt for the path to the certificate file
printf "Enter path to certificate file: "
read CERT_PATH
# Prompt for the alias for the certificate in the keystore
printf "Enter alias for certificate: "
read CERT_ALIAS
# Prompt for the keystore password
printf "Enter keystore password: "
read -s PASSWORD
echo
# Import the certificate into the cacerts file
keytool -importcert -alias "${CERT_ALIAS}" -file "${CERT_PATH}" -keystore "${CACERTS_FILE}" -storepass "${PASSWORD}"
# Verify the certificate was imported successfully
keytool -list -v -keystore "${CACERTS_FILE}" -storepass "${PASSWORD}" | grep "${CERT_ALIAS}"
In this version of the script, we prompt the user to enter the path to the certificate file, the alias for the certificate in the keystore, and the keystore password using the printf and read commands. The user's input is stored in the CERT_PATH, CERT_ALIAS, and PASSWORD variables, respectively.
The rest of the script is the same as before, using the keytool command to import the certificate into the cacerts file and verify that it was imported successfully.
Comments
Post a Comment