#! /bin/sh

set -e

. /usr/share/debconf/confmodule

if [ "configure" = "$1" ] && [ -z "$2" ]; then 
    cat > /etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
EOF
    
fi

if [ ! -f /config-done ]; then
	oem-config-prepare --quiet
	touch /config-done
fi

# Ew
if [ -f /etc/X11/Xwrapper.config ]; then
    sed -i -e 's/allowed_users=.*/allowed_users=anybody/' /etc/X11/Xwrapper.config
fi

# Double ew. Hack to work around unionfs bug/feature.
if [ ! -L /squashmnt ]; then
	ln -s / /squashmnt
fi

[ -e "/etc/X11/xorg.conf.netbook" ] && mv /etc/X11/xorg.conf.netbook /etc/X11/xorg.conf

# We do not want to allow access to sound devices if user is not part of the
# audio group
polkit-action --set-defaults-active org.freedesktop.hal.device-access.sound no

# Explicitly specify modules to load during early boot as this is the fastest
# way to load them
grep intel_agp /etc/modules > /dev/null 2>&1 || echo "intel_agp" >> /etc/modules
grep drm /etc/modules > /dev/null 2>&1 || echo "drm" >> /etc/modules
grep psmouse /etc/modules > /dev/null 2>&1 || echo "psmouse" >> /etc/modules
grep r8101 /etc/modules > /dev/null 2>&1 || echo "r8101" >> /etc/modules
grep serio_raw /etc/modules > /dev/null 2>&1 || echo "serio_raw" >> /etc/modules
grep iTCO_vendor_support /etc/modules > /dev/null 2>&1 || echo "iTCO_vendor_support" >> /etc/modules
grep iTCO_wdt /etc/modules > /dev/null 2>&1 || echo "iTCO_wdt" >> /etc/modules

# Disable links for rc2.d services that we now explicitly start with latebootcmds
# script. Note that the packages that install the rc2.d links must be added to the
# control file's Depends field to ensure the link is properly removed.
if [ -e /etc/rc2.d/S89anacron ]; then
        mv /etc/rc2.d/S89anacron /etc/rc2.d/K89anacron > /dev/null 2>&1
fi

if [ -e /etc/rc2.d/S20apport ]; then
        mv /etc/rc2.d/S20apport /etc/rc2.d/K20apport > /dev/null 2>&1
fi

if [ -e /etc/rc2.d/S20cupsys ]; then
        mv /etc/rc2.d/S20cupsys /etc/rc2.d/K20cupsys  > /dev/null 2>&1
fi

if [ -e /etc/rc2.d/S25pulseaudio ]; then
        mv /etc/rc2.d/S25pulseaudio /etc/rc2.d/K25pulseaudio > /dev/null 2>&1
fi

# Disable some upstart events
if [ -e /etc/event.d/tty3 ]; then
        update-upstart disable tty3
fi

if [ -e /etc/event.d/tty4 ]; then
        update-upstart disable tty4
fi

if [ -e /etc/event.d/tty5 ]; then
        update-upstart disable tty5
fi

if [ -e /etc/event.d/tty6 ]; then
        update-upstart disable tty6
fi

#DEBHELPER#

