#! /usr/bin/perl


###############################################################################
#
# Add the 'gnats' userid into the password file
#
$gnatsid    = 41;														# provided by 'init'
$passwdfile = "/etc/passwd";											# provided by 'init'
$gnatshome  = "/var/lib/gnats/gnats-db";								# provided by 'init'
$gnatsentry = "gnats:*:$gnatsid:$gnatsid:gnats:$gnatshome:/bin/sh";		# provided by 'init'

#
# Slurp the entire password file
#
$delim = $/; undef $/;
open(PASSWD,"<$passwdfile") || adduser_die;
$passwd = <PASSWD>;
close(PASSWD);
$/ = $delim;
@passwd = split(/\n/,$passwd);

#
# Remove any old entry for 'gnats'
#
$pwfound = grep(/^gnats:/,@passwd);
$pwgstar = grep(/^gnats:\*:/,@passwd);
if ($pwfound > 1) {
	print "* Multiple listings of the 'gnats' userid were found in '$passwdfile'.\n";
	$waitcr = 1;
}
if ($pwfound > 0) {
	if (!grep(/^gnats.*:\Q$gnatshome\E:/,@passwd)) {
		print "- A 'gnats' userid with incorrect home directory was found\n";
	}
}
if ($pwfound == 0) {
	print "* Your password file does not contain a userid for the 'gnats' user.\n";
	print "  You must either upgrade your 'base-passwd' package or add the following\n";
	print "  line to your /etc/passwd file:\n\n";
	print "  $gnatsentry\n";
	$waitcr = 1;
}
