-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathonLeave
executable file
·57 lines (57 loc) · 3.12 KB
/
onLeave
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
INPUT=~/gam-data/userterm.csv
TEMP=~/gam-data/orgname.csv
OLDIFS=$IFS
IFS=,
timestamp=$(date +%Y-%m-%d@%I:%M%p)
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read userEmail userFirst userLast managerEmail managerPhone
do
#domain=${userEmail/*@/ }
#userId=${userEmail/@*/ }
#userId="$(echo -e "${userId}" | sed -e 's/[[:space:]]*$//')"
#domain="$(echo -e "${domain}" | sed -e 's/^[[:space:]]*//')"
#domain="@$domain"
#dateStamp=_onleave_$(date +%Y%m%d)
#newEmail=$userId$dateStamp$domain
~/bin/gam/gam info user $userEmail | grep "Path:" > $TEMP
line="$(head -1 $TEMP)"
line="${line#'Google Org Unit Path: '}"
if [ -z "$1" ]
then
echo -e "\e[91m\e[7mALERT:\e[0m To be used only for on leave procedure"
echo -e "to process changes use \e[91m./onLeave doit\e[0m"
echo -e "---[ \e[93m\e[1mPREVIEW of Changes \e[0m]--- "
echo -e "\e[1mUser on Leave: \e[0m$userEmail"
echo -e "\e[1mDelegate to: \e[0m$managerEmail ($managerPhone)"
echo -e "\e[1mVacation Responder: \e[0m"
echo -e " $userFirst $userLast is out of the office, please contact $userFirst's manager at"
echo -e " <$managerEmail> or by telephone at $managerPhone. \n\n Thank You. \n IEEE Support."
echo -e "\e[1mSet OnLeave and Date $(date +%Y-%m-%d)"
echo -e "---[ \e[93m\e[1mPREVIEW END \e[0m]--"
echo
else
if [ "${1^^}" == "DOIT" ]
then
echo -e "---[ \e[93m\e[1mOn Leave Process for User \e[36m$userFirst $userLast \e[0m]---\e[32m"
echo "* $timestamp * $userEmail - On Leave Process Start" >> ~/gam-data/gam-data.log
~/bin/gam/gam update user $userEmail suspended off
~/bin/gam/gam update user $userEmail Status.Status OnLeave Status.Date $(date +%Y-%m-%d) Status.OU $line
echo "* $timestamp * $userEmail - Status set to OnLeave on $(date +%Y-%m-%d)" >> ~/gam-data/gam-data.log
echo -e "\e[36m- Delegate access to Manager\e[0m"
~/bin/gam/gam user $userEmail delegate to $managerEmail
~/bin/gam/gam user $managerEmail add calendar $userEmail selected true hidden false
echo "* $timestamp * $userEmail - Delegated email to $managerEmail" >> ~/gam-data/gam-data.log
echo -e "\e[36m- Deprovision $userEmail\e[0m"
~/bin/gam/gam user $userEmail deprovision
echo "* $timestamp * $userEmail - Revoked all App Passwords, 2 Factor, and OAuth tokens" >> ~/gam-data/gam-data.log
echo -e "\e[36m- Set Vacation Message\e[0m"
~/bin/gam/gam user $userEmail vacation on subject "$userFirst $userLast is out of the office:" message "$userFirst $userLast is out of the office, please contact $userFirst's manager by email at <$managerEmail> or by telephone at $managerPhone. \n\n Thank You, \n IEEE Support." startdate $(date +%Y-%m-%d) enddate 2099-12-30
echo "* $timestamp * $userEmail - Set vacation responder to $managerEmail ($managerPhone)" >> ~/gam-data/gam-data.log
echo "* $timestamp * $userEmail - On Leave Process Complete" >> ~/gam-data/gam-data.log
echo -e "\e[0m---[ \e[93m\e[1m On Leave Process Complete for \e[36m$userFirst $userLast \e[0m]---"
echo
fi
fi
done < $INPUT
IFS=$OLDIFS