-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffboard.sh
executable file
·794 lines (706 loc) · 22.9 KB
/
offboard.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
#!/usr/bin/env bash
# =============================================================================
# Script Name: offboard.sh
# Description: A user-friendly shell script with interactive
# select menus and comprehensive error handling.
# Author: Joshua McKenna
# Date: 2025-02-04
# =============================================================================
# -------------------------------
# 1. Configuration and Initialization
# -------------------------------
# Enable strict error handling
set -euo pipefail
IFS=$'\n\t'
# Move execution to the script's parent directory
INITIAL_WORKING_DIRECTORY=$(pwd)
parent_path=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd -P
)
cd "$parent_path"
# Check if config.env exists
if [ ! -f "$(dirname "$0")/config.env" ]; then
echo -e "'\033[1;31m'ERROR'\033[0m': config.env file is missing from the $(dirname "$0") directory."
exit 1
else
# shellcheck source=/dev/null
source "$(dirname "$0")/config.env"
fi
# Define time variables
NOW=$(date '+%F %H.%M.%S')
TODAY=$(date '+%F')
# Ensure the log directory exists
mkdir -p "${LOG_DIR}/${TODAY}"/other
# Define log variables
LOG_FILE="${LOG_DIR}/${TODAY}/$NOW $(basename "$0").log"
LOG_LEVEL="INFO" # Set your log level here
# Set default log paths
ERR_LOG="${LOG_DIR}/${TODAY}/other/$NOW $(basename "$0") ERROR.log"
WARN_LOG="${LOG_DIR}/${TODAY}/other/$NOW $(basename "$0") WARNING.log"
INFO_LOG="${LOG_DIR}/${TODAY}/other/$NOW $(basename "$0") INFO.log"
# Determine the logging behavior based on LOG_LEVEL
if [[ "$LOG_LEVEL" == "INFO" ]]; then
ERR_LOG="${LOG_FILE}"
WARN_LOG="${LOG_FILE}"
INFO_LOG="${LOG_FILE}"
elif [[ "$LOG_LEVEL" == "WARNING" ]]; then
ERR_LOG="${LOG_FILE}"
WARN_LOG="${LOG_FILE}"
# INFO_LOG will remain as its default
elif [[ "$LOG_LEVEL" == "ERROR" ]]; then
ERR_LOG="${LOG_FILE}"
# WARN_LOG and INFO_LOG will remain as their defaults
elif [[ "$LOG_LEVEL" == "DEBUG" || "$LOG_LEVEL" == "VERBOSE" ]]; then
exec 19> "${LOG_FILE}"
BASH_XTRACEFD="19"
set -x # Enable debug mode
# Separate logs for DEBUG/VERBOSE
else
echo "Unsupported LOG_LEVEL: $LOG_LEVEL. Defaulting to separated ERR/WARN/INFO logs."
# Use the defaults
fi
# Print ERROR messages in bold red.
print_error() {
echo -e "${BOLD_RED}ERROR${RESET}: ${1:-}" | tee -a "${ERR_LOG}" >&2
}
# Print WARNING messages in bold yellow.
print_warning() {
echo -e "${BOLD_YELLOW}WARNING${RESET}: ${1:-}" | tee -a "${WARN_LOG}"
}
# Print INFO messages in bold blue.
print_info() {
echo -e "${BOLD_CYAN}INFO${RESET}: ${1:-}" | tee -a "${INFO_LOG}"
}
# Print SUCCESS messages in bold green.
print_success() {
echo -e "${BOLD_GREEN}SUCCESS${RESET}: ${1:-}" | tee -a "${INFO_LOG}"
}
# Print PROMPT messages in bold purple.
# shellcheck disable=SC2120
print_prompt() {
echo -e "${BOLD_PURPLE}ACTION REQUIRED${RESET}: ${1:-}"
}
# Print COMMAND before executing.
print_and_execute() {
echo -e "${BOLD_WHITE} + $* ${RESET}" | tee -a "${INFO_LOG}"
"$@"
}
# Function to update GAM and GAMADV-XTD3
update_gam() {
print_info "Updating GAM and GAMADV-XTD3..."
bash <(curl -s -S -L https://gam-shortn.appspot.com/gam-install) -l
bash <(curl -s -S -L https://raw.githubusercontent.com/taers232c/GAMADV-XTD3/master/src/gam-install.sh) -l
# Update the last update date in the config.env file
local current_date
current_date=$(date +%F)
sed -i'' -e "s/^GAM_LAST_UPDATE=.*/GAM_LAST_UPDATE=\"$current_date\"/" "$(dirname "$0")/config.env"
export GAM_LAST_UPDATE="$current_date"
}
# -------------------------------
# 2. Utility Functions
# -------------------------------
validate_email() {
# Example: use a regular expression to check for valid email format
[[ $1 =~ ^[^@]+@[^@]+\.[^@]+$ ]] || print_error "Invalid email address: $1"
}
# Initialize the log file.
initialize_logging() {
# Create a new log file for each run of the script.
echo
echo "========================================"
print_info "Starting $0 script at $(date)"
echo "========================================"
echo "GAM3 command alias set to ${GAM3}"
${GAM3} version
echo "Bash version ${BASH_VERSION}"
echo "Logging to ${LOG_FILE}"
echo
}
# Print HELP instructions.
print_help() {
echo
echo -e "${BOLD_WHITE}Usage:${RESET} $0 [OPTIONS]"
echo
echo -e "${BOLD_WHITE}Options:${RESET}"
echo " -h, --help Display this help message and exit."
echo
echo -e "${BOLD_WHITE}Description:${RESET}"
echo " This script provides an interactive menu for onboarding new users in Google"
echo " Workspace. It uses the Google Apps Manager (GAMADV-XTD3) command-line tool"
echo " to interact with Google Workspace APIs."
echo
echo " Without any options, it launches the interactive menu."
echo
echo -e "${BOLD_WHITE}Examples:${RESET}"
echo -e " Display help:"
echo " $0 -h | --h | --help | help"
echo
echo -e " ${WHITE}Provide all arguments up-front:${RESET}"
echo -e " ${BOLD_YELLOW}1${RESET} offboard_user User email for the offboarding user"
echo -e " ${BOLD_YELLOW}2${RESET} receiving_user User email for the receiving user of any transfers"
echo
echo -e " ${WHITE}Run the interactive menu:${RESET}"
echo " $0"
echo
}
# -------------------------------
# 3. Task Functions
# -------------------------------
# Exits the script.
task_exit() {
func=${FUNCNAME[0]}
ret=$?
echo
if [ $ret -ne 0 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo -e "Exit $func with code $ret"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
else
echo "========================================"
echo "========================================"
fi
return 0
}
handle_help() {
if [ "$#" -eq 0 ]; then
print_help
exit 0
fi
case "$1" in
-h | --h | --help | help)
print_help
exit 0
;;
*)
return 0
;;
esac
}
confirm_continue() {
print_prompt
read -r -p "Press any key to continue..." -n1 -s
echo
}
confirm_inputs() {
echo
print_info "Confirming inputs at $(date)"
echo
echo "Employee to offboard: ${offboard_user}"
echo "Employee to receive transfers: ${receiving_user}"
echo
confirm_continue
echo
print_success "Inputs confirmed."
echo
}
get_info() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Fetching ${offboard_user}'s info for audit..."
if user_info_result=$(${GAM3} info user "$offboard_user"); then
print_success "$user_info_result"
else
print_warning "$user_info_result"
fi
echo
echo "Showing email forwards for ${offboard_user}..."
if user_forwards=$(${GAM3} user "$offboard_user" show forwards); then
print_success "$user_forwards"
else
print_warning "$user_forwards"
fi
echo
echo "Showing Shared Drives for ${offboard_user}..."
if user_teamdrives=$(${GAM3} user "$offboard_user" show teamdrives); then
print_success "$user_teamdrives"
else
print_warning "$user_teamdrives"
fi
echo
echo "Showing calendars for ${offboard_user}..."
if user_calendars=$(${GAM3} user "$offboard_user" show calendars); then
print_success "$user_calendars"
else
print_warning "$user_calendars"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
unsuspend() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Unsuspending user account for offboarding..."
if user_unsuspend_result=$(${GAM3} update user "$offboard_user" suspended off); then
print_success "$user_unsuspend_result"
else
print_error "$user_unsuspend_result"
task_exit
fi
echo
echo "Waiting for suspension to be removed..."
sleep 10
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
set_org_unit() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Moving ${offboard_user} to offboarding OU..."
if user_ou_result=$(${GAM3} update org 'Inactive' move user "${offboard_user}"); then
print_success "$user_ou_result"
else
print_error "$user_ou_result"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
reset_password() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Generating random password..."
if user_pass_reset=$(${GAM3} update user "$offboard_user" password random); then
print_success "$user_pass_reset"
else
print_error "$user_pass_reset"
fi
echo
echo "Requiring password change on next login..."
if changepassword_on_result=$(${GAM3} update user "$offboard_user" changepassword on); then
print_success "$changepassword_on_result"
else
print_error "$changepassword_on_result"
fi
sleep 2
if changepassword_off_result=$(${GAM3} update user "$offboard_user" changepassword off); then
print_success "$changepassword_off_result"
else
print_error "$changepassword_off_result"
fi
echo
print_success "${offboard_user}'s password changed."
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
reset_recovery() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Erasing recovery options for ${offboard_user}..."
if user_recovery_reset=$(${GAM3} update user "$offboard_user" recoveryemail "" recoveryphone ""); then
print_success "$user_recovery_reset"
else
print_error "$user_recovery_reset"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
set_endDate() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Setting ${offboard_user} end date to today..."
if user_end_date=$(${GAM3} update user "$offboard_user" Employment_History.End_dates multivalued "$(date '+%F')"); then
print_success "$user_end_date"
else
print_error "$user_end_date"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
#https://github.com/GAM-team/GAM/wiki/GAM3DirectoryCommands#setting-custom-user-schema-fields-at-create-or-update
}
deprovision() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Deprovisioning application passwords, backup verification codes, and access tokens..."
echo "Disabling POP/IMAP access, signing out all devices, and turning off MFA..."
if user_deprovision=$(${GAM3} user "$offboard_user" deprovision popimap signout); then #turnoff2sv
print_success "$user_deprovision"
else
print_error "$user_deprovision"
fi
echo
echo "Generating new MFA backup codes..."
if user_mfa_reset=$(${GAM3} user "$offboard_user" update backupcodes); then
print_success "$user_mfa_reset"
else
print_error "$user_mfa_reset"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
#https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Deprovision
}
remove_directory() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Hiding ${offboard_user} from the Global Address List (GAL)..."
if user_unlist_directory=$(${GAM3} update user "$offboard_user" gal off); then
print_success "$user_unlist_directory"
else
print_warning "$user_unlist_directory"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
#https://github.com/GAM-team/GAM/wiki/GAM3DirectoryCommands
}
forward_emails() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Forwarding emails..."
if user_unforward=$(${GAM3} user "$offboard_user" print forwardingaddresses | ${GAM3} csv - gam user "~User" delete forwardingaddress "~forwardingEmail"); then
print_success "$user_unforward"
echo "User-configured forwarding for ${offboard_user} has been deleted."
else
print_warning "$user_unforward"
fi
echo
echo "...granting delegate access to $receiving_user..."
if user_forward_recipient=$(${GAM3} user "$offboard_user" add forwardingaddress "$receiving_user"); then
print_success "$user_forward_recipient"
echo "Email for ${offboard_user} has been forwarded to ${receiving_user}."
else
print_error "$user_forward_recipient"
fi
echo
if archive_after_forward=$(${GAM3} user "$offboard_user" forward on "$receiving_user" archive); then
print_success "$archive_after_forward"
echo "Set ${offboard_user} inbox to archive after forwarding."
else
print_warning "$archive_after_forward"
fi
echo
if user_delegate_result=$(${GAM3} user "$offboard_user" delegate to "$receiving_user"); then
print_success "$user_delegate_result"
echo "Email for ${offboard_user} has been delegated to ${receiving_user}."
else
print_error "$user_delegate_result"
fi
echo
echo "Deleting ${offboard_user}'s email aliases..."
if user_aliases_result=$(${GAM3} user "$offboard_user" delete aliases); then
print_success "$user_aliases_result"
echo "${offboard_user}'s email aliases were deleted."
else
print_error "$user_aliases_result"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
#https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Gmail-Forwarding
}
set_autoreply() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
company="Grace Bible Church"
subject="No longer at $company"
message="Thank you for contacting me. I am no longer working at $company. Please direct any future correspondence to $receiving_user."
startDate=$(date +%F)
endDate=$(date -v +1y +%F)
print_info "Autoreply message will read:"
echo "Subject: ${subject}"
echo "Message: ${message}"
echo "Autoreply until: ${endDate}"
echo
confirm_continue
echo
echo "Configuring email autoreply..."
if user_autoreply=$(${GAM3} user "$offboard_user" vacation on subject "$subject" message "$message" startdate "$startDate" enddate "$endDate"); then
print_success "$user_autoreply"
echo "Email autoreply for ${offboard_user} set."
else
print_warning "$user_autoreply"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
transfer_drive() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Transferring Drive..."
# Runs the drive transfer locally instead of using the bulk transfer feature
if user_transfer_drive=$(${GAM3} create datatransfer "$offboard_user" gdrive "$receiving_user"); then
print_success "$user_transfer_drive"
echo "${offboard_user}'s My Drive was transferred to ${receiving_user}"
else
print_error "$user_transfer_drive"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
# ${GAM3} user "$offboard_user" transfer drive "$receiving_user"
#https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Drive-Transfer
}
transfer_calendar() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Transferring Calendar..."
if user_transfer_cal=$(${GAM3} add datatransfer "$offboard_user" calendar "$receiving_user" releaseresources); then
print_success "$user_transfer_cal"
echo "${offboard_user}'s calendar was transferred to ${receiving_user}"
else
print_error "$user_transfer_cal"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
# ${GAM3} calendar "$offboard_user" add owner "$receiving_user"
}
remove_groups() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Removing from groups..."
if user_delete_groups=$(${GAM3} user "$offboard_user" delete groups); then
print_success "$user_delete_groups"
echo "${offboard_user} removed from groups."
else
print_error "$user_delete_groups"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
remove_drives() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Removing from Shared Drives..."
${GAM3} redirect csv ./SharedDriveAccess.csv multiprocess user "$offboard_user" print shareddrives fields id,name
${GAM3} redirect stdout ./DeleteSharedDriveAccess.txt multiprocess redirect stderr stdout csv ./SharedDriveAccess.csv gam delete drivefileacl ~~id~~ ~~User~~
echo
print_success "${offboard_user} removed from Shared Drives."
echo
echo "Cleaning up temporary files..."
rm ./SharedDriveAccess.csv
rm ./DeleteSharedDriveAccess.txt
echo
print_success "Temporary files deleted."
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
suspend() {
echo
print_info "Entering ${FUNCNAME[0]} function at $(date)"
echo
echo "Waiting for last changes to take effect..."
sleep 10
print_info "Suspending $offboard_user before exiting."
if user_suspend_result=$(${GAM3} update user "$offboard_user" suspended on); then
print_success "${offboard_user} was suspended."
echo "$user_suspend_result"
else
print_error "$user_suspend_result"
fi
echo
echo "Exiting ${FUNCNAME[0]} function at $(date)"
echo
}
end_logger() {
echo
print_success "Google Workspace boarding process complete"
echo
echo "========================================"
echo "========================================"
}
trap 'print_warning "Interrupted by user."; exit 0' INT
trap 'print_error "Error on line ${LINENO}"; exit 1' ERR
# trap 'print_info "Exiting ${0}"; exit' EXIT
# exec 1> >(tee -a "${LOG_FILE}")
# exec 2> >(tee -a "${ERR_LOG}" "${LOG_FILE}")
# -------------------------------
# 4. Menu Setup
# -------------------------------
# Define menu options
choices=(
"Get user pre-offboarding info for audit"
"Set employee end date"
"Erase password and pass recovery options"
"Clear app passwords, backup codes, and access tokens"
"Move to Inactive OU and erase from directory (GAL)"
"Forward, delegate, configure autoreply for email"
"Transfer Google Drive files"
"Transfer Google Calendars and events"
"Remove from all Google Groups"
"Fully remove from all Shared Drive files"
"Standard offboard deprovisioning"
"Cancel"
)
# Set the prompt
PS3=$(printf 'Please select one of the options: \n ')
# -------------------------------
# 5. Main Menu Function
# -------------------------------
main_menu() {
select choice in "${choices[@]}"; do
case "$choice" in
"${choices[0]}")
echo
print_and_execute get_info
echo
break
;;
"${choices[1]}")
echo
print_and_execute set_endDate
echo
break
;;
"${choices[2]}")
echo
print_and_execute reset_password
print_and_execute reset_recovery
echo
break
;;
"${choices[3]}")
echo
print_and_execute deprovision
echo
break
;;
"${choices[4]}")
echo
print_and_execute set_org_unit
print_and_execute remove_directory
echo
break
;;
"${choices[5]}")
echo
print_and_execute forward_emails
print_and_execute set_autoreply
echo
break
;;
"${choices[6]}")
echo
print_and_execute transfer_drive
echo
break
;;
"${choices[7]}")
echo
print_and_execute transfer_calendar
echo
break
;;
"${choices[8]}")
echo
print_and_execute remove_groups
echo
break
;;
"${choices[9]}")
echo
print_and_execute remove_drives
echo
break
;;
"${choices[10]}")
echo
print_and_execute set_endDate
print_and_execute reset_password
print_and_execute reset_recovery
print_and_execute deprovision
print_and_execute set_org_unit
print_and_execute remove_directory
print_and_execute forward_emails
print_and_execute set_autoreply
print_and_execute transfer_drive
print_and_execute transfer_calendar
echo
break
;;
*)
echo
print_warning "Invalid selection, please try again."
echo
break
;;
esac
done
}
# -------------------------------
# 6. Script Entry Point
# -------------------------------
# Check the last update date
if [[ -z "${GAM_LAST_UPDATE:-}" ]]; then
print_info "GAM_LAST_UPDATE variable is not set in the config file."
update_gam
else
LAST_UPDATE_DATE=$(date -j -f "%Y-%m-%d" "${GAM_LAST_UPDATE}" "+%s")
CURRENT_DATE_SECS=$(date -j -f "%Y-%m-%d" "${TODAY}" "+%s")
SECONDS_DIFF=$((CURRENT_DATE_SECS - LAST_UPDATE_DATE))
DAYS_SINCE_LAST_UPDATE=$((SECONDS_DIFF / 86400))
if [ "${DAYS_SINCE_LAST_UPDATE}" -ge "${UPDATE_INTERVAL_DAYS}" ]; then
print_info "Checking for updates."
update_gam
else
print_info "GAM was updated ${DAYS_SINCE_LAST_UPDATE} days ago. Skipping update."
fi
fi
#Check for arguments
if [[ $# -ge 1 ]]; then
echo
offboard_user="$1"
receiving_user="${2:-}"
echo
else
echo
print_warning "You ran the script without adequate arguments."
echo
read -r -p "Input the email address of the USER TO OFFBOARD from Google Workspace, followed by [ENTER] " offboard_user
offboard_user=$(echo "$offboard_user" | tr '[:upper:]' '[:lower:]')
echo
read -r -p "Input the email address of the USER TO RECEIVE from ${offboard_user}, followed by [ENTER] " receiving_user
receiving_user=$(echo "$receiving_user" | tr '[:upper:]' '[:lower:]')
echo
fi
handle_help "$@"
initialize_logging | tee -a "${INFO_LOG}"
unsuspend | tee -a "${INFO_LOG}"
confirm_inputs
# Display the menu and handle user selection
while true; do
echo
main_menu
echo | tee -a "${INFO_LOG}"
echo "----------------------------------------" | tee -a "${INFO_LOG}"
echo | tee -a "${INFO_LOG}"
read -r -p "Would you like to perform another operation? (y/n): " yn
case "$yn" in
[Yy]*)
;;
[Nn]*)
suspend | tee -a "${INFO_LOG}"
task_exit | tee -a "${INFO_LOG}"
break
;;
*)
print_warning "Please answer Y or N."
;;
esac
echo
done
end_logger | tee -a "${INFO_LOG}"
cd "$INITIAL_WORKING_DIRECTORY"
#Heavily inspired by Sean Young's [deprovision.sh](https://github.com/seanism/IT/tree/5795238dc1309f245d939c89e975c805dda745f3/GAM)