#!/bin/sh
# NOTE: Actual install (ltsp-update-sshkeys + ltsp-update-image +
# ltsp-update kernsl) is done through the ltsp-server package.

. /usr/share/debconf/confmodule

db_get ubiquity/edubuntu-addon_ltsp_install
INSTALL="$RET"
db_get ubiquity/edubuntu-addon_ltsp_interface
INTERFACE="$RET"

if [ "$INSTALL" = "true" ]; then
    # Install the required packages
    apt-install ltsp-server-standalone

    # Copy the chroot
    mkdir -p /target/opt/ltsp/ /opt/ltsp/i386
    mount /cdrom/ltsp/i386.img /opt/ltsp/i386 -o loop
    cp -r /opt/ltsp/i386 /target/opt/ltsp

    # Configuring network
    cat >> /target/etc/network/interfaces <<EOF
auto $INTERFACE
iface $INTERFACE inet static
  address 192.168.0.254
  netmask 255.255.255.0
EOF

    # Let ltsp-server's postinst know what to do
    touch /target/etc/edubuntu_ltsp_install

    # Cleaning up
    umount -l /opt/ltsp/i386
fi
