#!/bin/sh

# Mount filesystems and configure apt
mount $1 /target
mount --bind /proc /target/proc
mount --bind /dev /target/dev
mount --bind /dev/pts /target/dev/pts
mount --bind /cdrom /target/cdrom
chroot /target apt-cdrom add
sed -i 's/#deb cdrom/deb cdrom/g' /target/etc/apt/sources.list

# Close down if dpkg is running on the system
if [ "`chroot /target ps aux | grep dpkg | wc -l`" -gt "1" ]; then
  zenity --info --title "Operation in Progress" --text "Another process is currently installing software, please try again later."
  exit
fi

chooseinterface() {
  CONFIRM=$(zenity --question --ok-label=Continue --cancel-label=Cancel "Edubuntu Netbook Installation" --text="This will enable the netbook interface on the installed system.")
  if [ "$?" != "0" ]; then
    exit
  fi
}

configure() {
chroot /target apt-get -y install ubuntu-netbook | zenity --auto-kill --auto-close --title "Configuring Netbook Interface" --text \
    "Installing Netbook Interface, this usually takes about 3 minutes." --progress --pulsate
  # Unmount filesystems
  umount -l /target/dev/pts
  umount -l /target/dev
  umount -l /target/proc
  umount -l /target/cdrom
  umount -l /target
  zenity --info --title "Finished" --text \
    "Installation complete."
  rm /home/ubuntu/Desktop/netbook.desktop
}

chooseinterface
configure
