#!/bin/sh arg1="" arg2="" arg3="" ksfile="" oldpw="" alias="" menu() { echo Arguments for changeP12password utlity echo ======================================== echo -keystorefile Keystore file echo -keypassword Current key password exit 1 } terminate () { exit 1 } success () { rm -rf tomcat-keystore.pem echo "### Success: $ksfile password changed ###" exit 1 } parseargs2 () { keystorefile="-keystorefile" if [ "$arg1" != $keystorefile ] then echo Wrong argument: $arg1 menu else if [ "$arg2" != "-keypassword" ] then echo Wrong argument: $arg2 menu fi fi } execution () { tmppassword="temp" sslc pkcs12 -in $ksfile -out tomcat-keystore.pem -passin pass:$oldpw -passout pass:$tmppassword if [ "$?" != "0" ] then echo MAC verify error: invalid password? rm -rf tomcat-keystore.pem terminate fi rm -rf tomcat-keystore_bk.p12 echo "##### Take backup of original tomcat-keystore.p12 as tomcat-keystore_bk.p12 #####" mv $ksfile tomcat-keystore_bk.p12 sslc pkcs12 -export -in tomcat-keystore.pem -out $ksfile -passin pass:$tmppassword -name $alias if [ "$?" != "0" ] then echo Error changing keystore password !!! rm -rf tomcat-keystore.pem rm -rf $ksfile mv tomcat-keystore_bk.p12 $ksfile fi rm -rf tomcat-keystore.pem } if [ "$#" -eq "4" ] then arg1=$1 arg2=$3 parseargs2 ksfile=$2 oldpw=$4 alias="test2" else menu fi execution terminate