if grep "^nutups:" /etc/passwd 1> /dev/null 2> /dev/null || grep "^nutups:" /etc/group 1> /dev/null 2> /dev/null ; then
  echo "NOTE!"
  echo "There are already a user or group named nutups on this system."
  echo "Nut is compiled to use user/group nutups. You can override this"
  echo "by using -u in most of the programs."
else
  echo "Making user/group nutups."
  groupadd nutups 2>/dev/null
  useradd -g nutups -d / -s /bin/false -c "Network UPS Tools" nutups 2>/dev/null
  echo "Nut is compiled to use the user/group nutups by default, make sure"
  echo "it has permission to access the UPS port for it to work or use the"
  echo "-u switch to make Nut use a different user."
  # A possible solution would have been to add nutups to the tty group.
  # This could also give modem access to nutups on some systems, so
  # I didn't do this by default.
fi
# Be completely certain the correct permissions are set. Note the use of
# relative paths: this is because installpkg could be run with -root.
chmod 0700 var/state/ups
chown nutups:nutups var/state/ups
chmod 0640 etc/nut/*
chown -R root:nutups etc/nut
chmod 0750 etc/nut
# The files in /etc/nut/ must not be world-readable, and definitely not
# world-writable. Some contain the password for the ups and could allow an
# attacker-initiated shutdown. Together with editing upsmon.conf, an attacker
# could run any program under nutups or maybe even root.
echo
echo "Do you wish to add NUT to /etc/rc.d/ for automatic startup [y/N]?"; read -t 5 answer
case $answer in
 y|Y) 
	# if rc.local doesn't exist, create it
	if [ ! -e etc/rc.d/rc.local ]; then
        	echo "#!/bin/sh" > etc/rc.d/rc.local
        	chmod 755 etc/rc.d/rc.local
		chown root:root etc/rc.d/rc.local
	fi
	echo "if [ -x /etc/rc.d/rc.nut ]; then" >> etc/rc.d/rc.local
	echo " /etc/rc.d/rc.nut start" >> etc/rc.d/rc.local
	echo "fi" >> etc/rc.d/rc.local
 ;;
esac
echo "You may need to edit the configuration files at /etc/nut/sample/ and place them in /etc/nut for NUT to work."

