Преглед изворни кода

hooks; generate-ssl-cert

tags/v2.0.0
Robin Thoni пре 9 година
родитељ
комит
08c2974a5f

+ 1
- 0
.gitignore Прегледај датотеку

@@ -0,0 +1 @@
1
+*.swp

+ 21
- 0
generate-ssl-cert.sh Прегледај датотеку

@@ -0,0 +1,21 @@
1
+#! /usr/bin/env bash
2
+
3
+if [ $# -eq 0 ]
4
+then
5
+  echo "Usage: generate-ssl-cert hostname [options]" >&2
6
+  exit 64
7
+fi
8
+
9
+host="$1"
10
+
11
+letsencrypt --agree-tos --renew-by-default --standalone --standalone-supported-challenges http-01 --http-01-port 9999 --server https://acme-v01.api.letsencrypt.org/directory certonly -d $*
12
+
13
+if [ $? -ne 0 ]
14
+then
15
+  echo "Failed to generate certificate" >&2
16
+  exit 1
17
+fi
18
+
19
+ln -sf /etc/letsencrypt/live/${host}/cert.pem /etc/ssl/private/${host}.crt
20
+ln -sf /etc/letsencrypt/live/${host}/privkey.pem /etc/ssl/private/${host}.key
21
+ln -sf /etc/letsencrypt/live/${host}/chain.pem /etc/ssl/private/${host}-chain.crt

+ 2
- 0
install Прегледај датотеку

@@ -1,6 +1,8 @@
1 1
 #! /usr/bin/env sh
2 2
 
3 3
 mkdir -p /etc/sitegen
4
+mkdir -p ~/.sitegen/hooks.d
4 5
 install sitegen/* /etc/sitegen/
5 6
 install sitegen.sh /usr/local/bin/sitegen
7
+install generate-ssl-cert.sh /usr/local/bin/generate-ssl-cert
6 8
 install sitegen.completion /etc/bash_completion.d/sitegen

+ 21
- 14
sitegen.sh Прегледај датотеку

@@ -4,17 +4,8 @@ apache_dir=/etc/apache2/sites-available/
4 4
 conf_dir=/etc/sitegen/
5 5
 site_dir=/var/
6 6
 
7
-conf_file=/etc/sitegen/sitegen.conf
8
-conf_file_local=~/.sitegen.conf
9
-
10
-loadConf()
11
-{
12
-  if [ -e "$1" ]
13
-  then
14
-    echo "Found a config file: $1"
15
-    . "$1"
16
-  fi
17
-}
7
+hooks_dir=/etc/sitegen/hooks.d/
8
+hooks_dir_local=~/.sitegen/hooks.d/
18 9
 
19 10
 makeDir()
20 11
 {
@@ -30,15 +21,28 @@ getPath()
30 21
   readlink -m "$1"
31 22
 }
32 23
 
24
+applyHooks()
25
+{
26
+  dir="$1"
27
+  if [ -d ${dir} ]
28
+  then
29
+    for file in $(find ${dir} | sort) ;
30
+    do
31
+      echo "Applying ${file}"
32
+      . "${file}"
33
+    done
34
+  else
35
+    echo "No hooks found in ${dir}"
36
+  fi
37
+}
38
+
39
+
33 40
 if [ $# -eq 0 ] || [ $# -gt 2 ] || [ "$1" = "--help" ]
34 41
 then
35 42
   echo "Usage:" $(basename $0) "hostname [config=default]" >&2
36 43
   exit 1
37 44
 fi
38 45
 
39
-loadConf "${conf_file}"
40
-loadConf "${conf_file_local}"
41
-
42 46
 host="$1"
43 47
 if [ $# -eq 2 ]
44 48
 then
@@ -75,3 +79,6 @@ makeDir "${apache_dir}"
75 79
 
76 80
 sed -e "${sed_host}" -e "${sed_root}" "${conf_conf}" > "${site_conf}"
77 81
 sed -e "${sed_host}" -e "${sed_root}" "${conf_include}" > "${site_include}"
82
+
83
+applyHooks ${hooks_dir}
84
+applyHooks ${hooks_dir_local}

+ 6
- 0
sitegen/hooks.available/000-print Прегледај датотеку

@@ -0,0 +1,6 @@
1
+echo "Host: ${host}"
2
+echo "Root Document: ${root_dir}"
3
+echo "Http Configuration Source: ${conf_conf}"
4
+echo "Site Configuration Source: ${conf_include}"
5
+echo "Http Configuration Destination: ${site_conf}"
6
+echo "Site Configuration Destination: ${site_include}"

+ 8
- 0
sitegen/hooks.available/050-letsencrypt Прегледај датотеку

@@ -0,0 +1,8 @@
1
+count=$(grep -ci SSLCertificateFile ${site_conf})
2
+if [ "${count}" -ge 1 ]
3
+then
4
+  echo "SSL found; generating certificate..."
5
+  generate-ssl-cert "${host}"
6
+else
7
+  echo "No SSL found; doing nothing"
8
+fi

+ 3
- 0
sitegen/hooks.available/100-chown Прегледај датотеку

@@ -0,0 +1,3 @@
1
+user=$(logname)
2
+echo "chown to ${user}"
3
+chown ${user}:${user} ${root_dir}

+ 1
- 0
sitegen/hooks.available/200-a2ensite Прегледај датотеку

@@ -0,0 +1 @@
1
+a2ensite "${host}.conf"

+ 1
- 0
sitegen/hooks.available/300-reload Прегледај датотеку

@@ -0,0 +1 @@
1
+service apache2 reload

+ 1
- 0
sitegen/hooks.d/000-print Прегледај датотеку

@@ -0,0 +1 @@
1
+../hooks.available/000-print

+ 1
- 1
sitegen/https.conf Прегледај датотеку

@@ -9,7 +9,7 @@
9 9
         SSLEngine on
10 10
         SSLCertificateFile /etc/ssl/private/%%HOST%%.crt
11 11
         SSLCertificateKeyFile /etc/ssl/private/%%HOST%%.key
12
-        SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.pem
12
+        SSLCertificateChainFile /etc/ssl/private/%%HOST%%-chain.crt
13 13
     </VirtualHost>
14 14
 </IfModule>
15 15
 <IfModule !mod_ssl.c>

Loading…
Откажи
Сачувај