#!/bin/bash

# Source debconf library.
. /usr/share/debconf/confmodule

# echo 'CacheDir: /var/cache/apt-cacher-ng
# 
# LogDir: /var/log/apt-cacher-ng
# 
# Port:2323
# 
# ReportPage: acng-report.html
# 
# ForceManaged: 0
# 
# ExTreshold: 4
# 
# PfilePattern = .*(.7z|.deb|.rpm|.exe|.dsc|.tar.gz.gpg|.tar.gz|.diff.gz|.diff.bz2|.jigdo|.template|changelog|copyright|.udeb|.diff/.*.gz|vmlinuz|initrd.gz|(Devel)?ReleaseAnnouncement(\?.*)?)$
# 
# LocalDirs: acng-doc /usr/share/doc/apt-cacher-ng
# ' > /etc/apt-cacher-ng/acng.conf


# Open port 2323 in the UCS firewall
ucr set security/packetfilter/package/m23/tcp/2323/all=ACCEPT
ucr set security/packetfilter/package/m23/udp/2323/all=ACCEPT
/etc/init.d/univention-firewall restart

# Get the PHP Apache module that is shipped with the newest Debian package
phpModPkg=$(dpkg --get-selections | grep php | grep -v '-' | grep -v deinstall$ | tr -d '[:blank:]' | sed 's/install$//g' | egrep '[0-9]' | sort -n | tail -1)

# Get the enabled PHP Apache module
phpModEnabled="$(ls /etc/apache2/mods-enabled/php*.load | sed -e 's#.*/##' -e 's#\.load##')"

# Activate the package's PHP Apache module, if not active
if [ "$phpModPkg" ] && [ "$phpModEnabled" ] && [ $phpModEnabled != $phpModPkg ]
then
	a2dismod $phpModEnabled
	a2enmod $phpModPkg
	/etc/init.d/apache2 restart
fi

# /etc/init.d/apt-cacher-ng restart

db_stop
