Browse Source

hooks; generate-ssl-cert

tags/v2.0.0
Robin Thoni 9 years ago
parent
commit
08c2974a5f

+ 1
- 0
.gitignore View File

1
+*.swp

+ 21
- 0
generate-ssl-cert.sh View File

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 View File

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

+ 21
- 14
sitegen.sh View File

4
 conf_dir=/etc/sitegen/
4
 conf_dir=/etc/sitegen/
5
 site_dir=/var/
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
 makeDir()
10
 makeDir()
20
 {
11
 {
30
   readlink -m "$1"
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
 if [ $# -eq 0 ] || [ $# -gt 2 ] || [ "$1" = "--help" ]
40
 if [ $# -eq 0 ] || [ $# -gt 2 ] || [ "$1" = "--help" ]
34
 then
41
 then
35
   echo "Usage:" $(basename $0) "hostname [config=default]" >&2
42
   echo "Usage:" $(basename $0) "hostname [config=default]" >&2
36
   exit 1
43
   exit 1
37
 fi
44
 fi
38
 
45
 
39
-loadConf "${conf_file}"
40
-loadConf "${conf_file_local}"
41
-
42
 host="$1"
46
 host="$1"
43
 if [ $# -eq 2 ]
47
 if [ $# -eq 2 ]
44
 then
48
 then
75
 
79
 
76
 sed -e "${sed_host}" -e "${sed_root}" "${conf_conf}" > "${site_conf}"
80
 sed -e "${sed_host}" -e "${sed_root}" "${conf_conf}" > "${site_conf}"
77
 sed -e "${sed_host}" -e "${sed_root}" "${conf_include}" > "${site_include}"
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 View File

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 View File

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 View File

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

+ 1
- 0
sitegen/hooks.available/200-a2ensite View File

1
+a2ensite "${host}.conf"

+ 1
- 0
sitegen/hooks.available/300-reload View File

1
+service apache2 reload

+ 1
- 0
sitegen/hooks.d/000-print View File

1
+../hooks.available/000-print

+ 1
- 1
sitegen/https.conf View File

9
         SSLEngine on
9
         SSLEngine on
10
         SSLCertificateFile /etc/ssl/private/%%HOST%%.crt
10
         SSLCertificateFile /etc/ssl/private/%%HOST%%.crt
11
         SSLCertificateKeyFile /etc/ssl/private/%%HOST%%.key
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
     </VirtualHost>
13
     </VirtualHost>
14
 </IfModule>
14
 </IfModule>
15
 <IfModule !mod_ssl.c>
15
 <IfModule !mod_ssl.c>

Loading…
Cancel
Save