X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=debian%2Fpostinst;h=f08937c712f8ef5e64546a150f0b13f4c0b1ee15;hb=930386b4d1e6bb99259c06ece7bbf410b8e4d22e;hp=a3b3604b7990cdfbc997b3c1ea52f3c09177b69e;hpb=df6447ce620a5d010c17ba6413ac6a1fd59d0868;p=webalizer-cn.git diff --git a/debian/postinst b/debian/postinst index a3b3604..f08937c 100755 --- a/debian/postinst +++ b/debian/postinst @@ -1,62 +1,123 @@ #!/bin/sh -[ "$1" = "configure" ] || exit 0 -[ "$DEBIAN_SCRIPT_DEBUG" ] && set -x +set -e -# Load CARNet Tools -. /usr/share/carnet-tools/functions.sh +[ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx +[ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx -# Debconf +# Load Debconf . /usr/share/debconf/confmodule +db_version 2.0 + +# Include CARNET Tools +. /usr/share/carnet-tools/functions.sh -# Get some useful functions (apache-common) -. /usr/share/apache/postinst.common +PKG="webalizer-cn" +WDIR="/var/www/webalizer" +WHTPASSWD="$WDIR/.htpasswd" +WCONF="/etc/webalizer/webalizer.conf" +WCONFBAK=`basename $WCONF` -dir=/var/www/webalizer -htpasswd=$dir/.htpasswd -CONF=/etc/webalizer/webalizer.conf -BACKUPDIR=/var/backups -CONFBAK=$BACKUPDIR/`basename $CONF`.bak -oldreporttitle="Usage Statistics for" +oldreporttitle="usage statistics for" reporttitle="Statistika pristupa za" +customized=0 -# Check if there is some old webalizer-cn.conf file in Apache 1.x conf.d directory -ddosen -if [ -f "/etc/apache/conf.d/webalizer-cn.conf" ]; then - if ! cmp -s "/etc/apache/conf.d/webalizer-cn.conf" "/etc/apache2/conf.d/webalizer-cn.conf"; then - mv /etc/apache/conf.d/webalizer-cn.conf /etc/apache2/conf.d/webalizer-cn.conf - fi -fi +if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then + . /usr/share/apache2/apache2-maintscript-helper + + webalizer_enable() { + cp_echo "CN: Enabling $PKG configuration for Apache2." + return 0 + } +else + cp_echo "CN: Could not load Apache 2.4 maintainer script helper." -temp=`pget $CONF OutputDir |tail -n 1|awk '{print $NF}'` -if [ "$temp" != "$dir" ]; then - #cp_echo "CN: Found custom OutputDir value: $temp, not touching anything!" - db_set webalizer/directory "$temp" || true + webalizer_enable() { + return 1 + } fi -# Customise ReportTitle -temp=`pget $CONF ReportTitle |tail -n 1|perl -pe 's/(ReportTitle\s+?)(.*$)/$2/'` -if [ "$temp" = "$oldreporttitle" ]; then - pset $CONF ReportTitle "$reporttitle" - db_set webalizer/doc_title "$reporttitle" || true +webalizer_error() { + cp_echo "CN: Error while trying to enable $PKG configuration for Apache2." +} + +mv_conffile() +{ + local oldconffile="$1" + local newconffile="$2" + + rm -f $oldconffile.dpkg-remove + [ -e "$oldconffile" ] || return 0 + + cp_echo "CN: Preserving user changes to $newconffile (renamed from $oldconffile)." + mv -f "$newconffile" "$newconffile.dpkg-new" + mv -f "$oldconffile" "$newconffile" +} + + +mv_conffile /etc/apache2/conf.d/$PKG.conf /etc/apache2/conf-available/$PKG.conf + +if [ -f "$WCONF" ]; then + # Backup first. + if cp_check_and_backup "$WCONF"; then + cp_echo "CN: Old $WCONF saved as /var/backups/$WCONFBAK.bak." + fi + + # Check for OutputDir + temp=`awk 'tolower($1) == "outputdir" { print $2; }' $WCONF | tail -n 1` + if [ "$temp" != "$WDIR" ]; then + cp_echo "CN: Found custom OutputDir value: $temp" + db_set webalizer/directory "$temp" || true + customized=1 + fi + + # Check for ReportTitle + temp=`awk 'tolower($1) == "reporttitle" { for(i=2; i /dev/null + cp_echo "" + cp_echo "CN: Webalizer URL is http://`hostname -f`/stats/" + cp_echo "CN: User: admin" + cp_echo "CN: Password: $passwd" + cp_echo "" + cp_echo "CN: Use \"htpasswd -m $WHTPASSWD admin\" to change it." + else + cp_echo "CN: File $WHTPASSWD already exists." + fi +else + cp_echo "CN: Skipping file $WHTPASSWD" fi -# Send mail with informations -if [ ! -f $htpasswd ]; then - passwd=`makepasswd` - htpasswd -bc $htpasswd admin $passwd 2> /dev/null - cp_echo "" - cp_echo "CN: Webalizer URL is http://`hostname -f`/stats/" - cp_echo "CN: User: admin" - cp_echo "CN: Password: $passwd" - cp_echo "" - cp_echo "CN: Use \"htpasswd $htpasswd admin\" to change it." - cp_mail "webalizer-cn" +#DEBHELPER# + +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" + +exit 0