#!/bin/bash

EVENT=$1
USER=$2

if [ -z "$EVENT" ]; then
    echo "event name is missing"
    exit 1
fi
if [ -z "$USER" ]; then
    echo "user account is missing"
    exit 1
fi

# SOGo is set to the short_username, if using a domain account, strip the domaine
if ($USER =~ /@/) {
    $USER = (split(/@/, $USER))[0];
}

# user is unknown by SOGo when SOGo service has never been used.
# command will still exit 0.
su -l -s /bin/bash sogo -c "/usr/sbin/sogo-tool remove $USER"  > /dev/null 2>&1

