#!/bin/sh
 
chooseinterface() {
  INTERFACE=$(zenity --title "Trisquel Live LTSP" --entry --text="This script will set up a Live Terminal Server. Please select an\n interface it should start on, for example 'eth0', 'eth1', etc.\nEnter 'none' if you have pre-configured networking." --entry-text="eth1")
  if [ "$?" != "0" ]; then
    exit
  fi
  confirmation
}
 
confirmation() {
  if [ "`LANG=C ifconfig $INTERFACE | grep 'inet addr' | wc -l`" = "1" ]; then
    CONFIRMATION=`zenity --question --title "Please confirm" --text="The interface you have selected is already configured for another network. Are you sure you want to run LTSP on this interface?" --ok-label="Yes" --cancel-label="No"`
    if [ "$?" != "0" ]; then
      chooseinterface
    fi
  fi
}
 
configure() {
  if [ ! $INTERFACE = "none" ]; then
    ifconfig $INTERFACE 192.168.0.254
  fi
  ltsp-livecd | zenity --title "Configuring LTSP" --text \
    "Configuring LTSP, this usually takes about 2 minutes." --progress --pulsate
  zenity --info --title "Finished" --text \
    "LTSP Live CD Services should now be available.\nTo end it, simply reboot."
}
 
chooseinterface
configure
