#!/bin/csh -f

if ($#argv == 0) then
   echo "Usage: qrl <rlogin args>"
   exit 1
endif

set remote_host = $1

if ($?DISPLAY) xhost $remote_host

set krb_realm
set i = 1
set argc = $#argv
@ argc --
while ($i <= $argc)
   if ($argv[$i] == "-k") then
      @ i++
      set krb_realm = "-k $argv[$i]"
      set i = $argc
      @ i++
   endif
   @ i++
end

unset ok
set count = 0
while ((! $?ok) && ($count != 3))
   rkinit $remote_host $krb_realm
   if ($status == 0) then
      set ok
   else
      @ count++
   endif
end

if (! $?ok) then
   if (`ask -yn 5 n "rkinit failed; rlogin anyway?"`) set ok 
endif

if (! $?ok) exit 1

rsh $remote_host $krb_realm /bin/athena/attach $user 
rlogin $argv -t $term@$host 
exit 0
