Merge pull request #48 from jtanx/master
[matches/MCTX3420.git] / server-configs / gen_ssl_cert.sh
1 #!/bin/bash
2
3 # Check input params
4 if [ $# -ne 1 ]; then
5         (echo "Usage: $0 common-name") 1>&2
6         exit 1
7 fi
8
9 # Check running as root
10 if [ "$(whoami)" != "root" ]; then
11         (echo "Run $0 as root.") 1>&2
12         exit 1
13 fi
14
15 echo 'Making the conf dir /usr/share/nginx/conf...'
16 mkdir -p /usr/share/nginx/conf
17
18 echo Generating the server private key...
19 openssl genrsa -out /usr/share/nginx/conf/server.key 2048
20
21 echo Generating the CSR...
22 openssl req -new -key /usr/share/nginx/conf/server.key \
23 -out /usr/share/nginx/conf/server.csr \
24  -subj "/C=AU/ST=WA/L=Perth/O=UWA/OU=Mechatronics/CN=$1"
25
26 echo Signing the certificate...
27 openssl x509 -req -days 3650 -in /usr/share/nginx/conf/server.csr \
28 -signkey /usr/share/nginx/conf/server.key \
29 -out /usr/share/nginx/conf/server.crt
30
31

UCC git Repository :: git.ucc.asn.au