#! /bin/sh
#
# Written 9/20/00 by Joe Block <jpb@creol.ucf.edu>
#
# It shouldn't matter, but this script is GPL.

cat <<EOF
This script massages your netinfo database.  This can severely break
your system.  If your netinfo database breaks, you get to keep the parts.

If you've already created a postfix user using Multiple Users, you'll need
to edit this script.  do:

		niutil -read / /users/postfix

to find out what uid was assigned to postfix.  Comment out the stanza in
this script that creates the postfix user

Also note that this script assumes that you are
	A) running MacOS X Public Beta
	B) have not added any groups to the base system

If you've added groups or are not running Public Beta, you should
make sure the gids in this script have not already been used.

You'll need to edit the script to remove the exit statement before the first
call to niutil to show you read the directions and understand the risks.

EOF

PFSHELL=/usr/bin/false
PFUID=88
PFGID=88
PFHOME=/Users/postfix
MDGID=99

echo -n "shell for user postfix? [$PFSHELL]"
read pfshell
if ["$pfshell" = ""]
then
	pfshell=$PFSHELL
fi
echo

echo -n "uid for user postfix? [$PFUID]"
read pfuid
if ["$pfuid" = ""]
then
	pfuid=$PFUID
fi
echo

echo -n "gid for user postfix? [$PFGID]"
read pfgid
if ["$pfgid" = ""]
then
	pfgid=$PFGID
fi
echo

echo -n "Home directory for user postfix (we won't actually create it as postfix doesn't use it)? [$PFHOME]"
read pfhome
if ["$pfhome" = ""]
then
	pfhome=$PFHOME
fi
echo

echo -n "gid for maildrop group? [$MDGID]"
read mdgid
if ["$mdgid" = ""]
then
	mdgid=$MDGID
fi
echo

echo "postfix user: shell=$pfshell, uid=$pfuid, gid=$pfgid,home=$pfhome"
echo "maildrop group: $mdgid"
echo
echo -n "You're sure you want to massage your netinfo database? [yes/NO]"
read arewesure

case $arewesure in
	yes|YES)
		echo "remember, you were warned"
		;;
	*)
		echo "OK, exiting"
		exit 0
		;;
esac
exit 0

echo "Tweaking netinfo now"
echo "Creating postfix user"
niutil -create / /users/postfix
niutil -createprop / /users/postfix realname "Postfix user"
niutil -createprop / /users/postfix shell $pfshell
niutil -createprop / /users/postfix uid $pfuid
niutil -createprop / /users/postfix gid $pfgid
niutil -createprop / /users/postfix home $pfhome
niutil -createprop / /users/postfix _shadow_passwd
passwd postfix

echo "Creating postfix group"
niutil -create / /groups/postfix
niutil -createprop / /groups/postfix name postfix
niutil -createprop / /groups/postfix gid $pfgid
niutil -createprop / /groups/postfix passwd '*'
echo "Adding postfix user to postfix group"
niutil -appendprop / /groups/postfix users postfix

echo "Creating maildrop group.  Remember not to add any users to this group,"
echo "or you might as well have made your maildrop directory world writable."
niutil -create / /groups/maildrop
niutil -createprop / /groups/maildrop name maildrop
niutil -createprop / /groups/maildrop gid $mdgid
niutil -createprop / /groups/maildrop passwd '*'
