#!/bin/sh

#
# Setting up the server directory
#

echo 
echo Your server directories will hold the files \(not directories\). 
echo You can currently only have one directory per disk partition.
echo

echo -n 'Where shall we store your data [/vicepa]? '
srvdir=/vicepa
read srvdir

if [ x$srvdir = x ]; then
    srvdir=/vicepa
fi

# set up a symlink if needed

if [  -e $srvdir -a ! -d $srvdir ]; then
   echo $srvdir exists, but is not a directory. Exiting.
   exit 1
fi

if [ -d $srvdir -a -e $srvdir/FTREEDB ]; then
   echo "An FTREEDB exists in $srvdir.  Clean up first and rerun $0"
   exit 1
fi

mkdir $srvdir
touch $srvdir/FTREEDB

hn=`hostname`
bn=${hn%%.*}
if [ x$bn = x ]; then
    bn=$hn
fi

until [ x$yesno != x ]; do
   echo -n "Shall I set up a vicetab entry for approx 256000 files for $srvdir (y/n) "
   read yesno
   if [  x$yesno = xy -o  x$yesno = xyes  ]; then
       grep $srvdir /vice/db/vicetab
       if [ $? = 0 ]; then
          echo "$srvdir already in /vice/db/vicetab. Please clean up first."
	  exit 1
       fi

       echo "$bn   $srvdir   ftree   width=64,depth=3" >> /vice/db/vicetab
       echo "Now initializing the partition. This takes a while...."
       makeftree /vice/db/vicetab $srvdir
       echo "done."
   else
       echo
       echo  "Read vicetab(5) and makeftree(8) for set up info."
   fi
done

echo Server directory is set up!
echo
