#!/bin/sh
# BLURB gpl
# 
#                            Coda File System
#                               Release 5
# 
#           Copyright (c) 1987-1999 Carnegie Mellon University
#                   Additional copyrights listed below
# 
# This  code  is  distributed "AS IS" without warranty of any kind under
# the terms of the GNU General Public Licence Version 2, as shown in the
# file  LICENSE.  The  technical and financial  contributors to Coda are
# listed in the file CREDITS.
# 
#                         Additional copyrights
#                            none currently
# 
#*/

echon() {
    if [ "`echo -n`" ] ; then
        echo "$@"\c
    else
        echo -n "$@"
    fi
}

#
# 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

echon '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 [ -d $srvdir -o -h $srvdir ]; then
    if [ -f $srvdir/FTREEDB ]; then
      echo "An FTREEDB exists in $srvdir.  Clean up first and rerun $0"
      echo "You may also want to clean up /vice/db/vicetab"
      exit 1
    fi
else
    mkdir $srvdir
    if [ $? = 0 ]; then
   	 echo $srvdir exists, but is not a directory. Exiting.
  	  echo Run vice-setup-srvdir to repeat this step.
  	  exit 1
    fi
fi
touch $srvdir/FTREEDB

hn=`hostname`
bn=`echo $hn | cut -f 1 -d .`
if [ x$bn = x ]; then
    bn=$hn
fi

until [ x$yesno != x ]; do
   echon "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 >/dev/null 2>&1
       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
