#! /usr/bin/ksh
#######################################################################
# rt_setup 
rt_www_rev='2.30'
# 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_edit_control\n"
print -- '--------------------------------------------------------------'
ed ${rt_home}/rt_edit_control <<%%
g+RT_HOME="+s+=.*+="${rt_home}"
w
q
%%

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

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

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

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

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

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

ed ${rt_home}/bin/rt_graph_update.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/gen_graph\n"
print -- '--------------------------------------------------------------'

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

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

ed ${rt_home}/cgi-bin/quick_view <<%%
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/get_stats_from_h2o.py\n"
print -- '--------------------------------------------------------------'

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

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

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

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