#!/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`" = "-n" ] ; then
        echo "$@"'\c'
    else
        echo -n "$@"
    fi
}

# exit if errors
set -e

#
# Configuration
#
prefix=/usr
conf=/etc/coda/server.conf
if [ -f ${conf} ] ; then
  . ${conf}
  haveconf=1
else
  haveconf=0
fi

if [ x${vicedir} = x ] ; then
  vicedir=/vice
fi

# current first maximum replicated volume id
cd ${vicedir}/vol
echo 2130706432 > maxgroupid

#
# setting up servers file
#

id=""
echo
echo Setting up servers file.
#
# making hostname
#

hn=`hostname`
bn=`echo $hn | cut -f 1 -d .`
if [ x$bn = x ]; then
    bn=$hn
fi
cd ${vicedir}/db

until [ "x$id" != x ]; do
   echo 'Enter an id for this server.'
   echo 'The serverid should be a number between 0 and 255 *avoid 0, 127, and
255*'
   echon 'serverid: '
   read id
done
echo "$bn		$id" >> servers
echo done!

#
#  this is the scm so put hostname in ${vicedir}/db/scm
#
echo $bn > ${vicedir}/db/scm

#
# set up the initial VSG on the SCM; this is the SCM itself only. 
#
echo "Initializing the VSGDB to contain the SCM as E0000100"
echo E0000100 $bn > ${vicedir}/db/VSGDB
echo ${vicedir}/db/VSGDB set up

id=""
echo
echo Setting up ROOTVOLUME file
cd ${vicedir}/db
until [ "x$id" != x ]; do
   echon 'Enter the name of the rootvolume (< 32 chars) : '
   read id
done
echo $id > ${vicedir}/db/ROOTVOLUME
echo
echo


