Changes for umask and file access permissions in carnet-generate-ssl.
[apache2-cn.git] / debian / config
1 #!/bin/sh
2
3 set -e
4
5 # Load debconf
6 . /usr/share/debconf/confmodule
7
8 if [ "$1" != reconfigure ]; then
9
10     apache2_done=1
11
12     db_fget apache2-cn/wwwhost seen
13     if [ "$RET" != "true" ]; then
14         apache2_done=0
15     fi
16
17     test $apache2_done -eq 1 && exit 0
18 fi
19
20
21 CONFDIR="/etc/apache2"
22 CONF="$CONFDIR/apache2.conf"
23 HOST=$(hostname)
24 DOMAIN=$(hostname -d)
25
26
27 # Check for existing SSL VirtualHosts.
28 #
29 has_listen_ssl=0
30
31 if [ -d "$CONFDIR/conf.d" ] && [ -n "$(ls $CONFDIR/conf.d)" ]; then
32         listen_ssl_mask=$CONFDIR/conf.d/*
33 fi
34 if [ -d "$CONFDIR/sites-enabled" ] && [ -n "$(ls $CONFDIR/sites-enabled)" ]; then
35         listen_ssl_mask=$listen_ssl_mask" "$CONFDIR/sites-enabled/*
36 fi
37
38 for file in $CONF $listen_ssl_mask; do
39     if [ -f "$file" ]; then
40         if egrep -iq '^[[:space:]]*<VirtualHost .*443[[:space:]]*>' $file; then
41             has_listen_ssl=1
42             break
43         fi
44     fi
45 done
46
47
48 # SSL certificates.
49 #
50 if [ $has_listen_ssl -eq 1 ]; then
51
52         # SSL configuration already exists - no need for SSL certificates.    
53         db_set apache2-cn/sslcf "" || true
54         db_set apache2-cn/sslckf "" || true
55         db_set apache2-cn/sslccf "" || true
56
57 else
58
59         # SSL certificates information..
60         SSLCF=1
61         while [ $SSLCF -eq 1 ]; do
62
63             # SSL certificate file input.
64             db_input critical apache2-cn/sslcf || true
65             db_go || true
66             
67             db_get apache2-cn/sslcf || true
68             
69             if [ -n "$RET" ]; then
70
71                 if [ -f "$RET" ]; then
72                 
73                     # SSL certificate file exists.
74                     SSLCF=0
75                     
76                     SSLCKF=1
77                     while [ $SSLCKF -eq 1 ]; do
78                     
79                         # SSL certificate key file input.
80                         db_input critical apache2-cn/sslckf || true
81                         db_go || true
82                 
83                         db_get apache2-cn/sslckf || true
84                 
85                         if [ -n "$RET" ]; then
86                         
87                             if [ -f "$RET" ]; then
88                         
89                                 # SSL certificate key file exists.    
90                                 SSLCKF=0
91                                 
92                                 SSLCCF=1
93                                 while [ $SSLCCF -eq 1 ]; do
94                                 
95                                     # SSL certificate chain file input.
96                                     db_input critical apache2-cn/sslccf || true
97                                     db_go || true
98                                     
99                                     db_get apache2-cn/sslccf || true
100                                     
101                                     if [ -n "$RET" ]; then
102                                             
103                                         if [ -f "$RET" ]; then
104                                         
105                                             # SSL certificate chain file exists.
106                                             SSLCCF=0
107                                         fi
108                                     else
109                                         SSLCCF=0
110                                     fi
111                                 done
112                             fi
113                         fi
114                     done
115                 fi
116             else
117             
118                 # No SSL certificates specified.
119                 db_set apache2-cn/sslcf "" || true
120                 db_set apache2-cn/sslckf "" || true
121                 db_set apache2-cn/sslccf "" || true
122                 
123                 SSLCF=0
124             fi
125         done
126 fi
127
128
129 # Use WWW VirtualHost?
130 # - only during fresh install
131 #
132 if [ -z "$2" ]; then
133         db_subst apache2-cn/wwwhost stroj_domena "${HOST}.${DOMAIN}"
134         db_subst apache2-cn/wwwhost www_domena "www.${DOMAIN}"
135         db_input critical apache2-cn/wwwhost || true
136         db_go || true
137 fi
138
139 exit 0