#!/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
exec_prefix=${prefix}

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

# exit if errors
set -e

#
# Configuration
#
. "$("${exec_prefix}/sbin/codaconfedit" server.conf)"

if [ "$vicedir" = "" ] ; 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 [ "$hn" = "" ] ; then
  if [ "$(uname -s)" != Linux ] ; then
    domain=""
    while [ "$domain" = "" ] ; do
      echon "What is the domain name for your servers? "
      read -r domain
    done
    hn=$(hostname -s).$domain
  else
    hn=$(hostname -f)
  fi
fi

cd "$vicedir/db" || exit

id=""
while [ "$id" = "" ]; 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 -r id
done
echo "$hn		$id" >> servers
echo done!

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