#!/bin/bash # $Id$ # TODO: Add variable cert life SSLDIR="/etc/apache2/ssl" SSLBIN="/usr/bin/openssl" DOMAIN=$1 cd $SSLDIR if [[ -e "$DOMAIN.key" ]]; then { echo -en "Key file already exists, skipping\n(remove $SSLDIR/$DOMAIN.key if you want to start from scratch)\n"; }; else { echo -en "Generating key file...\n"; $SSLBIN genrsa -out "$DOMAIN.key" 1024; }; fi; if [[ -e "$DOMAIN.csr" ]]; then { echo -en "Signing request already exists, skipping\n(remove $SSLDIR/$DOMAIN.csr if you want to make a new one)\n"; }; else { echo -en "Creating Certificate Signing Request...\n"; $SSLBIN req -new -key "$DOMAIN.key" -out "$DOMAIN.csr"; }; fi; echo -en "Creating certificate...\n" $SSLBIN x509 -in "$DOMAIN.csr" -out "$DOMAIN.crt" -req -signkey "$DOMAIN.key" -days 365 echo -en "Done!\nUse the following lines in the vhost declaration:\n\n" echo -en "SSLCertificateFile $SSLDIR/$DOMAIN.crt\nSSLCertificateKeyFile $SSLDIR/$DOMAIN.key\n"