#!/bin/bash
clear
cd $HOME

arch=`uname -m`
version=Indy-1.1.0

# Check for ROOT UID
if [ $UID != 0 ]; then
  echo "### SORRY, YOU MUST BE ROOT SUPER-USER IN ORDER TO INSTALL MaXX Desktop, Bailing out!"
  printf "\n"
  exit
fi

cd /tmp

# Download the NO-ARCH tar.gz file
echo ">>> Downloading MaXX Interactive Desktop - Release $version - NO-ARCH files..."
printf "\n"

filename=MaXX-$version-NO-ARCH.tar.gz
wget -c http://maxxinteractive.com/downloads/$version/UBUNTU/$filename
if [ ! -f /tmp/$filename ]; then
  echo "### SORRY, SOMETHING WENT WRONG WITH THE DOWNLOAD OF : $filename, Installation unsuccesful!"
  printf "\n"
  exit
fi

# Extracting NO-ARCH tar.gz file into /opt/
tar zxf MaXX-$version-NO-ARCH.tar.gz -C /opt/
echo ">>> Extracting MaXX Interactive Desktop - Release $version - NO-ARCH files..."
printf "\n"


# Download the Binaries .tar.gz file
echo ">>> Downloading MaXX Interactive Desktop - Release $version - Binaries files..."
printf "\n"

arch="x86_64"
filename=MaXX-$version-$arch.tar.gz
wget -c http://maxxinteractive.com/downloads/$version/UBUNTU/$filename
if [ ! -f /tmp/$filename ]; then
  echo "### SORRY, SOMETHING WENT WRONG WITH THE DOWNLOAD OF : $filename, installation unsuccesfull!"
  printf "\n"
  exit
fi

# Extracting NO-ARCH tar.gz file into /opt/
echo ">>> Extracting MaXX Interactive Desktop - Release $version - $(arch) files..."
tar zxf $filename -C /opt/


# Setup Symlinks and configuration files

echo ">>> Setting MaXX Interactive Desktop - Release $version - SGI XCursors and IRIX icons"
printf "\n"
ln -s /opt/MaXX/share/icons/* /usr/share/icons/

#echo ">>> Setting MaXX Interactive Desktop - Release $version - GTK Themes"
#printf "\n"
#ln -s /opt/MaXX/share/themes/* /usr/share/themes/

echo ">>> Adding MaXX Interactive Desktop - Release $version - to GDM's XSession menu"
ln -s /opt/MaXX/share/xsessions/maxx.desktop /usr/share/xsessions/maxx.desktop

echo ">> MaXX Interactive Desktop - Release $version - was installed successfuly!"

echo ":)"
