+sys-user_pkg_pretend() {
+ # Sanity checks that would otherwise run code in global scope.
+ #
+ # First ensure that the user didn't say his UID is important and
+ # then fail to specify one.
+ if (( "${SYS_USER_UID}" == -1 )) &&
+ [[ "${SYS_USER_UID_IMPORTANT}" == "true" ]]; then
+ # Don't make no damn sense.
+ die "arbitrary UID requested with SYS_USER_UID_IMPORTANT=true"
+ fi
+
+ # Next ensure that no other username owns an important UID.
+ if [[ "${SYS_USER_UID_IMPORTANT}" == "true" ]]; then
+ # Ok, the UID is important. Make sure nobody else has it. Or
+ # rather, nobody else *with a different username* has it.
+ local oldname=$(egetent passwd "${SYS_USER_UID}" | cut -f1 -d':')
+ if [[ "${SYS_USER_NAME}" != "${oldname}" ]]; then
+ die "important UID ${SYS_USER_UID} already belongs to ${oldname}"
+ fi
+ fi
+
+ # Finally, ensure that this username doesn't already exist with
+ # another UID if its UID is supposedly important.
+ if [[ -n $(egetent passwd "${SYS_USER_NAME}") ]]; then
+ local olduid=$(id --real --user "${SYS_USER_NAME}")
+ if [[ "${SYS_USER_UID_IMPORTANT}" == "true" ]] && \
+ [[ "${SYS_USER_UID}" != "${olduid}" ]]; then
+ # The UID is important and specified, but there is already a
+ # system user with this name and a different UID. Halp.
+ die "user ${SYS_USER_NAME} already exists with UID ${olduid}"
+ fi
+ fi
+}