#!/bin/bash
clear
cd $HOME

arch=`uname -m`
version=Octane-2.2.0

# Check for ROOT UID
if [ $UID != 0 ]; then
  echo "### SORRY, you MUST BE ROOT or HAVE SUPER-USER LEVEL permissions in order to install the MaXX Interactive Desktop. Bailing out!"
  printf "\n"
  exit
fi

cd /tmp


# Download the Binaries
echo ">>> Downloading MaXXdesktop - Release $version - Binaries..."
printf "\n"


filename=MaXX-Desktop-v2.2.0-LINUX-x86_64-tar.gz
wget -c https://s3.ca-central-1.amazonaws.com/cdn.maxxinteractive.com/maxx-desktop-installer/$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 MaXXdesktop - Release $version - $(arch) files..."
tar zxf /tmp/$filename -C /opt/


# Setup Symlinks and configuration files

echo ">>> Setting MaXXdesktop - Release $version - SGI XCursors and IRIX icons"
printf "\n"
rm -rf /usr/share/icons/redSGI > /dev/null
rm -rf /usr/share/icons/IRIX > /dev/null


ln -sf /opt/MaXX/share/icons/* /usr/share/icons/ > /dev/null

#printf "\n"

echo ">>> Adding MaXXdesktop - Release $version - to your Display Manager's XSession menu"
rm -f /usr/share/xsessions/maxx.desktop
ln -sf /opt/MaXX/share/xsessions/maxx.desktop /usr/share/xsessions/maxx.desktop

echo ">> MaXXdesktop - Release $version - has been installed successfuly!"

echo ":)"
