#!/bin/sh
# BLURB gpl
# 
#                            Coda File System
#                               Release 6
# 
#           Copyright (c) 1987-2003 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 1

#
# Configuration
#
numservers=1

. "`codaconfedit server.conf`"

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

# current first maximum replicated volume id
echo 2130706432 > ${vicedir}/db/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

if [ $numservers -eq 1 ]; then
    id=""
    until [ "x$id" != x ]; do
	echo "Enter an id for the SCM server. (hostname $bn)"
	echo "The serverid is a unique number between 0 and 255."
	echo "You should avoid 0, 127, and 255."
	echon "serverid: "
	read id
    done
    echo "$bn		$id" >> servers
else 
    n=1;
    while [ $n -le $numservers ]; do
        . "`codaconfedit server_$n.conf`"
        id=""
	until [ "x$id" != x ]; do
	    echo "Enter an id for server number $n. ($hostname)"
	    echo "The serverid is a unique number between 0 and 255."
	    echo "You should avoid 0, 127, and 255."
	    echon "serverid: "
	    read id
	done
	echo "$hostname		$id" >> servers
	n=`expr $n + 1`
    done
fi  
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
if [ $numservers -gt 1 ]; then
    echo "You will need to edit ${vicedir}/db/VSGDB to make more"
    echo "volume storage groups that include other servers than the SCM."
fi

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

#
# Add information for other servers on this machine
#
