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

prefix=/usr/pkg
exec_prefix=${prefix}

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

# exit if errors
set -e 1

#
# Configuration
#
numservers=1

. "`${exec_prefix}/sbin/codaconfedit server.conf`"

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

# current first maximum replicated volume id (0x7f000000)
echo 2130706432 > ${vicedir}/db/maxgroupid

#
# setting up servers file
#

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

if [ x$hn = x ] ; then
  if [ `uname -s` != Linux ] ; then
    domain=""
    while [ x$domain = x ] ; do
      echo -n "What is the domain name for your servers? "
      read domain
    done
    hn=`hostname -s`.$domain
  else
    hn=`hostname -f`
  fi
fi

cd ${vicedir}/db

if [ $numservers -eq 1 ]; then
    id=""
    until [ "x$id" != x ]; do
	echo "Enter an id for the SCM server. (hostname $hn)"
	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 "$hn		$id" >> servers
else 
    n=1;
    while [ $n -le $numservers ]; do
        . "`${exec_prefix}/sbin/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 $hn > ${vicedir}/db/scm

#
# Add information for other servers on this machine
#
