-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpantheon-offboard
executable file
·96 lines (81 loc) · 2.56 KB
/
pantheon-offboard
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
#!/bin/bash
# Bash script to offboard a staff member:
# * Remove them from the Pantheon organization
# * Remove them from each site
# * Block any user account in each environment.
# Include all of the subscripts that we need.
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/functions/pantheon-script-colours"
. "$DIR/functions/pantheon-get-framework"
#set -x
EMAIL=$1
if [ "$EMAIL" == "" ]; then
read -p "${UNDERLINE}What email address should be offboarded?${NOUNDERLINE} " EMAIL
fi
echo ""
echo "$EMAIL will be:"
echo "* Removed from your Pantheon organization."
echo "* Removed from all Pantheon sites."
echo "* Blocked in all environments."
echo ""
CONFIRM=$2
if [ "$CONFIRM" != "y" ]; then
read -p "${UNDERLINE}Confirm (Y/${BOLD}N${NOBOLD}) ${NOUNDERLINE}" confirm
case $confirm in
[Yy]) ;;
*)
echo "abort."
exit
;;
esac
fi
echo "This will take a really long time..."
sites=`terminus site:list --format=list --field=name | sort`
## D7
#sites="aftorg"
## D8
#sites="columbia-sps"
## D9
#sites="advotools"
## WP
#sites="advomatic"
for site in $sites; do
FRAMEWORK=''
get_framework "$site" FRAMEWORK
environments=`terminus env:list $site --format=list --field=id --filter='initialized=1'`
for environment in $environments; do
echo "Blocking from $FRAMEWORK $site.$environment"
case $FRAMEWORK in
drupal)
# Need to '-q' to avoid 'Unable to find a matching user' error.
terminus -y -q drush ${site}.${environment} -- user-block --mail=$EMAIL
;;
drupal8)
# Need to '-q' to avoid muddying the output with
# "this site is in git mode" messages.
name=`terminus -y -q drush ${site}.${environment} -- user-information --mail=$EMAIL --field=name`
if [ "$name" != "" ]; then
# Need to '-q' to avoid 'Unable to find a matching user' error.
terminus -y -q drush ${site}.${environment} -- user-block $name
fi
;;
wordpress)
# WP doesn't have a concept of "blocking" an account, so instead,
# reset their password.
terminus -y -q wp ${site}.${environment} -- user reset-password $EMAIL --skip-email
;;
*)
echo "Don't know how to handle framework $FRAMEWORK"
;;
esac
done
echo "Removing from $site"
terminus -y site:team:remove $site $EMAIL
done
organizations=`terminus org:list --format=list --field=name`
for organization in $organizations; do
echo "Removing from $organization"
terminus org:people:remove $organization $EMAIL
done
echo -e "Thanks. All done."