Changes for umask and file access permissions in carnet-generate-ssl.
[apache2-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
6
7 # Source debconf library.
8 . /usr/share/debconf/confmodule
9
10 case "$1" in
11         configure)
12                 # continue below
13                 ;;
14
15         abort-upgrade|abort-remove|abort-deconfigure)
16                 exit 0
17                 ;;
18
19         *)
20                 echo "postinst called with unknown argument \`$1'" >&2
21                 exit 0
22                 ;;
23 esac
24
25
26 # Include CARNet functions.
27 . /usr/share/carnet-tools/functions.sh
28
29 PKG="apache2-cn"
30 VERSION="2.2-1"
31 CONFDIR="/etc/apache2"
32 CONF="$CONFDIR/apache2.conf"
33 A2MODEDIR="$CONFDIR/mods-enabled"
34 PORTCONF="$CONFDIR/ports.conf"
35 A2CNDIR=/usr/share/apache2-cn
36 TMPLDIR=$A2CNDIR/templates
37 CERTDIR=/etc/ssl/certs
38 A2PHPINI="/etc/php5/apache2/php.ini"
39
40 HOST=$(hostname)
41 FQDN=$(hostname --fqdn)
42 WEBMASTER="webmaster@$FQDN"
43 DOMAIN=$(hostname -d)
44 BACKUPDIR="/var/backups/apache2-cn"
45
46 backup_done=0
47 need_restart=0
48 apache2_sslcert=0
49 apache2_sslcf=
50 apache2_sslckf=
51 apache2_sslccf=
52 has_vhosts=0
53 temp_files=
54 has_listen_ssl=0
55 listen_ssl_mask=
56
57
58 # cleanup()
59 #
60 #   Cleanup all temp files.
61 #
62 cleanup () {
63
64         if [ -n "$temp_files" ]; then
65                 for item in $temp_files; do
66                         if [ -e "$item" ]; then
67                                 rm -f $item
68                         fi
69                 done
70         fi
71 }
72
73 # tag_conf()
74 #
75 #   Add CARNet package info lines to config's header.
76 #
77 tag_conf () {
78         
79         local conf_file
80         conf_file="$1"
81         
82         if [ -e "$conf_file" ]; then
83         
84                 cat >> $conf_file <<EOF
85 ## Begin - Generated by CARNet package apache2-cn
86 #
87 #  REMOVE this whole block if you DON'T WANT apache2-cn
88 #  to edit your configuration file.
89 #
90 ## End - Generated by CARNet package apache2-cn
91 EOF
92         fi
93 }
94
95 # chk_conf_tag ()
96 #
97 #   Check if configuration file has CARNet package info lines.
98 #   return:  $RET => 0 - tagged
99 #                    1 - not tagged or file does not exists
100 #                    2 - file exists, but it is not tagged
101 #
102 chk_conf_tag () {
103
104         local conf_file
105         conf_file="$1"
106         RET=1
107         
108         if [ -f "$conf_file" ]; then
109                 if egrep -q "^## Begin - Generated by CARNet package apache2-cn$" "$conf_file"; then
110                         RET=0
111                 else
112                         RET=2
113                 fi
114         fi
115 }
116
117 # conf_log_fix ()
118 #
119 #   Check CustomLog, ErrorLog and TransferLog paths - /var/log/apache/ is replaced
120 #   with /var/log/apache2/.
121 #
122 conf_log_fix () {
123
124         local conf_file out
125         conf_file="$1"
126
127         if [ -f "$conf_file" ]; then
128         
129             if egrep -iq '^[[:space:]]*(Error|Custom|Transfer)Log[[:space:]]*\/var\/log\/apache\/' "$conf_file"; then
130             
131                 out=$(mktemp ${conf_file}.XXXXXX)
132                 temp_files="${temp_files} ${out}"
133             
134                 sed 's/\(^[[:space:]]*\(Error\|Custom\|Transfer\)Log[[:space:]]*\)\/var\/log\/apache\//\1\/var\/log\/apache2\//I' \
135                     $conf_file > $out
136                 mv $out $conf_file
137             fi
138             
139             # Be sure..
140             chmod 644 $conf_file
141         fi
142 }
143
144 # generate_ssl()
145 #
146 #   Generate Apache2 web server SSL certificate.
147 #
148 generate_ssl () {
149
150         generate_ssl_output=$($A2CNDIR/carnet-generate-ssl ignore "$FQDN" "$WEBMASTER" "$DOMAIN" 2> /dev/null)
151         cp_echo "$generate_ssl_output"
152         need_restart=1
153 }
154
155 # listen_ssl()
156 #
157 #   Check if port 443 is configured in ports.conf file.
158 #
159 listen_ssl() {
160
161         if [ ! -f "$PORTCONF" ] || ! egrep -iq "^[[:space:]]*Listen[[:space:]]*.*443$" "$PORTCONF"; then
162         
163                 cp_echo "CN: Enabling SSL port (443) for Apache2 web server."
164
165                 out=$(mktemp ${PORTCONF}.XXXXXX)
166                 
167                 if [ -f "$PORTCONF" ]; then
168                         cp $PORTCONF $out
169                 fi
170                 
171                 echo "Listen 443" >> $out
172                 cp_mv $out $PORTCONF
173                 chmod 644 $PORTCONF
174                 
175                 need_restart=1
176                 temp_files="${temp_files} ${out}"
177         fi
178 }
179
180 # install_conf()
181 #
182 #   Install specified Apache2 configuration file.
183 #
184 install_conf() {
185
186         conftmpl="$A2CNDIR/$1.conf"
187         conf="$CONFDIR/conf.d/$2.conf"
188
189         if [ ! -e "$conf" ]; then
190         
191                 cp_echo "CN: Enabling CARNet specific configuration."
192                 cp "$conftmpl" "$conf"
193                 
194                 need_restart=1
195         else
196                 cp_echo "CN: $conf already exists, left untouched." 1>&2
197         fi
198 }
199
200 # install_vhost()
201 #
202 #   Install specified VirtualHost for Apache2 web server.
203 #
204 #   Invocation:
205 #
206 #   install_vhost [-nvh] [-d] [-s docroot_symlink_dest] template site site-enabled-symlink
207 #
208 #     -nvh - add NameVirtualHost
209 #     -d   - mkdir DocumentRoot
210 #     -r   - set DocumentRoot
211 #     -n   - set ServerName
212 #     -s X - symlink DocumentRoot to X (all in /var/www)
213 #
214 #   site - name of file in sites-available, host part of ServerName unless -r or -n is used
215 #   site-enabled-symlink - name of symlink in sites-enabled
216 #
217 install_vhost() {
218
219         add_namevirthost=
220         mkdir_docroot=
221         symlink_docroot=
222         docroot=
223         vhostname=
224   
225         while echo "x$1" | grep -q '^x-'; do
226             case "$1" in
227                 -nvh)
228                     add_namevirthost=1
229                     shift
230                     ;;
231                 -d)
232                     mkdir_docroot=1
233                     shift
234                     ;;
235                 -s)
236                     shift
237                     symlink_docroot="$1"
238                     shift
239                     ;;
240                 -r)
241                     shift
242                     docroot="$1"
243                     if ! echo "$docroot" | grep -q /; then
244                             docroot="/var/www/$docroot"
245                     fi
246                     shift
247                     ;;
248                 -n)
249                     shift
250                     vhostname="$1"
251                     shift
252                     ;;
253             esac
254         done
255
256         vhosttmpl="$1.template"
257         vhost="$2"
258         venabled="$3"
259         [ -z "$vhostname" ] && vhostname=$(echo "$vhost"| awk -F. '{print $1}')
260         force_vhost=
261
262         vhostdir=$CONFDIR/sites-available
263         venabledir=$CONFDIR/sites-enabled
264
265         if [ ! -e "$TMPLDIR/${vhosttmpl}" ]; then
266                 echo "E: vhost template ${vhosttmpl} not found in $TMPLDIR!" 1>&2
267                 exit 2
268         fi
269
270         [ -z "$docroot" ] && docroot="/var/www/$vhostname.$DOMAIN"
271   
272         # if we were broken mid-installation, force
273         if [ ! -e "$docroot" -a \( -n "$mkdir_docroot" -o -n "$symlink_docroot" \) ]; then
274                 force_vhost=1
275         fi
276   
277         # add vhost if either of these is true
278         # - adding is forced OR
279         # - it doesn't exist
280         #
281         if [ -n "$force_vhost" -o \( ! -e "$vhostdir/$vhost" -a ! -e "$venabledir/$venabled" \) ]; then
282         
283                 cp_echo "CN: Adding $vhost VirtualHost."
284                 out=$(mktemp $vhostdir/$vhost.XXXXXX)
285                 temp_files="${temp_files} ${out}"
286                 
287                 # CARNet header.
288                 tag_conf "$out"
289
290                 if [ "$add_namevirthost" ]; then
291                         nvh=$(awk -F'[ >]' '/^<VirtualHost/ {print $2}' $TMPLDIR/$vhosttmpl |\
292                             sed "s/IPADDR/$MYIP/g")
293                         echo "NameVirtualHost $nvh" >> $out
294                 fi
295     
296                 sed "s/HOST/$vhostname/g; s/DOMAIN/$DOMAIN/g;
297                      s#DOCROOT#$docroot#g; s/IPADDR/$MYIP/g" < $TMPLDIR/$vhosttmpl >> $out
298                 cp_mv $out $vhostdir/$vhost
299                 chmod 644 $vhostdir/$vhost
300                 ln -fs ../sites-available/$vhost $venabledir/$venabled    
301     
302                 if [ -n "$mkdir_docroot" -a ! -d "$docroot" ]; then
303                         mkdir "$docroot"
304                         echo '<html><body><h1>Radi!</h1></body></html>' > "$docroot/index.html"
305                 elif [ -n "$symlink_docroot" ]; then
306                         ln -fs "$symlink_docroot" "$docroot"
307                 fi
308
309                 need_restart=1
310         fi
311 }
312
313
314 # Set trap for deleting all temp files.
315 #
316 trap cleanup 0 1 2 15
317
318
319 # Make sure that monit conf for Apache is disabled.
320 #
321 if [ -f "/etc/monit.d/apache1.conf" ]; then
322         mv /etc/monit.d/apache1.conf /etc/monit.d/apache1.conf.disabled
323         pkill -9 -f /usr/sbin/monit || true
324 fi
325
326
327 # Make sure Apache is NOT running.
328 #
329 if [ -x /etc/init.d/apache ]; then
330         if [ -x /usr/sbin/invoke-rc.d ]; then
331                 invoke-rc.d apache stop || true
332         else
333                 /etc/init.d/apache stop || true
334         fi
335
336         pkill -9 -f '/usr/sbin/apache$' || true
337 fi
338
339
340 # Backup all configuration located in /etc/apache2/conf.d/ and
341 # /etc/apache2/sites-available/ directories.
342 #
343 if [ -e "$CONF" ]; then
344         cp_echo "CN: Doing backup for $CONF"
345         cp_backup_conffile -d $BACKUPDIR -p $CONF
346         backup_done=1
347 fi
348 if [ -d "$CONFDIR/conf.d" ] && [ -n "$(ls ${CONFDIR}/conf.d/)" ]; then
349         cp_echo "CN: Doing backup for all files in /etc/apache2/conf.d/"
350         for file in /etc/apache2/conf.d/*; do
351             if [ -z "$(echo $file | egrep '^/.*~')" ]; then
352                 cp_backup_conffile -d $BACKUPDIR -p $file
353             fi
354         done
355         backup_done=1
356 fi
357 if [ -d "$CONFDIR/sites-available" ] && [ -n "$(ls ${CONFDIR}/sites-available/)" ]; then
358         cp_echo "CN: Doing backup for all files in /etc/apache2/sites-available/"
359         for file in /etc/apache2/sites-available/*; do
360             if [ -z "$(echo $file | egrep '^/.*~')" ]; then
361                 cp_backup_conffile -d $BACKUPDIR -p $file
362             fi
363         done
364         backup_done=1
365 fi
366 if [ $backup_done -eq 1 ]; then
367         cp_echo "CN: Backup is located in directory: $BACKUPDIR/"
368 fi
369
370
371 # Enable Apache2 web server modules (cgi, rewrite, userdir, suexec, php5, ssl).
372 #
373 if [ -e "$CONF" ]; then
374
375         if [ ! -e "$A2MODEDIR/cgi.load" ]; then
376                 cp_echo "CN: Enabling CGI module for Apache2 web server."
377                 a2enmod cgi >/dev/null || true
378                 need_restart=1
379         fi
380
381         if [ ! -e "$A2MODEDIR/rewrite.load" ]; then
382                 cp_echo "CN: Enabling rewrite module for Apache2 web server."
383                 a2enmod rewrite >/dev/null || true
384                 need_restart=1
385         fi
386
387         if [ ! -e "$A2MODEDIR/userdir.load" ] || [ ! -e "$A2MODEDIR/userdir.conf" ]; then
388                 cp_echo "CN: Enabling userdir module for Apache2 web server."
389                 a2enmod userdir >/dev/null || true
390                 need_restart=1
391         fi
392
393         if [ ! -e "$A2MODEDIR/suexec.load" ]; then
394                 cp_echo "CN: Enabling SUEXEC module for Apache2 web server."
395                 a2enmod suexec >/dev/null || true
396                 need_restart=1
397         fi
398
399         if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then
400             if [ -e "/usr/lib/apache2/modules/libphp5.so" ]; then
401                 cp_echo "CN: Enabling PHP5 module for Apache2 web server."
402                 a2enmod php5 >/dev/null || true
403                 need_restart=1
404             fi
405         fi
406
407         if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then
408             if [ -e "/usr/lib/apache2/modules/libphp4.so" ]; then
409                 cp_echo "CN: Enabling PHP4 module for Apache2 web server."
410                 a2enmod php4 >/dev/null || true
411                 need_restart=1
412             fi
413         fi
414
415         if [ ! -e "$A2MODEDIR/ssl.load" ] || [ ! -e "$A2MODEDIR/ssl.conf" ]; then
416                 cp_echo "CN: Enabling SSL module for Apache2 web server."
417                 a2enmod ssl >/dev/null || true
418                 need_restart=1
419         fi
420 fi
421
422
423 # Install CARNet specific configuration file.
424 #
425 install_conf carnet 000-carnet
426
427 # Enable SSL port (443).
428 #
429 listen_ssl
430
431 # Disable default site configuration.
432 #
433 if [ -e "$CONF" ]; then
434         if [ -e "$CONFDIR/sites-enabled/000-default" ]; then
435                 cp_echo "CN: Disabling 000-default site configuration."
436                 a2dissite 000-default >/dev/null || true
437
438                 need_restart=1
439         fi
440 fi
441
442
443 # Apache2 SSL certificate.
444 #
445 has_listen_ssl=0
446
447 if [ -d "$CONFDIR/conf.d" ] && [ -n "$(ls $CONFDIR/conf.d)" ]; then
448         listen_ssl_mask=$CONFDIR/conf.d/*
449 fi
450 if [ -d "$CONFDIR/sites-enabled" ] && [ -n "$(ls $CONFDIR/sites-enabled)" ]; then
451         listen_ssl_mask=$listen_ssl_mask" "$CONFDIR/sites-enabled/*
452 fi
453
454 for file in $CONF $listen_ssl_mask; do
455         if [ -f "$file" ]; then
456                 if egrep -iq '^[[:space:]]*<VirtualHost .*443[[:space:]]*>' $file; then
457                         has_listen_ssl=1
458                         apache2_sslcert=1
459                         break
460                 fi
461         fi
462 done
463
464 if [ $apache2_sslcert -eq 0 ]; then
465
466         db_get apache2-cn/sslcf || true
467         apache2_sslcf="$RET"
468
469         if [ -n "$apache2_sslcf" ]; then
470
471                 db_get apache2-cn/sslckf || true
472                 apache2_sslckf="$RET"
473
474                 db_get apache2-cn/sslccf || true
475                 apache2_sslccf="$RET"
476         
477                 need_restart=1
478         else
479
480                 # Generate new SSL certificate files.
481                 generate_ssl
482         
483                 apache2_sslcf=
484                 apache2_sslckf=
485                 apache2_sslccf=
486         fi
487 fi
488
489
490 # Add VirtualHosts.
491 # - on fresh install
492 #
493 if [ -z "$2" ]; then
494
495     db_get apache2-cn/wwwhost || true
496     if [ "$RET" = "true" ]; then
497
498         # Add WWW VirtualHost.
499         if [ -f "$CONFDIR/sites-available/$FQDN" ]; then
500                 cp_backup_conffile -d $BACKUPDIR -p $CONFDIR/sites-available/$FQDN
501         fi
502         if [ -f "$CONFDIR/sites-available/www.$DOMAIN" ]; then
503                 cp_backup_conffile -d $BACKUPDIR -p $CONFDIR/sites-available/www.$DOMAIN
504         fi
505
506         chk_conf_tag "$CONFDIR/sites-available/$FQDN"
507         if [ ! -f "$CONFDIR/sites-available/$FQDN" ] || [ $RET -eq 0 ]; then
508                 install_vhost -nvh -d -r www.$DOMAIN default $FQDN 000-$FQDN
509                 need_restart=1
510         fi
511
512         chk_conf_tag "$CONFDIR/sites-available/www.$DOMAIN"
513         if [ ! -f "$CONFDIR/sites-available/www.$DOMAIN" ] || [ $RET -eq 0 ]; then
514                 install_vhost default www.$DOMAIN www.$DOMAIN
515                 need_restart=1
516         fi
517     else
518
519         # No WWW VirtualHost.
520         if [ -f "$CONFDIR/sites-available/$FQDN" ]; then
521                 cp_backup_conffile -d $BACKUPDIR -p $CONFDIR/sites-available/$FQDN
522         fi
523
524         chk_conf_tag "$CONFDIR/sites-available/$FQDN"
525         if [ ! -f "$CONFDIR/sites-available/$FQDN" ] || [ $RET -eq 0 ]; then
526                 install_vhost -nvh -d -r $FQDN default $FQDN 000-$FQDN
527                 need_restart=1
528         fi
529     fi
530 fi
531
532
533 # Add VirtualHost for SSL?
534 #
535 if [ $apache2_sslcert -eq 0 ]; then
536
537         if [ -f "$CONFDIR/sites-available/ssl" ]; then
538                 cp_backup_conffile -d $BACKUPDIR -p $CONFDIR/sites-available/ssl
539         fi
540
541         # No active SSL VirtualHosts found - add new one.
542         chk_conf_tag "$CONFDIR/sites-available/ssl"
543         if [ ! -f "$CONFDIR/sites-available/ssl" ] || [ $RET -eq 0 ]; then
544                 install_vhost -r $FQDN -n $HOST ssl ssl 001-ssl
545                 need_restart=1
546         fi
547 fi
548
549
550 # Check SSL certificates location for VirtualHosts.
551 #
552 if [ $apache2_sslcert -eq 0 ]; then
553
554         chk_conf_tag "${CONFDIR}/sites-available/ssl"
555         if [ $RET -eq 0 ] && [ -n "$apache2_sslcf" ]; then
556
557                 SSLTMP=$(mktemp ${CONFDIR}/ssltmp.XXXXXX)
558                 temp_files="${temp_files} ${SSLTMP} ${SSLTMP}.cn-old"
559                 cp ${CONFDIR}/sites-available/ssl $SSLTMP
560
561                 # SSLCertificateFile
562                 cp_check_and_sed "^[[:space:]]*SSLCertificateFile \/etc\/ssl\/certs\/apache2\.pem" \
563                     "s#SSLCertificateFile /etc/ssl/certs/apache2.pem#SSLCertificateFile $apache2_sslcf #g" \
564                     $SSLTMP || true
565
566                 # SSLCertificateKeyFile
567                 cp_check_and_sed "^[[:space:]]*SSLCertificateKeyFile \/etc\/ssl\/private\/apache2\.key" \
568                     "s#SSLCertificateKeyFile /etc/ssl/private/apache2.key#SSLCertificateKeyFile $apache2_sslckf #g" \
569                     $SSLTMP || true
570
571                 # SSLCertificateChainFile
572                 if [ -n "$apache2_sslccf" ]; then
573                     cp_check_and_sed "^# SSLCertificateChainFile \/etc\/ssl\/certs/sureserverEDU\.pem" \
574                         "s#\# SSLCertificateChainFile /etc/ssl/certs/sureserverEDU.pem#SSLCertificateChainFile $apache2_sslccf #g" \
575                         $SSLTMP || true
576                 fi
577
578                 cp_mv $SSLTMP ${CONFDIR}/sites-available/ssl
579
580                 need_restart=1
581
582                 # Just to be sure.
583                 [ -e "${SSLTMP}" ] && rm -f ${SSLTMP}
584                 [ -e "${SSLTMP}.cn-old" ] && rm -f ${SSLTMP}.cn-old
585         fi
586 fi
587
588
589 # Check file access permissions for SSL certificates.
590 #
591 cp_echo "CN: Checking file access permissions for Apache2 SSL certificates."
592 sslkey=/etc/ssl/private
593 sslcerts="${sslkey}/ca.key ${sslkey}/apache2-ca.key ${sslkey}/apache2.key"
594 for certf in $sslcerts; do
595         if [ -f "$certf" ]; then
596             chmod 600 $certf
597         fi
598 done
599
600
601 # Check for CustomLog, ErrorLog and TransferLog in Apache2 configuration.
602 #
603 cp_echo "CN: Checking Apache2 CustomLog, ErrorLog and TransferLog directives."
604 if [ -d "$CONFDIR/conf.d" ] && [ -n "$(ls $CONFDIR/conf.d)" ]; then
605         log_mask=$CONFDIR/conf.d/*
606 fi
607 if [ -d "$CONFDIR/sites-available" ] && [ -n "$(ls $CONFDIR/sites-available)" ]; then
608         log_mask=$log_mask" "$CONFDIR/sites-available/*
609 fi
610 for file in $CONF $log_mask; do
611         chk_conf_tag "$file"
612         if [ $RET -eq 0 ]; then
613                 conf_log_fix "$file"
614         fi
615 done
616
617
618 # Start Apache2 web server on boot?
619 # This will enable Apache2 in /etc/default/apache2 file.
620 #
621 if egrep -q "^[[:space:]]*NO_START=1" /etc/default/apache2; then
622         cp_check_and_sed NO_START=1 s/NO_START=1/NO_START=0/ /etc/default/apache2 || true
623         need_restart=1
624 fi
625
626
627 db_stop || true
628
629
630 # Remove old AOSI configuration for Apache: aosi-www.conf, aosi.conf.
631 #
632 if [ -e "$CONFDIR/conf.d/aosi-www.conf" ] || [ -e "$CONFDIR/conf.d/aosi.conf" ]; then
633         cp_echo "CN: Removing old AOSI configuration files for Apache2."
634         need_restart=1
635 fi
636 [ -e "$CONFDIR/conf.d/aosi-www.conf" ] && rm -f $CONFDIR/conf.d/aosi-www.conf
637 [ -e "$CONFDIR/conf.d/aosi.conf" ] && rm -f $CONFDIR/conf.d/aosi.conf
638
639
640 # Stop Apache web server and disable Apache automatic start on boot.
641 #
642 if [ -x "/etc/init.d/apache" ]; then
643
644         # Stop Apache.
645         if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
646                 invoke-rc.d apache stop || true
647         else
648                 /etc/init.d/apache stop || true
649         fi
650
651         # Disable automatic start on boot.
652         if [ -x "`which update-rc.d 2>/dev/null`" ]; then
653                 update-rc.d -f apache remove > /dev/null 2>&1 || true
654                 update-rc.d apache stop 90 6 . > /dev/null 2>&1 || true
655         fi
656 fi
657
658 # Also check for Apache-SSL web server.
659 #
660 if [ -x "/etc/init.d/apache-ssl" ]; then
661
662         # Stop Apache-SSL.
663         if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
664                 invoke-rc.d apache-ssl stop || true
665         else
666                 /etc/init.d/apache-ssl stop || true
667         fi
668
669         # Disable automatic start on boot.
670         if [ -x "`which update-rc.d 2>/dev/null`" ]; then
671                 update-rc.d -f apache-ssl remove > /dev/null 2>&1 || true
672                 update-rc.d apache-ssl stop 90 6 . > /dev/null 2>&1 || true
673         fi
674 fi
675
676
677 # Restart Apache2 web server if needed.
678 #
679 if [ $need_restart -eq 1 ]; then
680
681         # Check Apache2 web server configuration.
682         if apache2ctl configtest 2>/dev/null; then
683
684                 # Restart Apache2 web server.
685                 if [ -x "/etc/init.d/apache2" ]; then
686                     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
687                         invoke-rc.d apache2 force-reload || true
688                     else
689                         /etc/init.d/apache2 force-reload || true
690                     fi
691                 fi
692         else
693
694                 # Something is broken.
695                 cp_echo "CN: Your Apache2 configuration seem to be broken."
696                 cp_echo "CN: Please, check the service after the installation finishes!"
697         fi
698 fi
699
700
701 # Mail root
702 #
703 cp_mail "$PKG"
704
705
706 # (re)generate monit.d files if monit-cn is installed.
707 #
708 if [ -x "/usr/sbin/update-monit.d" ]; then
709         cp_echo "CN: Updating monit configuration..."
710         update-monit.d || true
711 fi
712
713
714 exit 0