#!/bin/sh

# check for root
if [[ $EUID -ne 0 ]]; then
  echo "This script must be run as root" 1>&2
  exit 1
fi

# check for arguments
if [[ $# -gt 1 ]]; then
	echo "USAGE: $0 [filename]" 1>&2
	exit 1
fi

SECRET="`cat /etc/ldap.secret`"

if [[ $# -eq 1 ]]
then
	exec < $1
fi

cd /home
while read line
do
	if [[ -z $line ]]
	then
		continue
	fi

	line="`echo $line | cut -d ' ' -f 1`"

	echo "Deleting user ${line}..."

	ldapdelete -x -w "$SECRET" -D cn=admin,dc=zotac,dc=lctp "cn=$line,ou=users,dc=zotac,dc=lctp" >/dev/null
	ldapdelete -x -w "$SECRET" -D cn=admin,dc=zotac,dc=lctp "cn=$line,ou=groups,dc=zotac,dc=lctp" >/dev/null

	[ -d "$line" ] && rm -rf "$line"
done

