#!/bin/sh
#
# This script is called by /etc/init.d/xdebian-edu-firstboot in
# debian-edu-install on the first boot after installation.

logger -t debian-edu-config "Executing run-at-firstboot script."

# fix for skolelinux bug #1355:
# make sure /opt/ltsp/*/etc/ssh/ssh_known_hosts is created
if [ -x /usr/sbin/ltsp-update-sshkeys ]; then
    ltsp-update-sshkeys
fi

# Make sure the LTSP kernels are updated too, in case the initrd was
# upgraded during installation (for example for removing usplash)
if [ -x /usr/sbin/ltsp-update-kernels ]; then
    ltsp-update-kernels
fi

# Do readahead profiling on the next boot, and not on the initial
# boot, to avoid incuding the test in the readahead profiling.
if [ -x /sbin/readahead-list ] ; then
    touch /etc/readahead/profile-once
fi

# Update sitesummary and munin configuration quickly
if [ -x /usr/sbin/sitesummary-client ] ; then
    sitesummary-client
    if [ -x /etc/cron.daily/sitesummary ] ; then
	/etc/cron.daily/sitesummary

	# Update the munin web pages too
	if [ -x /usr/bin/munin-cron ] ; then
	    su munin -s /usr/bin/munin-cron
	fi
    fi
fi

# Make sure powerdns listen to all the used interfaces, to make sure
# replies have the correct source address.  Solves Skolelinux bug
# #1441.
pdnscfg=/etc/powerdns/pdns.d/pdns-debian-edu-if.conf
if [ -x /etc/init.d/pdns ] && [ ! -f $pdnscfg ] ; then
    (
	LC_ALL=C
	export LC_ALL
	iplist="$(ip addr list | awk '/ inet / { print $2}' | cut -d/ -f1)"
	echo local-address=$iplist | sed 's/ /, /g'

	netlist="$(ip addr|grep 'inet '|awk '{print $2}')"
	echo '#ACL that allow recursion from this server, and the network.'
	echo allow-recursion=$netlist | sed 's/ /, /g'
    ) > $pdnscfg
    chmod 644 $pdnscfg
    invoke-rc.d pdns-recursor force-reload
    invoke-rc.d pdns reload
fi

if [ -x /usr/sbin/etckeeper ] ; then
    etckeeper commit "End of first boot" > /dev/null 2>&1 || true
fi
