#!/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/puppybasic" ];then
  cp puppybasic /usr/bin/puppybasic
  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 PuppyBasic-traffic-viewer for root?"
RESULT=$?
echo $RESULT

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

  # put install here
  cd ~ 
  tar -xzvf "$mypath/resource/PuppyBasic-traffic-viewer.tgz"
  $XM -nearmouse "finished, starting program"
echo test
~/PuppyBasic-traffic-viewer/runPuppyBasic-traffic-viewer
  #exit 0
fi
fi


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

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

  # put install here
  cd ~ 
  tar -xzvf "$mypath/resource/PuppyBasic-traffic-viewer.tgz"
  $XM -nearmouse "finished, starting program"
~/PuppyBasic-traffic-viewer/runPuppyBasic-traffic-viewer&
  exit 0
fi
fi


exit 0



