#! /usr/bin/ksh
#######################################################################
# rt_setup rev 1.0
# Feb, 1997
# by Dave Briar and Daryll Pope
#######################################################################
if [[ -z $1 ]] then
  print '\n   Usage: rt_setup.ksh <unix_path_to_RT_HOME>\n'
  exit
fi

 rt_home=$1

 print -- '\n----------------------------'
 print -- '   rt_setup.ksh -- rev 1.0'
 print -- '----------------------------'
 print -- "\nSetting RT_HOME to $rt_home"
 print -n '\n  Is this correct (Y/N)?'
 read resp

if [[ $resp = [nN]* ]]
   then print -- '-- Please start over -- exiting'
   exit
fi

# -- Check if directory exists
if [[ ! -d $rt_home ]]
   then print  ''
   print -- "-- Directory $rt_home does not seem to be a valid directory"
   print -- '-- Please check:  exiting'
   exit
fi

# -- Set system environment variable TMPDIR to RT_HOME
TMPDIR=${rt_home}

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/rt.py\n"
print -- '--------------------------------------------------------------'
ed ${rt_home}/rt.py <<%%
g+RT_HOME="+s+=.*+="${rt_home}"
w
q
%%

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/run_rt_updates.py\n"
print -- '--------------------------------------------------------------'
ed ${rt_home}/run_rt_updates.py <<%%
g+RT_HOME=+s+=.*+="${rt_home}"
w
q
%%

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/rt_prepare_data.py\n"
print -- '--------------------------------------------------------------'

ed ${rt_home}/rt_prepare_data.py <<%%
g+RT_HOME=+s+=.*+="${rt_home}"
w
q
%%

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/cgi-bin/gen_stn_pg\n"
print -- '--------------------------------------------------------------'

ed ${rt_home}/cgi-bin/gen_stn_pg <<%%
g+RT_HOME=+s+=.*+="${rt_home}"
w
q
%%

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/cgi-bin/gen_tbl_pg\n"
print -- '--------------------------------------------------------------'

ed ${rt_home}/cgi-bin/gen_tbl_pg <<%%
g+RT_HOME=+s+=.*+="${rt_home}"
w
q
%%

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/cgi-bin/rts_gen_station_pg.py\n"
print -- '--------------------------------------------------------------'

ed ${rt_home}/cgi-bin/rts_gen_station_pg.py <<%%
g+RT_HOME=+s+=.*+="${rt_home}"
w
q
%%

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/util/split_textlist.py\n"
print -- '--------------------------------------------------------------'

ed ${rt_home}/util/split_textlist.py <<%%
g+RT_HOME=+s+=.*+="${rt_home}"
w
q
%%

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/util/compute_stats.py\n"
print -- '--------------------------------------------------------------'

ed ${rt_home}/util/compute_stats.py <<%%
g+RT_HOME=+s+=.*+="${rt_home}"
w
q
%%

# ----------------------------------------------------------------------
print -n "\n\nSetting RT_HOME in     ${rt_home}/graph/rt_graph_update.py\n"
print -- '--------------------------------------------------------------'

ed ${rt_home}/graph/rt_graph_update.py <<%%
g+RT_HOME=+s+=.*+="${rt_home}"
w
q
%%

print '\n\n---- Finished ----\n'

# read resp
# if [[ $resp = [nN]* ]]
#    then print -- '-- Please start over -- exiting'
#    exit
# fi