#!/bin/sh

BASENAME=`basename $0`
if [ $# != 2 ]; then
	echo "usage: $BASENAME <username> <listfile>"
	exit 1
fi

DEFAULTSCMD=/usr/bin/defaults
USERNAME=$1
DEFAULTSLIST=$2
TMPFILE=/tmp/$BASENAME.$$

if [ -f $DEFAULTSCMD ]; then
	if [ -f $DEFAULTSLIST ]; then
		if [ "`/usr/ucb/whoami`" = "root" ]; then
			grep -v "^#" $DEFAULTSLIST | sed "s/^/\/usr\/bin\/defaults write /" > $TMPFILE
			su $USERNAME < $TMPFILE
			rm -f $TMPFILE
		else
			echo "$BASENAME must be run as root."
			exit 1
		fi
	else
		echo "Missing `basename $DEFAULTSLIST`."
		exit 1
	fi
else
	exit 0	# The system is not NeXTSTEP 4.x
fi
