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

if [ -f /etc/debian-edu/config ] ; then
    . /etc/debian-edu/config
fi

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

# Enable all relevant munin plugins now the machine is completely
# configured.  Some of the plugins are not enabled when munin-node is
# installed, because their service is installed after munin-node.
if [ -x /usr/sbin/munin-node-configure ] ; then
    /usr/sbin/munin-node-configure -shell | sh || true
    invoke-rc.d munin-node restart || true
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

# Update PXE setup on Main-server with proxy values set in environment
# to make sure the proxy values are passed on to clients.  When set up
# from cfengine, the proxy values are not passed on and missing from
# /etc/debian-edu/www/debian-edu-install.dat
if echo "$PROFILE" | grep -q Main-Server && \
    [ -x /usr/sbin/debian-edu-pxeinstall ] ; then
    if [ -e /etc/environment ] ; then
	. /etc/environment
	export http_proxy ftp_proxy
    fi
    /usr/sbin/debian-edu-pxeinstall
fi

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