#!/bin/bash
# Skrypt generowania certyfikatów dla serwera APACHE o nazwie podanym w parametrze par_1
# Autor: Radek Bursztynowski
# 7 sierpnia 2011

if [ $# = 0 ] || [ $1 = '-h' ];
  then echo
       echo "Wywołanie skryptu 'certyfikat_dla_apache': certyfikat_dla_apache par_1 par_2"
       echo "    gdzie:"
       echo "             par_1       to nazwa certyfikatu"
       echo "             par_2       to czas trwania ważności certyfikatu - w dniach"
  else echo
  cd /opt/install
  mkdir /opt/install/certyfikaty
  chmod 770 /opt/install/certyfikaty
  cd /opt/install/certyfikaty
  openssl genrsa -des3 -out $1.key 1024
  openssl req -new -key $1.key -out $1.csr
  cp $1.key $1.key.org
  openssl rsa -in $1.key.org -out $1.key
  openssl x509 -req -days $2 -in $1.csr -signkey $1.key -out $1.crt
  cp $1.key /etc/pki/tls/private
  cp $1.crt /etc/pki/tls/certs
  echo
  echo "W pliku httpd.conf (lub apache.conf) lub ssl.conf (CentOS) (w zależności od dystrybucji) ustawiamy ścieżki dostępu do certyfikatów:"
  echo "    Dla CentOS w pliku /etc/httpd/conf.d/ssl.conf"
  echo "        SSLCertificateKeyFile /etc/pki/tls/private/$1.key"
  echo "        SSLCertificateFile /etc/pki/tls/certs/$1.crt"
  gedit /etc/httpd/conf.d/ssl.conf
fi
