#!/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
# 
#*/

# Set up password and group files for Coda

cd /vice/db

echo "Setting up users and groups for Coda"
echo
echo "You need to give me a uid (not 0) and username (not root)"
echo "for a Coda System:Administrator member on this server,"
echo "(sort of a Coda super user)"
echo
 
until [ x$userid != x ]; do
 	echo -n "Enter the uid of this user: "
 	read userid
 	if [ x$userid = x ]; then
 	    echo "Nothing cannot be a Coda administrator"
 	    echo "Run vice-setup-user again"
#	    exit 1
 	fi
  
 	if [ x$userid = x0 ]; then
 	    echo "Root cannot be a Coda administrator"
 	    echo "Run vice-setup-user again"
 	    exit 1
 	fi
done

until [ x$username != x ]; do
 	echo -n "Enter the username of this user: "
 	read username
 	if [ x$username = x ]; then
 	    echo "Nothing cannot be a Coda administrator"
 	    echo "Run vice-setup-user again"
#	    exit 1
 	fi
 
 	if [ x$username = xroot ]; then
 	    echo "Root cannot be a Coda administrator"
 	    echo "Run vice-setup-user again"
 	    exit 1
 	fi
done

cat > pdbsetup<<EOF
nui Anonymous 776
nui System 777
ng System:AnyUser 777
ci System:AnyUser -101
nui $username $userid
ng System:Administrators $userid
ci System:Administrators -204
EOF

if [ -f prot_users.db ] ; then
  echo "Going to rebuild the protection databases"
  echo "moving /vice/db/prot_users.db to /vice/db/prot_users.db.old"
  mv prot_users.db prot_users.db.old
fi
if [ -f prot_index.db ] ; then
  echo "moving /vice/db/prot_index.db to /vice/db/prot_index.db.old"
  mv prot_index.db prot_index.db.old
fi

pdbtool source pdbsetup
rm pdbsetup

echo "$userid	changeme	admin user" > passwd.coda
initpw -k "drseuss " < passwd.coda > auth2.pw
rm passwd.coda

echo "An initial administrative user $username (id $userid)"
echo "with Coda password changeme now exists."
