#!/bin/tcsh

cd $HOME_EXEC_BASE

if ($1 == "") then
	set availv=`ls -d V-*`
	echo "Available versions are:"
	foreach version ($availv)
	   set name="$version"
	   if ( -l $name ) then 
	      set symlink=`ls -l $name | cut -d\> -f2-` 
	      set local="(symbolic link to $symlink)"
	   else
	      set local=" "
           endif
	   echo "  ---> $name $local" 
	end
	set current=`ls -l current | cut -d\> -f2-`
	echo "Current installed version is: $current"
	echo "Use 'install_version <num_version>' to install available version <num_version>" 
	echo "<num_version> could be DEV"
	exit(1)
endif

if ( $1 != "DEV" ) then
    setenv DDEST V-$1
else
    setenv DDEST DEV
endif

if ( -l $DDEST ) then
	set target=`ls -l $DDEST | cut -d\> -f2-`
	if ( ! -d $target ) then
		echo "ERROR : version <$DDEST> is a symbolic to <$target>, which is unreachable (networked version??)"
	exit(1)
	endif
endif 

if ( ! -d $DDEST ) then
	echo "ERROR : version $DDEST does not exist"
	exit (1)
endif

# should remove an eventual existing link
# since GNU ln would create a link 'inside' current if
# not removed
\rm -f current
\ln -s $DDEST current
echo "Post-installing Version $DDEST..."

echo "$HOME_EXEC_BASE is ready for use in $DDEST"


