Redirect stderr in batch mode.
[shibboleth/sp.git] / configs / keygen.sh
1 #! /bin/sh
2
3 while getopts h:y:b c
4      do
5          case $c in
6            b)         BATCH=1;;
7            h)         FQDN=$OPTARG;;
8            y)         DAYS=$OPTARG;;
9            \?)        echo keygen [-h hostname/cn for cert] [-y years to issue cert]
10                       exit 1;;
11          esac
12      done
13
14 if  [ -e sp-key.pem ] || [ -e sp-cert.pem ] ; then
15     if [ -z $BATCH ] ; then  
16         echo The files sp-key.pem and/or sp-cert.pem already exist!
17         exit 2
18     fi
19     exit 0
20 fi
21
22 if [ -z $FQDN ] ; then
23     FQDN=`hostname`
24 fi
25
26 if [ -z $DAYS ] ; then
27     DAYS=10
28 fi
29
30 DAYS=$(($DAYS*365))
31
32 if [ -z $BATCH ] ; then
33     openssl req -x509 -days $DAYS -newkey rsa:2048 -nodes -keyout sp-key.pem -out sp-cert.pem -subj /CN=$FQDN -extensions usr_cert -set_serial 0
34 else
35     openssl req -x509 -days $DAYS -newkey rsa:2048 -nodes -keyout sp-key.pem -out sp-cert.pem -subj /CN=$FQDN -extensions usr_cert -set_serial 0 2> /dev/null
36 fi