X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=debian%2Fpostinst;h=1f30bd63391147b58ebeec369578e78096a48d39;hb=HEAD;hp=c53e5f089b8f696d5c52628dbf0811fba6cdfcd0;hpb=1ff8d171b246925b19d2c8299fbcd71f55d2edcd;p=squirrelmail-cn.git diff --git a/debian/postinst b/debian/postinst old mode 100644 new mode 100755 index c53e5f0..1f30bd6 --- a/debian/postinst +++ b/debian/postinst @@ -2,24 +2,24 @@ set -e -[ "$DEBIAN_SCRIPT_DEBUG" ] && set -x +[ "$DEBIAN_SCRIPT_DEBUG" ] && set -x # Source debconf library. . /usr/share/debconf/confmodule case "$1" in - configure) - # continue below - ;; - - abort-upgrade|abort-remove|abort-deconfigure) - exit 0 - ;; - - *) - echo "postinst called with unknown argument \`$1'" >&2 - exit 0 - ;; + configure) + # continue below + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + exit 0 + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 0 + ;; esac @@ -31,40 +31,69 @@ FQDN=`hostname --fqdn` . /usr/share/carnet-tools/functions.sh unset CP_ECHO_RETURN -mv_old_backups() { - - # Clean up /etc, nove old jun^H^H^Hbackups where they belong - glob="$1.old.*-*-*.*:*:*" - - # ${glob%/*} (dirname $glob) does not work for files in root - if [ -n "$(find ${glob%/*} -name ${glob##*/})" ]; then - for i in $(find ${glob%/*} -name ${glob##*/}) - do - cp_backup_conffile "$i" "$2" - rm -f "$i" - done - fi + +if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then + . /usr/share/apache2/apache2-maintscript-helper + + squirrelmail_enable() { + cp_echo "CN: Enabling $PKG configuration for Apache2." + return 0 + } +else + cp_echo "CN: Could not load Apache 2.4 maintainer script helper." + + squirrelmail_enable() { + return 1 + } +fi + +mv_old_backups () { + # Clean up /etc, nove old jun^H^H^Hbackups where they belong + local glob="$1.old.*-*-*.*:*:*" + + # ${glob%/*} (dirname $glob) does not work for files in root + if [ -n "$(find ${glob%/*} -name ${glob##*/})" ]; then + for i in $(find ${glob%/*} -name ${glob##*/}) + do + cp_backup_conffile "$i" "$2" + rm -f "$i" + done + fi } # listconffiles () # -# Recursively walks /etc/apache2/apache2.conf for Include directives. +# Recursively walks /etc/apache2/apache2.conf for Include and +# IncludeOptional directives. # Returns all configfiles so defined. # -function listconffiles () { - - local i incs +listconffiles () { + local i incs + local base_dir="`dirname $1`" + + incs=`awk 'tolower($1) ~ /include(optional)?/ { sub("/$","/*",$2); print $2; }' $1` + incs=`echo "$incs" | sed -r "s#^([^/])#${base_dir}/\1#"` + if [ -n "$incs" ]; then + for i in $incs; do + if [ -e "$i" ]; then echo "`readlink -m -q $i`"; listconffiles "$i"; fi + done + fi +} - incs=`awk 'tolower($1) == "include" { sub("/$","/*",$2); print $2; }' $1` - if [ -n "$incs" ]; then - for i in $incs; do - if [ -e "$i" ]; then echo "$i"; listconffiles "$i"; fi - done - fi +# genlocales () +# +# Update/generate localisation files from templates if locales-all +# is not installed. +# +genlocales () { + if [ -f /usr/lib/locales-all/supported.tar.lzma ] ; then + cp_echo "CN: locales-all installed, skipping locales generation." + else + locale-gen + fi } -reload="" DATE=`date +%Y-%m-%d.%H:%M:%S` CONFDIR=/etc/squirrelmail CONF=$CONFDIR/apache.conf @@ -76,70 +105,69 @@ mv_old_backups $CONF $backup_name # if [ -f "$CONF" ]; then - # Backup first. - if cp_check_and_backup "$CONF" "$backup_name"; then - cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"." - fi - - # Check if we already modified apache.conf - if ! egrep -q "^[ ]+RewriteRule \. https" "$CONF"; then - - echo -n "CN: Updating Apache2 configuration for Squirrelmail" - perl -n -e 'print if ! m|^Alias\s*/webmail|' "$CONF" > $CONF.tmp - - cp-update -t squirrelmail-cn $CONF.tmp <<-EOF - # Force SSL for /webmail -> you can still use /squirrelmail - Alias /webmail /usr/share/squirrelmail - - - - - RewriteEngine on - RewriteCond %{HTTPS} !=on - RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L] - - - - - # - # WARNING: This file is automatically included in each VirtualHost - # entry you might have. Do not enable the VirtualHost example provided - # in this file, it WILL break your Apache configuration. Copy the - # VirtualHost section to the standard webserver configuration file - # instead. - # - EOF - cp_mv $CONF.tmp $CONF - - # This will break if cp_backup_conffile ever changes destination path - if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then - echo "." - cp_echo "CN: Updated Apache2 configuration for Squirrelmail." - reload="reload" - else - echo "... no changes." - fi + # Backup first. + if cp_check_and_backup "$CONF" "$backup_name"; then + cp_echo "CN: Old $CONF saved as \"/var/backups/$backup_name.bak\"." + fi + + # Check if we already modified apache.conf + if ! egrep -q "^[ ]+RewriteRule \. https" "$CONF"; then + echo -n "CN: Updating Apache2 configuration for Squirrelmail" + perl -n -e 'print if ! m|^Alias\s*/webmail|' "$CONF" > $CONF.tmp + + cp-update -t $PKG $CONF.tmp <<-EOF +# Force SSL for /webmail -> you can still use /squirrelmail +Alias /webmail /usr/share/squirrelmail + + + + + RewriteEngine on + RewriteCond %{HTTPS} !=on + RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L] + + + + +# +# WARNING: This file is automatically included in each VirtualHost +# entry you might have. Do not enable the VirtualHost example provided +# in this file, it WILL break your Apache configuration. Copy the +# VirtualHost section to the standard webserver configuration file +# instead. +# +EOF + cp_mv $CONF.tmp $CONF + + # This will break if cp_backup_conffile ever changes destination path + if ! cmp -s "$CONF" "/var/backups/$backup_name.bak"; then + echo "." + cp_echo "CN: Updated Apache2 configuration for Squirrelmail." + else + echo "... no changes." fi + fi fi hconf=/etc/apache2/apache2.conf sconf=/etc/apache2/sites-available/ssl -# Include Squirrelmail apache.conf in Apache2 web server configuration -# (directory /etc/apache2/conf.d/), but only if we are not present in -# Apache2 configuration at all. +# Remove obsolete symbolic link. # -# We're not using listconffiles from apache-common Debian package. -# apache-common is no longer available in Debian Lenny. We're using -# listconffiles() function instead. +if [ "`readlink -q -m /etc/apache2/conf.d/$PKG.conf`" = "$CONF" ]; then + rm -f /etc/apache2/conf.d/$PKG.conf +fi + +# Include Squirrelmail apache.conf in Apache2 web server configuration, +# but only if we are not present in Apache2 configuration at all. # apache2listconf=`listconffiles "$hconf" | grep "$CONF"` || true -apache2squirrel=`ls -l /etc/apache2/conf.d/ | grep "$CONF"` || true -if [ -z "$apache2listconf" -a -z "$apache2squirrel" ]; then - ln -s "$CONF" /etc/apache2/conf.d/squirrelmail-cn.conf - reload=reload +if [ -z "$apache2listconf" ]; then + if [ ! -L /etc/apache2/conf-available/$PKG.conf -a ! -f /etc/apache2/conf-available/$PKG.conf ]; then + ln -sf "$CONF" /etc/apache2/conf-available/$PKG.conf + fi fi @@ -149,30 +177,30 @@ CONF="$CONFDIR/config.php" TMPL="$CONFDIR/config_default.php" mv_old_backups "$CONF" "`basename $CONF`" if cp_check_and_backup "$CONF"; then - cp_echo "CN: Old $CONF saved as \"/var/backups/${CONF##*/}.bak\"." + cp_echo "CN: Old $CONF saved as \"/var/backups/${CONF##*/}.bak\"." fi # We use sed to replace old defaults with ours. # Must escape \$ because of shell expansion. # seddef="/^[ ]*\\\$org_logo[ ]*=/s/sm_logo\.jpg/sm_carnet_logo.png/; - /^[ ]*\\\$org_logo[ ]*=/s/sm_logo\.png/sm_carnet_logo.png/; - /^[ ]*\\\$org_logo[ ]*=/s/sm_carnet_logo\.jpg/sm_carnet_logo.png/; - /^[ ]*\\\$domain[ ]*=/s/mydomain\.com/$domainname/; - /^[ ]*\\\$default_charset[ ]*=/s/iso-8859-1/iso-8859-2/; - /^[ ]*\\\$org_logo_width[ ]*=/s/308/0/; - /^[ ]*\\\$org_logo_height[ ]*=/s/111/0/; - /^[ ]*\\\$squirrelmail_default_language[ ]*=/s/en_US/hr_HR/; - /^[ ]*\\\$data_dir[ ]*=/s/\.\.\/data\//\/var\/lib\/squirrelmail\/data\//; - " + /^[ ]*\\\$org_logo[ ]*=/s/sm_logo\.png/sm_carnet_logo.png/; + /^[ ]*\\\$org_logo[ ]*=/s/sm_carnet_logo\.jpg/sm_carnet_logo.png/; + /^[ ]*\\\$domain[ ]*=/s/mydomain\.com/$domainname/; + /^[ ]*\\\$default_charset[ ]*=/s/iso-8859-1/iso-8859-2/; + /^[ ]*\\\$org_logo_width[ ]*=/s/308/0/; + /^[ ]*\\\$org_logo_height[ ]*=/s/111/0/; + /^[ ]*\\\$squirrelmail_default_language[ ]*=/s/en_US/hr_HR/; + /^[ ]*\\\$data_dir[ ]*=/s/\.\.\/data\//\/var\/lib\/squirrelmail\/data\//; + " # Left frame size to 220px. # $default_left_size = '220'; # db_get squirrelmail-cn/leftwidth || true if [ "$RET" = "true" ]; then - seddef="$seddef/^[ ]*\\\$default_left_size[ ]*=/s/'[0-9]*'/'220'/; - " + seddef="$seddef/^[ ]*\\\$default_left_size[ ]*=/s/'[0-9]*'/'220'/; + " fi # Change CSS file for Squirrelmail. @@ -180,8 +208,8 @@ fi # db_get squirrelmail-cn/themecss || true if [ "$RET" = "true" ]; then - seddef="$seddef/^[ ]*\\\$theme_css[ ]*=/s/=.*/= SM_PATH . 'themes\/css\/squirrelmail-cn.css';/; - " + seddef="$seddef/^[ ]*\\\$theme_css[ ]*=/s/=.*/= SM_PATH . 'themes\/css\/squirrelmail-cn.css';/; + " fi db_stop || true @@ -189,128 +217,63 @@ db_stop || true # Check for our dovecot package; if it is installed, assume it's used. # if dpkg -l dovecot-cn 2>/dev/null | grep -q '^ii'; then - seddef="$seddef/^[ ]*\\\$imap_server_type[ ]*=/ {s/cyrus/dovecot/;s/other/dovecot/;s/uw/dovecot/} - " -fi - -# Would there be any changes, perhaps? -# -if cp_check_and_sed '.' "$seddef" "$CONF"; then - changed=1 -fi - -if grep -q x62 "$CONF"; then - really_old_config=1 + seddef="$seddef/^[ ]*\\\$imap_server_type[ ]*=/ {s/cyrus/dovecot/;s/other/dovecot/;s/uw/dovecot/} + " fi +cp_check_and_sed '.' "$seddef" "$CONF" || true -# -# MORE FIXES... -# - -# Global $config_version; -# -if ! egrep -q '^[ ]*global[ ]+\$config_version' "$CONF"; then - really_old_config=1 - #echo "CN: Adding \"global \$config_version;\" to config.php." - perl -p -e 'print "global \$config_version;\n" if (/^\s*\$config_version/);' \ - "$CONF" > "$CONF.tmp" - cp_mv "$CONF.tmp" "$CONF" -fi - -# This was missing on some machines -# -if ! egrep -q '^[ ]*\$allow_thread_sort' $CONF; then - to_add='\$allow_thread_sort = false;\n' - cp_echo "CN: Adding \"\$allow_thread_sort\"." - perl -p -e 'if (! $a && /^\s*\$edit_name/) { - $_ .= "'"$to_add"'"; $a = 1; } - elsif (! $a && /^\?>/) { - $_ = "'"$to_add"'" . $_; $a = 1; }' \ - $CONF > "$CONF.tmp" - cp_mv "$CONF.tmp" "$CONF" -fi -# Shouldn't use /etc/hostname, especially if it contains only the host part -# replace -# $domain = implode('', file('/etc/hostname')); -# with -# $domain = trim(implode('',file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name'))); +# Check /etc/hostname and /etc/mailname, because +# $domain = trim(implode('', file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name'))); # -if egrep -q "^[[:blank:]]*\\\$domain[[:blank:]]*=[[:blank:]]*implode\\('',[[:blank:]]*file\\('/etc/hostname'\\)\\);" $CONF; then - nodots= - nomailname= - grep -q '\.' /etc/hostname || nodots=1 - [ -e /etc/mailname ] || nomailname=1 - if cp_check_and_sed "^[[:blank:]]*\\\$domain[[:blank:]]*=[[:blank:]]*implode\\('',[[:blank:]]*file\\('/etc/hostname'\\)\\);" \ - "s|^[ \t]*\\\$domain[ \t]*=[ \t]*implode('',[ \t]*file('/etc/hostname'));|\$domain = trim(implode('',file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));|" \ - $CONF; then - cp_echo "CN: config.php updated to use either /etc/mailname or /etc/hostname" - fi -fi +nodots= +nomailname= +grep -q '\.' /etc/hostname || nodots=1 +[ -e /etc/mailname ] || nomailname=1 -# Generate hr_HR locale if needed. +# Check for hr_HR locale. # -if ! egrep -q '^hr_HR ISO-8859-2\b' /etc/locale.gen; then - if [ -f /etc/locale.gen ]; then - echo "hr_HR ISO-8859-2" >> /etc/locale.gen - cp_echo "CN: Added hr_HR locale to /etc/locale.gen." - else - echo "hr_HR ISO-8859-2" > /etc/locale.gen - cp_echo "CN: /etc/locale.gen created." - fi - dpkg-reconfigure -f noninteractive locales +if [ -f /etc/locale.gen ]; then + if ! egrep -q '^hr_HR ISO-8859-2\b' /etc/locale.gen; then + echo "hr_HR ISO-8859-2" >> /etc/locale.gen + cp_echo "CN: Added hr_HR locale to /etc/locale.gen." + genlocales + fi +else + echo "hr_HR ISO-8859-2" > /etc/locale.gen + cp_echo "CN: /etc/locale.gen created." + genlocales fi -# Check Apache2 web server for restart/reload. +# Mailname info... # -if [ -n "$reload" ]; then - - # Restart Apache2 web server. - if [ -x "/etc/init.d/apache2" ]; then - if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then - invoke-rc.d apache2 "$reload" || exit $? - else - /etc/init.d/apache2 "$reload" || exit $? - fi - fi +if [ "$nodots" -o "$nomailname" ]; then + cp_echo + cp_echo "CN: Make sure that /etc/mailname contains a fully qualified domain name" + cp_echo "CN of this machine! Sending mail via squirrelmail might fail if the FQDN" + cp_echo "CN cannot be found in either /etc/mailname or /etc/hostname." + cp_echo "CN Read mailname(5) man page for details." + cp_echo -mailonly "CN If this machine receives mail for both user@`hostname -f` and " + cp_echo -mailonly "CN user@`hostname -d`, you can also put just the domain in there." + cp_echo fi - -# Warn user of really old config file -# -if [ "$really_old_config" ]; then - echo - echo "CN: You have a really old config file." - cp_echo -m "CN: Old \"$CONF\" detected during installation." - cp_echo "CN The known bad options were fixed, but it is _strongly_ recommended that" - cp_echo "CN you either copy over the new template, and reconfigure this package" - cp_echo - cp_echo " cp $TMPL $CONF" - cp_echo " dpkg-reconfigure squirrelmail-cn" - cp_echo - cp_echo "CN or use squirrelmail-configure (conf.pl) to generate a fresh" - cp_echo " ${CONF} file." - echo +if squirrelmail_enable; then + apache2_invoke enconf $PKG fi - -# Mailname info... -# -if [ "$nodots" -o "$nomailname" ]; then - cp_echo - cp_echo "CN: Make sure that /etc/mailname contains a fully qualified domain name" - cp_echo "CN of this machine! Sending mail via squirrelmail might fail if the FQDN" - cp_echo "CN cannot be found in either /etc/mailname or /etc/hostname." - cp_echo "CN Read mailname(5) man page for details." - cp_echo -mailonly "CN If this machine receives mail for both user@`hostname -f` and " - cp_echo -mailonly "CN user@`hostname -d`, you can also put just the domain in there." +if ! apache2ctl configtest >/dev/null 2>&1; then + cp_echo "CN: Your Apache2 configuration seems to be broken." + cp_echo "CN: Please, check the service after the installation finishes!" fi # Mail root # cp_mail "$PKG" +#DEBHELPER# + exit 0