#!/bin/sh

if [ -r .subdir ]; then
   cat .subdir
   exit 0
fi

cwd=`pwd`;

if [ -r configuration ]; then
   echo "." | tee .subdir
   exit 0
fi

if [ ! -r ../.subdir ]; then
   if echo $0 | egrep "^/" 2>&1 >/dev/null; then
      (cd ..; $0 >/dev/null)
   else
      (cd ..; $cwd/$0 >/dev/null)
   fi
fi

if [ ! -r ../.subdir ]; then
   echo "unable to determine subdirectory"
   exit 2
fi

rootdir=`sed 's/\.$//' ../.subdir`
subdir=`basename ${cwd}`
echo "${rootdir}${subdir}/." | tee .subdir

exit 0
