#!/bin/sh

set -e

pkg=base-passwd

if [ ! "$1" = "configure" ]; then
    exit 0
fi

if [ -d /usr/doc -a ! -e /usr/doc/$pkg -a -d /usr/share/doc/$pkg ] ; then
    ln -s ../share/doc/$pkg /usr/doc/$pkg
fi

if [ ! -e /etc/passwd ] ; then
	cp /usr/share/base-passwd/passwd.master /etc/passwd
fi

if [ ! -e /etc/group ] ; then
	cp /usr/share/base-passwd/group.master /etc/group
fi

tmp=`tempfile`
if ! update-passwd --dry-run > $tmp ; then
	cat <<EOF
update-passwd has found some differences between your system accounts
and the current Debian defaults. It is advisable to allow update-passwd
to change your system; without those changes some packages might not work
correctly.  For more documentation on the Debian account policies please
see /usr/share/doc/base-passwd/README.

The last of proposed changes is:

EOF
	
	cat $tmp
	cat <<EOF

It is highly recommend that you allow update-passwd to make these changes
(a backup file of modified files is made with the extension .old so you can
always restore the current settings).

EOF
	while : ; do
		echo -n "May I update your system? [Y/n] "
		read a
		if [ "$a" = "" ] ; then
			a="y"
		fi
		a=`echo $a | tr A-Z a-z`
		if [ "$a" = "y" -o "$a" = "n" ] ; then
			break
		fi
		echo "Illegal answer"
	done
fi

rm -f $tmp

if [ "$a" = "y" ] ; then
	echo "Okay, I am going to make the necessary updates now"
	update-passwd --verbose
elif [ "$a" = "n" ] ; then
	cat <<EOF

Okay, I will not update your system. If you want to make this update later
please check the update-passwd utility.

EOF
fi

exit 0

