#!/usr/local/bin/bash
#
# oshadow - create a shadow build tree from a given source.  This is like
# lndir but we just make the directories - no symbolic links.
#

if [ $# -eq 1 ]; then

  from=$1

else

  if [ -r config/sources ]; then
    defaultfrom=`head -1 config/sources`
  fi

  echo -n "Create shadow of ? [$defaultfrom] "

  read from

  if [ "$from" = "" ]; then
    from=$defaultfrom
  fi
fi

if [ ! -d "$from" ]; then
  echo "Error: $from is not a directory"
  exit 1
fi

shadow() {
  from=$1
  for dir in `ls -af $from`; do
    if [ -d $from/$dir -a $dir != RCS -a $dir != . -a $dir != .. ]; then
      echo $dir:
      mkdir $dir
      (cd $dir
       case "$from" in
       /*) ;;
       *)  from=../$from ;;
       esac
       shadow $from/$dir
      )
    fi
  done
}

shadow $from
