Skip to content

Instantly share code, notes, and snippets.

@firegate666
Created November 24, 2017 00:43
Show Gist options
  • Save firegate666/dc4b15b3e2a88ff44f95ecbaf0a04842 to your computer and use it in GitHub Desktop.
Save firegate666/dc4b15b3e2a88ff44f95ecbaf0a04842 to your computer and use it in GitHub Desktop.
Shell helper to create the bundle crt file needed by nginx
#/bin/bash
if [ -z "$1" ]; then
myyear=`date +'%Y'`
echo "Please specifiy domain by calling e.g.: './createBundle.sh mydomain.com $myyear'"
exit -4
fi
if [ -z "$2" ]; then
myyear=`date +'%Y'`
echo "Please specifiy year by calling e.g.: './createBundle.sh mydomain.com $myyear'"
exit -4
fi
BUNDLE_FILE="bundle.$1.$2.crt"
KEY_FILE="$1.$2.key"
CRT_FILE="$1.$2.crt"
INT_FILE="AlphaSSL_Intermediate_CA.2016.pem"
GLO_FILE="GlobalSign_Root_R1_CA.2016.pem"
echo "Creating $BUNDLE_FILE"
echo "Testing if all files exist"
echo ""
if [ -e $BUNDLE_FILE ]; then
echo "$BUNDLE_FILE already exists"
exit -1
fi
if [ ! -f $KEY_FILE ]; then
echo "$KEY_FILE not found"
exit -2
fi
if [ ! -f $CRT_FILE ]; then
echo "$CRT_FILE not found"
exit -3
fi
echo "Cleaning files from linebreaks"
echo ""
# get rid of nasty linebreaks
dos2unix --newline *.crt
dos2unix --newline *.key
dos2unix --newline *.pem
# make sure each file ends with a newline
# otherwise concated bundle file is invalid
echo "" >> $CRT_FILE
echo "" >> $INT_FILE
echo "" >> $GLO_FILE
echo ""
echo "Now execute this to create the bundle file"
echo "cat $CRT_FILE $INT_FILE $GLO_FILE > $BUNDLE_FILE"
echo ""
echo "and alter 'ssl_certificate' and 'ssl_certificate_key' in your nginx config"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment