#!/bin/sh # # CopyLeft moon.cat # This work is licensed under a Creative Commons Attribution 4.0 International License. # # Author: Rei Izumi - moon.cat - blog.moon.cat - 2017 # # EASYRSA_PKI="/etc/easy-rsa/pki" CERTIFICATE_PREFIX="prefix_" OUTPUT_FOLDER="/root" if [ ! $1 ] then echo "Error: You must provide the Common Name" exit fi if [ -f $EASYRSA_PKI/issued/$1.crt ] then echo "Error: certificate with Common Name: $1 already exists" exit fi echo "Creating certificate for $1 ..." easyrsa build-client-full $1 echo "Creating zip with certificates ..." mkdir $OUTPUT_FOLDER/$1 cp $EASYRSA_PKI/issued/$1.crt $OUTPUT_FOLDER/$1/$CERTIFICATE_PREFIX$1.crt cp $EASYRSA_PKI/private/$1.key $OUTPUT_FOLDER/$1/$CERTIFICATE_PREFIX$1.key cp $EASYRSA_PKI/ca.crt $OUTPUT_FOLDER/$1/$CERTIFICATE_PREFIX'ca.crt' zip -j $OUTPUT_FOLDER/$1.zip $OUTPUT_FOLDER/$1/$CERTIFICATE_PREFIX$1.crt $OUTPUT_FOLDER/$1/$CERTIFICATE_PREFIX$1.key $OUTPUT_FOLDER/$1/$CERTIFICATE_PREFIX'ca.crt' rm -rf $OUTPUT_FOLDER/$1 echo "Finished"