| 
				
			 | 
			
			
				@@ -46,6 +46,7 @@ done 
			 | 
		
	
		
			
			| 
				46
			 | 
			
				46
			 | 
			
			
				 PIN_CERTS= 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				47
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				48
			 | 
			
				48
			 | 
			
			
				 HOSTNAME= 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+remove_cert= 
			 | 
		
	
		
			
			| 
				49
			 | 
			
				50
			 | 
			
			
				 LETSENCRYPT_HOSTNAME= 
			 | 
		
	
		
			
			| 
				50
			 | 
			
				51
			 | 
			
			
				 COUNTRY_CODE="US" 
			 | 
		
	
		
			
			| 
				51
			 | 
			
				52
			 | 
			
			
				 AREA="Free Speech Zone" 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -70,19 +71,20 @@ function show_help { 
			 | 
		
	
		
			
			| 
				70
			 | 
			
				71
			 | 
			
			
				     echo '' 
			 | 
		
	
		
			
			| 
				71
			 | 
			
				72
			 | 
			
			
				     echo $'Creates a self-signed certificate for the given hostname' 
			 | 
		
	
		
			
			| 
				72
			 | 
			
				73
			 | 
			
			
				     echo '' 
			 | 
		
	
		
			
			| 
				73
			 | 
			
				
			 | 
			
			
				-    echo $'     --help                   Show help' 
			 | 
		
	
		
			
			| 
				74
			 | 
			
				
			 | 
			
			
				-    echo $'  -h --hostname [name]        Hostname' 
			 | 
		
	
		
			
			| 
				75
			 | 
			
				
			 | 
			
			
				-    echo $'  -e --letsencrypt [hostname] Hostname to use with Lets Encrypt' 
			 | 
		
	
		
			
			| 
				76
			 | 
			
				
			 | 
			
			
				-    echo $'  -s --server [url]           Lets Encrypt server URL' 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				
			 | 
			
			
				-    echo $'  -c --country [code]         Optional country code (eg. US, GB, etc)' 
			 | 
		
	
		
			
			| 
				78
			 | 
			
				
			 | 
			
			
				-    echo $'  -a --area [description]     Optional area description' 
			 | 
		
	
		
			
			| 
				79
			 | 
			
				
			 | 
			
			
				-    echo $'  -l --location [locn]        Optional location name' 
			 | 
		
	
		
			
			| 
				80
			 | 
			
				
			 | 
			
			
				-    echo $'  -o --organisation [name]    Optional organisation name' 
			 | 
		
	
		
			
			| 
				81
			 | 
			
				
			 | 
			
			
				-    echo $'  -u --unit [name]            Optional unit name' 
			 | 
		
	
		
			
			| 
				82
			 | 
			
				
			 | 
			
			
				-    echo $'     --email [address]        Email address for letsencrypt' 
			 | 
		
	
		
			
			| 
				83
			 | 
			
				
			 | 
			
			
				-    echo $'     --dhkey [bits]           DH key length in bits' 
			 | 
		
	
		
			
			| 
				84
			 | 
			
				
			 | 
			
			
				-    echo $'     --nodh ""                Do not calculate DH params' 
			 | 
		
	
		
			
			| 
				85
			 | 
			
				
			 | 
			
			
				-    echo $'     --ca ""                  Certificate authority cert' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+    echo $'     --help                     Show help' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+    echo $'  -h --hostname [name]          Hostname' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+    echo $'  -e --letsencrypt [hostname]   Hostname to use with Lets Encrypt' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+    echo $'  -r --rmletsencrypt [hostname] Remove a Lets Encrypt certificate' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+    echo $'  -s --server [url]             Lets Encrypt server URL' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+    echo $'  -c --country [code]           Optional country code (eg. US, GB, etc)' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+    echo $'  -a --area [description]       Optional area description' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+    echo $'  -l --location [locn]          Optional location name' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+    echo $'  -o --organisation [name]      Optional organisation name' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				+    echo $'  -u --unit [name]              Optional unit name' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				84
			 | 
			
			
				+    echo $'     --email [address]          Email address for letsencrypt' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				85
			 | 
			
			
				+    echo $'     --dhkey [bits]             DH key length in bits' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				86
			 | 
			
			
				+    echo $'     --nodh ""                  Do not calculate DH params' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				87
			 | 
			
			
				+    echo $'     --ca ""                    Certificate authority cert' 
			 | 
		
	
		
			
			| 
				86
			 | 
			
				88
			 | 
			
			
				     echo '' 
			 | 
		
	
		
			
			| 
				87
			 | 
			
				89
			 | 
			
			
				     exit 0 
			 | 
		
	
		
			
			| 
				88
			 | 
			
				90
			 | 
			
			
				 } 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -103,6 +105,11 @@ do 
			 | 
		
	
		
			
			| 
				103
			 | 
			
				105
			 | 
			
			
				             shift 
			 | 
		
	
		
			
			| 
				104
			 | 
			
				106
			 | 
			
			
				             LETSENCRYPT_HOSTNAME="$1" 
			 | 
		
	
		
			
			| 
				105
			 | 
			
				107
			 | 
			
			
				             ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				108
			 | 
			
			
				+        -r|--rmletsencrypt) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				109
			 | 
			
			
				+            shift 
			 | 
		
	
		
			
			| 
				
			 | 
			
				110
			 | 
			
			
				+            LETSENCRYPT_HOSTNAME="$1" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				111
			 | 
			
			
				+            remove_cert=1 
			 | 
		
	
		
			
			| 
				
			 | 
			
				112
			 | 
			
			
				+            ;; 
			 | 
		
	
		
			
			| 
				106
			 | 
			
				113
			 | 
			
			
				         --email) 
			 | 
		
	
		
			
			| 
				107
			 | 
			
				114
			 | 
			
			
				             shift 
			 | 
		
	
		
			
			| 
				108
			 | 
			
				115
			 | 
			
			
				             MY_EMAIL_ADDRESS="$1" 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -173,6 +180,25 @@ fi 
			 | 
		
	
		
			
			| 
				173
			 | 
			
				180
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				174
			 | 
			
				181
			 | 
			
			
				 CERTFILE=$HOSTNAME 
			 | 
		
	
		
			
			| 
				175
			 | 
			
				182
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				183
			 | 
			
			
				+function remove_cert_letsencrypt { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				184
			 | 
			
			
				+    CERTFILE=$LETSENCRYPT_HOSTNAME 
			 | 
		
	
		
			
			| 
				
			 | 
			
				185
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				186
			 | 
			
			
				+    # disable the site if needed 
			 | 
		
	
		
			
			| 
				
			 | 
			
				187
			 | 
			
			
				+    if [ -f /etc/nginx/sites-available/${LETSENCRYPT_HOSTNAME} ]; then 
			 | 
		
	
		
			
			| 
				
			 | 
			
				188
			 | 
			
			
				+        if grep -q "443" /etc/nginx/sites-available/${LETSENCRYPT_HOSTNAME}; then 
			 | 
		
	
		
			
			| 
				
			 | 
			
				189
			 | 
			
			
				+            nginx_dissite ${LETSENCRYPT_HOSTNAME} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				190
			 | 
			
			
				+        fi 
			 | 
		
	
		
			
			| 
				
			 | 
			
				191
			 | 
			
			
				+    fi 
			 | 
		
	
		
			
			| 
				
			 | 
			
				192
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				193
			 | 
			
			
				+    # remove the cert 
			 | 
		
	
		
			
			| 
				
			 | 
			
				194
			 | 
			
			
				+    rm -rf /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}* 
			 | 
		
	
		
			
			| 
				
			 | 
			
				195
			 | 
			
			
				+    rm -rf /etc/letsencrypt/archive/${LETSENCRYPT_HOSTNAME}* 
			 | 
		
	
		
			
			| 
				
			 | 
			
				196
			 | 
			
			
				+    rm /etc/letsencrypt/renewal/${LETSENCRYPT_HOSTNAME}.conf 
			 | 
		
	
		
			
			| 
				
			 | 
			
				197
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				198
			 | 
			
			
				+    # restart the web server 
			 | 
		
	
		
			
			| 
				
			 | 
			
				199
			 | 
			
			
				+    systemctl restart nginx 
			 | 
		
	
		
			
			| 
				
			 | 
			
				200
			 | 
			
			
				+} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				201
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				176
			 | 
			
				202
			 | 
			
			
				 function add_cert_letsencrypt { 
			 | 
		
	
		
			
			| 
				177
			 | 
			
				203
			 | 
			
			
				     CERTFILE=$LETSENCRYPT_HOSTNAME 
			 | 
		
	
		
			
			| 
				178
			 | 
			
				204
			 | 
			
			
				  
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -307,6 +333,11 @@ function make_cert_bundle { 
			 | 
		
	
		
			
			| 
				307
			 | 
			
				333
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				308
			 | 
			
				334
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				309
			 | 
			
				335
			 | 
			
			
				 function create_cert { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				336
			 | 
			
			
				+    if [ $remove_cert ]; then 
			 | 
		
	
		
			
			| 
				
			 | 
			
				337
			 | 
			
			
				+        remove_cert_letsencrypt 
			 | 
		
	
		
			
			| 
				
			 | 
			
				338
			 | 
			
			
				+        return 
			 | 
		
	
		
			
			| 
				
			 | 
			
				339
			 | 
			
			
				+    fi 
			 | 
		
	
		
			
			| 
				
			 | 
			
				340
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				310
			 | 
			
				341
			 | 
			
			
				     if [ $LETSENCRYPT_HOSTNAME ]; then 
			 | 
		
	
		
			
			| 
				311
			 | 
			
				342
			 | 
			
			
				         add_cert_letsencrypt 
			 | 
		
	
		
			
			| 
				312
			 | 
			
				343
			 | 
			
			
				     else 
			 |