#!/bin/sh
#
# Shell-script to bootstrap cell
#

# shell stuff

version="$Id: boot-strap.sh.in,v 1.4 2000/02/19 07:13:02 lha Exp $"
usage="Usage: $0 [-v] [-p /viceN ]"

#
# Milko Boot variables
#

#all zeros are needed on ROOTVOLNUM

ROOTVOL=root.cell
ROOTVOLNUM=00000003
ROOTPART=/vicepa

#
# Autoconf stuff
#

prefix=@prefix@
exec_prefix=@exec_prefix@
sbindir=@sbindir@
bindir=@bindir@
libexecdir=@libexecdir@
sysconfdir=@sysconfdir@

ksrvutil=/usr/athena/sbin/ksrvutil

while test $# -gt 0
do
    case $1 in
	-v) echo $version ; shift ; exit 1 ;;
	-p) ROOTPART=$2 ; 
	    shift 2 2>/dev/null || { echo $usage ; exit 1 }
	    ;;
	*)  echo $usage ; exit 1; break;;
    esac
done

#
# What we do if we fail
#

antibootstrapbin="${sbindir}/anti-boot-strap.sh"
antibootstrap="${antibootstrapbin} magic4711 $ROOTPART ${sysconfdir}"


PROGRAMS="$sbindir/sked \
    $libexecdir/fileserver \
    $libexecdir/ptserver \
    $libexecdir/bosserver \
    $libexecdir/vldbserver \
    $antibootstrapbin "

for a in $PROGRAMS; do
    if [ ! -x $a ] ; then
	echo "ERROR: missing $a, did you do a make install ?";
	exit 1;
    fi
done

if [ ! -d $ROOTPART ]; then
    echo "ERROR: You don't have a $ROOTPART katalog/mountpoint."
    echo "Please create.";
    exit 1
fi

# XXX figure out hostname

if [ -f $ROOTPART/vol$ROOTVOLNUM ] ; then
    echo "WARNING: are you sure you want to overwrite a existing installation"
    echo "There seams to be traces of a installation $ROOTPART"
    echo "Please remove it before retrying if you don't want it"
    exit 1
fi

if [ -f $sysconfdir/pr_database ] ; then
    echo "WARNING: there is already a pr database"
    echo "Remove it ($sysconfdir/pr_database) it you want to proceed"
    exit 1
fi

if [ -f $sysconfdir/vl_database ] ; then
    echo "WARNING: there is already a vl database"
    echo "Remove it ($sysconfdir/vl_database) it you want to proceed"
    exit 1
fi


if $sbindir/sked volcreate ${ROOTPART} ${ROOTVOLNUM} ${ROOTVOL}; then
    : ;
else
    echo "ERROR: failed to created ${ROOTVOL} with sked";
    exec ${antibootstrap}
fi

# XXX create root srvtab

if $libexecdir/vldbserver -create ; then
    : ;
else
    echo "ERROR: failed to vl database";
    exec ${antibootstrap}
fi

# XXX add rootvol

if $libexecdir/ptserver -create ; then
    : ;
else
    echo "ERROR: failed to pts database";
    exec ${antibootstrap}
fi

# XXX create a bosserver.conf

# XXX tell how to add users to system:administators (pts cu foo -local)

# XXX tell how to start bosserver

if test -x $ksrvutil ; then
    echo "Now its time to create kerberos tickets for you cell"
    echo "  For Name[rcmd]: write: afs"
    echo "  For Instance[hostname]: write: you.cell.here"
    echo "  For Realm [YOUR.REALM]: write YOUR.REALM.HERE"
    echo ""
    echo "  the rest is obvious"

    command="$ksrvutil -f $sysconfdir/srvtab -p $USER.admin get"

    echo "The command I'm try is \"$command\""

    eval $command

else

    echo "No kth-krb ksrvutil, create a srvtab with afs.you\.cell\.@YOUR.REALM"
    echo "token in $sysconfdir"

fi

echo "Congratulations, done"

exit 0;