alternc-awstats.postinst 2.96 KB
Newer Older
1
#!/bin/bash -e
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

# Uses debconf
. /usr/share/debconf/confmodule

LOGAPACHE="/etc/alternc/awstats.log.alternc.conf"
APACHEROTATE="/etc/logrotate.d/apache2"

logrotate_apache() {
        cp -a -f $APACHEROTATE $APACHEROTATE.tmp
        sed -e 's/create 640 root adm/create 640 root www-data/' < $APACHEROTATE > $APACHEROTATE.tmp
        mv -f $APACHEROTATE.tmp $APACHEROTATE
}

case "$1" in
  configure)

    # Then, configure the quota for "aws"
    db_get alternc-awstats/default_quota_value || true
    /usr/lib/alternc/quota_init aws $RET

    db_stop

    echo "Installing mysql table"
    mysql --defaults-file=/etc/alternc/my.cnf \
	</usr/share/alternc/awstats.sql || true

    # Refresh apache configuration
    # configure /etc/alternc/templates/apache/httpd.conf
    # configure /etc/alternc/templates/apache-ssl/httpd.conf

    if [ -x /usr/sbin/apache2 ]; then
        if [ ! -h /etc/apache2/conf.d/alterncawstats.conf ]; then
            ln -sf /etc/alternc/alterncawstats.conf \
                /etc/apache2/conf.d/alterncawstats.conf
        fi
        # build awstats.log.alternc.conf if it does not exist
        if [ ! -f $LOGAPACHE ]; then
            cat > $LOGAPACHE <<EOF
#LogFile directive isn't important here :
#Awstats is launched with the good "LogFile" directive when called
LogFile="/var/log/apache2/access.log"
LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %other %virtualname"
EOF
45 46
	fi
        chown alterncpanel:root $LOGAPACHE
Axel ROGER's avatar
Axel ROGER committed
47
        chmod 644 $LOGAPACHE
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    fi

    if [ -x /usr/sbin/apache-ssl ]; then
      if [ ! -h /etc/apache-ssl/conf.d/alterncawstats.conf ]; then
          ln -sf /etc/alternc/alterncawstats.conf \
              /etc/apache-ssl/conf.d/alterncawstats.conf
      fi
    fi

    logrotate_apache

    # Add htpasswd :
    touch /etc/alternc/awstats.htpasswd
    chown alterncpanel /etc/alternc/awstats.htpasswd /etc/awstats
    chmod 640 /etc/alternc/awstats.htpasswd
    chmod 755 /etc/awstats
    mkdir -p /var/cache/awstats
Axel ROGER's avatar
Axel ROGER committed
65 66
    chown alterncpanel:www-data /var/cache/awstats
    chmod 770 /var/cache/awstats
67 68

    # Update rights on previous user's awstats configuration files
Axel ROGER's avatar
Axel ROGER committed
69
    chown alterncpanel:root /etc/awstats/awstats.*.conf > /dev/null 2>&1 || true
70

71 72 73 74
    echo -e "\033[31m**********************************************"
    echo "*  ALTERNC-AWSTATS   ACTION REQUESTED        *"
    echo "* If you add an autorized user called 'admin'*"
    echo "* in statistics section, he will access      *"
75
    echo "*        every stats of every users          *"
76 77
    echo "*                                            *"
    echo "* Please run alternc.install to fully deploy *"
78
    echo "**********************************************"
79
    echo -e "\033[0m"
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    ;;

  abort-upgrade|abort-remove|abort-deconfigure)
    ;;

  *)
    echo "postinst called with unknown argument \`$1'" >&2
    exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#

# vim: et sw=4