Automatic commit of irc logs
[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 # Check for nginx dir
16 nginx=/usr/share/nginx
17 if [ ! -d "$nginx" ]; then
18         (echo "nginx folder not found at $nginx.") 1>&2
19         exit 1
20 fi;
21
22 echo 'Making the conf dir $nginx/conf...'
23 mkdir -p $nginx/conf
24
25 echo Generating the server private key...
26 openssl genrsa -out $nginx/conf/server.key 2048
27
28 echo Generating the CSR...
29 openssl req -new -key $nginx/conf/server.key -out $nginx/conf/server.csr \
30  -subj "/C=AU/ST=WA/L=Perth/O=UWA/OU=Mechatronics/CN=$1"
31
32 echo Signing the certificate...
33 openssl x509 -req -days 3650 -in $nginx/conf/server.csr \
34  -signkey $nginx/conf/server.key -out $nginx/conf/server.crt
35
36

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