#!/bin/csh -f
# check if user is root
id | fgrep -sv root 
set i_am_root =  $status

echo GIG 3DGO installation script
echo ""

set allok         = 'n'
while ( "$allok" == 'n' )
  set do_gig = $i_am_root
  set do_demo = 0
  set do_tutor = 0
  set do_map = 0
  echo ""
  if ( $do_gig ) then
    echo You are logged in as super user.
    echo "(If you only want to add demo, tutorial or mapfactory files to an existing"
    echo "installation, login as the gig user and rerun this script)"
  else
    echo You are not logged in as super user, you can only add demo, tutorial 
    echo or mapfactory files to an existing installation.
    echo "(If you want to install gig login in as root and rerun this script)"
  endif

  echo ""
  echo 'Do you want to install the tutorial? (yes/no/quit)'
  set ok = $<
  set ok = `echo "$ok" | awk ' \\\
    { \\\
    a = substr( $0, 1, 1);\\\
    if ((a == "n") || (a == "N")) print "n"; else {\\\
    if ((a == "q") || (a == "Q")) print "q"; else print "y" }\\\
    }'`

  if ($ok == 'q') then
    goto aborted
  endif
  if ($ok == 'y') then
    set do_tutor=1
  endif
  echo 'Do you want to install the demo images? (yes/no/quit)'
  set ok = $<
  set ok = `echo "$ok" | awk ' \\\
    { \\\
    a = substr( $0, 1, 1);\\\
    if ((a == "n") || (a == "N")) print "n"; else {\\\
    if ((a == "q") || (a == "Q")) print "q"; else print "y" }\\\
    }'`

  if ($ok == 'q') then
    goto aborted
  endif
  if ($ok == 'y') then
    set do_demo=1
  endif

  echo 'Do you want to install the mapfactory files? (yes/no/quit)'
  set ok = $<
  set ok = `echo "$ok" | awk ' \\\
    { \\\
    a = substr( $0, 1, 1);\\\
    if ((a == "n") || (a == "N")) print "n"; else {\\\
    if ((a == "q") || (a == "Q")) print "q"; else print "y" }\\\
    }'`

  if ($ok == 'q') then
    goto aborted
  endif
  if ($ok == 'y') then
    set do_map=1
  endif

  if ( $do_gig | $do_tutor | $do_demo | $do_map ) then
    goto checkall
  else
    echo nothing selected
    exit
  endif
  checkall:

set stuff=
if ($do_gig) then
  set stuff=($stuff GIG 3DGO)
endif
if ($do_tutor) then
  set stuff=($stuff tutorial)
endif
if ($do_demo) then
  set stuff=($stuff demo)
endif
if ($do_map) then
  set stuff=($stuff mapfactory)
endif

echo "installing: $stuff"
echo "are you sure? (yes/no/quit)"

  set allok = $<
  set allok = `echo "$allok" | awk ' \\\
    { \\\
    a = substr( $0, 1, 1);\\\
    if ((a == "n") || (a == "N")) print "n"; else {\\\
    if ((a == "q") || (a == "Q")) print "q"; else print "y" }\\\
    }'`

  if ($allok == 'q') then
    goto aborted
  endif
end

#now call installation if do_gig is set then do it all as superuser
if ( $do_gig) then
  set doit=./gig.ins
  if ($do_tutor) then
    set doit = ($doit -i tutor)
  endif
  if ($do_demo) then
    set doit = ($doit -i demo)
  endif
  if ($do_map) then
    set doit = ($doit -i map)
  endif
  /bin/csh $doit
  exit 0
endif

if ($do_tutor) then
  /bin/csh $cwd/tutor.ins
endif
if ($do_demo) then
  /bin/csh $cwd/demo.ins
endif
if ($do_map) then
  /bin/csh $cwd/map.ins
endif


exit 0

aborted:
    echo ""
    echo "installation aborted"
    exit 1
