#!/bin/sh
set -e

# 2 packages that use dh-sysuser:
# runit --> _runit-log // nonexistent //

# make sure the test env is clean
apt-get -y purge runit

if  grep _runit-log /etc/passwd /etc/group ; then
	echo "user _runit-log exists, environment is not clean"
	exit 1
fi

rc=0
# test the user creation
apt-get -y install runit
# we expect _runit-log to exist now
if  grep _runit-log /etc/passwd; then
	echo "OK: user _runit-log succesfully created"
else
	echo "FAILED: user _runit-log does not exist"
	rc=1
fi

# remove without purge, users should be still there
apt-get -y remove runit
if  grep _runit-log /etc/passwd; then
	echo "OK: user _runit-log succesfully created"
else
	echo "FAILED: user _runit-log does not exist"
	rc=1
fi

# now test the user removal on purge:
# _runit-log has home set to nonexistent so
# user should be removed on purge
#apt-get -y purge runit
#if  grep _runit-log /etc/passwd /etc/group ; then
#	echo "FAILED: user _runit-log exists after purge or environment is not clean"
#	rc=1
#fi

exit $rc
