#!/bin/sh -e

# Only perform this check/warning if the libvirt user groups aren't there
# already
if getent passwd libvirt-qemu >/dev/null \
&& getent group  libvirt-qemu >/dev/null; then
    exit 0
fi

# Source debconf library.
. /usr/share/debconf/confmodule

# Allocated UID and GID for libvirt-qemu
LIBVIRT_QEMU_UID=64055
LIBVIRT_QEMU_GID=64055

# Check if allocated UID/GID are assigned to a different user/group.
UID_TO_NAME="$(getent passwd $LIBVIRT_QEMU_UID | cut -d: -f1)"
GID_TO_NAME="$(getent group  $LIBVIRT_QEMU_GID | cut -d: -f1)"

if ( [ -n "$UID_TO_NAME" ] && [ "$UID_TO_NAME" != 'libvirt-qemu' ] ) \
|| ( [ -n "$GID_TO_NAME" ] && [ "$GID_TO_NAME" != 'libvirt-qemu' ] ) \
then
    # Ask if the user would like to continue or abort installation.
    db_input high libvirt-daemon-system/id_warning || true
    db_go
    db_get libvirt-daemon-system/id_warning
    if [ "$RET" = "false" ]; then
        exit 1
    fi
fi

db_stop
exit 0
