#!/bin/bash

# Here is a suitable bash_login to drop into /home/ubuntu/.bash_login
# Ensures this is an interactive ssh login, then asks the user if they
# want to enable NX functionality.

flagfile=~/.nx_setup_done
setupscript=setupnx.sh
cont=yes

# Do I go ahead?
[ -e "$flagfile" ] && cont=no
[ -n "$SSH_CONNECTION" ] || cont=no
tty -s || cont=no

if [ "$cont" = yes ] ; then
cat <<BLURB 

CloudBioLinux comes with FreeNX server to provide a fast remote
desktop on your cloud server instance.  Do you wish to configure this now?

  y = Yes
  n = No, but ask me again next time.
  x = No, and do not ask again.
BLURB

read -n 1 -p $'\n [ ]\b\b' answer
answer=`echo "$answer" | tr 'YNX' 'ynx'`
echo

if [ "$answer" = y ] ; then
    #Setupscript needs to be executable already.
    sudo "$setupscript" $USER && touch "$flagfile"
elif [ "$answer" = x ] ; then
    touch "$flagfile"
    echo "To initiate setup manually, type 'sudo $setupscript <username>'."
else
    echo "Quitting."   
fi
fi
