#!/bin/csh -f
# This postinstall script echoes the values of the available
# arguments and environmental variables.
#

echo "Start postinstall script"
echo ""

set InstDest = $argv[2]

set vapor_root = $InstDest/VAPOR3/VAPOR.app
set bindir = $vapor_root/Contents/MacOS
set lib_search_dirs = $bindir
set mandir = $vapor_root/Contents/share/man
set sharedir = $vapor_root/Contents/share

set sedcmd = sed
if (-e /bin/sed) set sedcmd = /bin/sed
if (-e /usr/bin/sed) set sedcmd = /usr/bin/sed


#
# Edit the user environment setup scripts
#
set old0 = 'set[    ][  ]*root[     ][  ]*=.*$'
set new0 = "set root = $vapor_root"
set old1 = 'set[    ][  ]*lib_search_dirs[  ][  ]*=.*$'
set new1 = "set lib_search_dirs = $lib_search_dirs"
set old2 = 'set[    ][  ]*bindir[   ][  ]*=.*$'
set new2 = "set bindir = $bindir"
set old3 = 'set[    ][  ]*mandir[   ][  ]*=.*$'
set new3 = "set mandir = $mandir"
set old4 = 'set[    ][  ]*sharedir[   ][  ]*=.*$'
set new4 = "set sharedir = $sharedir"
$sedcmd -e "s#$old0#$new0#" -e "s#$old1#$new1#"  -e "s#$old2#$new2#"  -e "s#$old3#$new3#" -e "s#$old4#$new4#" < $bindir/vapor-setup.csh >! $bindir/vapor-setup.tmp
/bin/mv $bindir/vapor-setup.tmp $bindir/vapor-setup.csh


set old0 = 'root=.*$'
set new0 = "root=$vapor_root"
set old1 = 'lib_search_dirs=.*$'
set new1 = "lib_search_dirs=$lib_search_dirs"
set old2 = 'bindir=.*$'
set new2 = "bindir=$bindir"
set old3 = 'mandir=.*$'
set new3 = "mandir=$mandir"
set old4 = 'sharedir=.*$'
set new4 = "sharedir=$sharedir"
$sedcmd -e "s#$old0#$new0#" -e "s#$old1#$new1#" -e "s#$old2#$new2#" -e "s#$old3#$new3#" -e "s#$old4#$new4#" < $bindir/vapor-setup.sh >! $bindir/vapor-setup.tmp
/bin/mv $bindir/vapor-setup.tmp $bindir/vapor-setup.sh

echo "Finish postinstall script"
exit 0
