#!/bin/sh

### ensure, we are in the correct folder

ROOTCHECK=0
ALLTHERE=1

mypath=`echo $0|sed 's/[^/]*$//'|sed 's/\/$//'`
if [ "$mypath" = "." ]; then
  mypath=`pwd`
fi
cd $mypath/resource


XM=`which xmessage`

if [ "$XM" = "" ];then
  XM=./xmessage
  cp xmessage /usr/X11R6/bin/xmessage
  ALLTHERE=0
fi
XD=`which Xdialog`

if [ "$XD" = "" ];then
  cp Xdialog /usr/X11R6/bin/Xdialog
  ALLTHERE=0
fi

if [ ! -f "/usr/bin/wxbasicscript" ];then
  cp wxbasicscript /usr/bin/wxbasicscript
  ALLTHERE=0
fi

GD=`which gtkdialog2`
if [ "$GD" = "" ];then
  cp gtkdialog2 /usr/bin/gtkdialog2
  ALLTHERE=0
fi

if [ ! -d "/usr/lib/wxbasicscript" ];then
  mkdir /usr/lib/wxbasicscript
  ALLTHERE=0
fi

if [ ! -f "/usr/lib/wxbasicscript/basefunctions.inc" ];then
  cp basefunctions.inc /usr/lib/wxbasicscript/basefunctions.inc
  ALLTHERE=0
fi


if [ "$ALLTHERE" = "0" ];then
if [  `echo ~` != "/root" ];then
  echo "You must be root to install the libraries - exiting"
  $XM -nearmouse "You must be root to install the libraries - exiting"
  exit 1
fi
fi

if [  `echo ~` = "/root" ];then
$XM -nearmouse -buttons yes,no "Install autostartmanager for root?"
RESULT=$?
echo $RESULT

if [ "$RESULT" = "101" ];then
#$XM -nearmouse $RESULT

  # put install here
  cd ~ 
  tar -xzvf "$mypath/resource/autostartmanager.tgz"
  $XM -nearmouse "finished, starting program"
  ~/autostart-manager/autostart-manager
  exit
fi
fi


if [  `echo ~` != "/root" ];then
$XM -nearmouse -buttons yes,no "Install autostartmanager?"
RESULT=$?
echo $RESULT

if [ "$RESULT" = "101" ];then
#$XM -nearmouse $RESULT

  # put install here
  cd ~ 
  tar -xzvf "$mypath/resource/autostartmanager.tgz"
  $XM -nearmouse "finished, starting program"
  ~/autostart-manager/autostart-manager
  exit
fi
fi


exit



