#! /bin/csh -f 
# Last edited on 2008-02-04 20:15:10 by stolfi

set usage = "cd WORKDIR; $0"

# Cria links simb'olicos para fontes em ~mc726/PUB/2001-1/now/
# Execute este script no seu diret'orio de trabalho de MC726

set path = ( /bin /usr/bin ${path} )

if ( $#argv != 0 ) then
  echo "\! bad arguments"
  echo "  usage: ${usage}"; exit 1
endif

set repository = "/home/spec/mc726/PUB/2001-1/now"
set bindir = "/home/spec/mc726/PUB/2001-1/bin"

set packages = ( `${bindir}/list-shared-packages` )
set files = ( `${bindir}/list-shared-files` )

echo "Creating local package directories"
echo " "
foreach pck ( ${packages} )
  if ( { test -d ${pck} } ) then
    echo "# package ${pck} exists - ok."
  else if ( -r ${pck} ) then
    echo "\! ${pck} already exists and is not a directory."; exit 1
  else 
    echo "creating directory ${pck}"
    mkdir ${pck}
  endif
end

echo "Creating symbolic links to shared sources in ${repository}"
echo " "
foreach f ( ${files} )
  set pck = "${f:h}"
  if ( { test -L ${f} } ) then
    echo "# ${f} already exists (symbolic link)."
  else if ( -r ${f} ) then
    echo "# ${f} already exists (LOCAL file)."
  else 
    echo "link ${f} -> ${repository}/${f}"
    ( cd ${pck} && ln -s ${repository}/${f} )
  endif
end

echo " "
echo "To make a file locally editable, delete the symbolic link and"
echo "  copy the actual file to this directory."
echo " "
echo "To use the shared copy of a file, delete the local copy (if any)"
echo "  and run this script again, in the same directory."

  
