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