Convert LetsEncrypt pem file to pfx
#!/bin/sh
pemsdir='/etc/letsencrypt/archive' # default search PEMs
pfxspath='/share/letsencrypt/archive' # dest of the PFXs
passfile='/share/letsencrypt/pass.txt' # password to be applied to the PFX file
for cnvifull in `find "${pemsdir}" -name 'cert*.pem' -o -name '*chain*.pem'`
do
cnvifile=${cnvifull##*/}
cnvinum=`echo ${cnvifile%.*} | sed -e "s#[cert|chain|fullchain]##g"`
cnvipkey="${cnvifull%/*}/privkey${cnvinum}.pem"
cnvopem=`echo ${cnvifull} | sed -e "s#${pemsdir}#${pfxspath}#g"`
cnvofull="${cnvopem%.*}.pfx"
echo "- :-) ->"
echo "-in ${cnvifull}"
echo "-inkey ${cnvipkey}"
echo "-out ${cnvofull}"
mkdir -p ${cnvofull%/*}
openssl pkcs12 \
-export \
-in ${cnvifull} \
-inkey ${cnvipkey} \
-out ${cnvofull} \
-passout file:${passfile}
done