Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Takes a zip file from sslforfree.com and puts it into name.crt and name.key automatically
#!/bin/bash
readyn() {
read -n1 yn
}
loopyn() {
readyn
while [[ "$yn" != "y" && "$yn" != "n" ]]
do
readyn
done
}
if [ $# -ne 2 ]
then
echo "Usage: $0 file.zip name"
exit -1
fi
ZIPFILE=$1
NAME=$2
BASE_PATH="/etc/pki/tls"
CERT_PATH="$BASE_PATH/certs/$NAME.crt"
KEY_PATH="$BASE_PATH/private/$NAME.key"
if [ -f $CERT_PATH ] || [ -f $KEY_PATH ]
then
echo -n "Cert / Key exist. Continue? (y/n) "
loopyn
if [ "$yn" = "n" ]
then
echo -e "\n"
exit 0
fi
fi
TMP_NAME=`uuidgen`
TMP_DIR="/tmp/$TMP_NAME"
echo -e "\nCreating tmp dir $TMP_DIR"
mkdir $TMP_DIR
echo "Unzipping $ZIPFILE to $TMP_DIR"
unzip -qq $ZIPFILE -d $TMP_DIR
echo "Moving files"
mv "$TMP_DIR/certificate.crt" $CERT_PATH
mv "$TMP_DIR/private.key" $KEY_PATH
echo "Cleaning up $TMP_DIR"
rm -rf $TMP_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment