#!/bin/bash

username=$1
password=$2
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ini="$current_dir/scripts.ini"
ldap_password=$(awk '/ldap_password/ {print $2}' $ini)
dc=$(awk '/dc/ {print $2}' $ini)
cn="$(awk '/cn/ {print $2}' $ini),$dc"
users_ou="$(awk '/users_ou/ {print $2}' $ini),$dc"
uid="uid=$username,$users_ou"

if [ -z $username ]
then
        echo "No username was set. Usage: change_passwd 'username' 'password'."
        exit 0
fi

if [ -z $password ]
then
        echo "No password was set. change_passwd 'username' 'password'."
        exit 0
fi

ldappasswd -x -D $cn -w $ldap_password -s $password "$uid"
