#!/bin/bash

# ....
# Main entry point.

TYPE="dpkg"
FILE=""
SSO_INSTALLED="0"

while [ $# -gt 0 ]; do
  if [ "x$1" = "x--sso_installed" ]; then
    SSO_INSTALLED="1"; shift 1
  elif [ "x$1" = "x--type" ]; then
    TYPE=$2; shift 2
  elif [ "x$1" = "x--file" ]; then
    FILE=$2; shift 2
  fi
done

if [ -n ${FILE} ]; then
  if [ "x${TYPE}" = "xdpkg" ]; then
    pkexec dpkg -i ${FILE}
  elif [ "x${TYPE}" = "xrpm" ]; then
    pkexec rpm -U ${FILE}
  elif [ "x${TYPE}" = "xtar" ]; then
    gksudo /opt/2X/Client/scripts/uninstall.sh
    cd /
    gksudo tar jxvf ${FILE}
    if [ "x${SSO_INSTALLED}" = "x1" ]; then
      gksudo /opt/2X/Client/scripts/install.sh --update --sso_installed
    else
      gksudo /opt/2X/Client/scripts/install.sh --update
    fi
  fi
fi

/opt/2X/Client/bin/2XClient &

