#!/bin/tcsh

set what="$1"
set where="$2"

set destlist=( type@osf1 \
alpha=/afs/psi.ch/project/sinq/tru64/stow/tecs/bin/ \
type@linux \
slinux=/afs/psi.ch/project/sinq/sl-linux/stow/tecs/bin/ \
linux=/afs/psi.ch/project/sinq/linux/stow/tecs/bin/ \
amor@amor:tecs/ focus@focus:tecs/ trics@trics:tecs/ \
tasp@tasp:tecs/ dmc@dmc:tecs/ hrpt@hrpt:tecs/ \
morpheus@morpheus:tecs/ sans@sans:tecs/ sans2@sans2:tecs/ \
type@darwin \
macosx=/afs/psi.ch/project/sinq/mac_os/stow/tecs/bin/ \
admin@ldmprep1:bin/ admin@ldmprep2:bin/ \
)

set dests=""
set destl=""
foreach dest ($destlist)
  set ext="${dest:s/=/ /}"
  set ext=($ext)
  if ("$ext" != "$dest") then
    set dest="$ext[2]"
    set d="$ext[1]"
  else
    set d=""
  endif
  set ext=${dest:s/@/ /}
  set ext=($ext) 
  if ("$ext[1]" == type) then
    set type=$ext[2]
  else
    if ("$d" == "") set d=$ext[1]
    if ($?type) then
      set t_$d=$type
    else
      echo "type undefined"
      exit
    endif
    set d_$d=$dest
    set dests=($dests $d)
  endif
end

set items=(TecsServer TecsClient six)

echo ""
echo "  all $items"
echo -n "distribute what: "
if ("$what" == "") then
  set what=$<
endif
if ($what == all) then
  set what=($items)
endif

echo ""
echo "  all $dests"
echo "distribute where: "
if ("$where" == "") then
  set where=$<
endif
if ($where == all) then
  set where=($dests)
endif

set this=${0:h}
if ($this == $0) then
  set this=./
endif
cd $this

#set obj=../../obj/$SICS_VERSION/psi/tecs
foreach dest ($where)
  alias get 'set d=$'"d_$dest;"'set t=$'"t_$dest"
  get
  foreach item ($what)
    if ("$t" == "$OSTYPE") then
       echo $item to $d
       rsync -e ssh -vt $item $d
    endif
  end
end

