#! /bin/bash
# This script is responsible for actually mounting Active Directory to give the user internet access


( # Create subshell for private env vars

this_dir=$(dirname $BASH_SOURCE)
. $this_dir/.env # Load private env vars

AD=$AD_MNT


#----- Init $AD folder -----#
# Check $AD folder exists, if not then create
[[ -d $AD ]] || mkdir -p $AD
# Unmount $AD if already mounted
mountpoint -q $AD && umount $AD


#----- Mount Active Directory on $AD via CIFS -----#
mount -t cifs //prhwinad03.up.ac.za/NETLOGON $AD -o domain=UP,credentials=$AD_CRED
rc=$? # Capture response code


#----- Cleanup -----#
rm $AD_CRED
exit $rc

) # End subshell
