#!/bin/bash
############################################################################
# Author: Rick Ogden
# Copyright: Rick Ogden 2009
# License: GNU General Public License
# Version: 1.2
# Name: Ubuntu FreeNX Installer
# Description: This adds the freenx repository, installs freenx with the
# default settings, and then downloads and installs NX Client.
############################################################################
lsb=$(lsb_release -c)
version=${lsb:10}
arch=$(dpkg --print-architecture)
nxcloc="http://64.34.161.181/download/3.4.0/Linux/"
cwd=$(pwd)
if [ $arch == "i386" ]; then
	nxcfile="nxclient_3.4.0-7_i386.deb"
else
	nxcfile="nxclient_3.4.0-7_x86_64.deb"
fi

if [ ! -f "/etc/apt/sources.list.d/freenx.sources.list" ]; then
	touch /etc/apt/sources.list.d/freenx.sources.list
	echo "deb http://ppa.launchpad.net/freenx-team/ppa/ubuntu $version main" >> /etc/apt/sources.list.d/freenx.sources.list
	echo "deb-src http://ppa.launchpad.net/freenx-team/ppa/ubuntu $version main" >> /etc/apt/sources.list.d/freenx.sources.list
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2a8e3034d018a4ce
fi
apt-get update
aptitude install --assume-yes openssh-server freenx
/usr/lib/nx/nxsetup --install --setup-nomachine-key
cd /tmp
wget "$nxcloc$nxcfile"
dpkg -i $nxcfile
rm $nxcfile
cd $cwd

