-
Notifications
You must be signed in to change notification settings - Fork 3
/
pantheon-module-report
executable file
·108 lines (92 loc) · 3.98 KB
/
pantheon-module-report
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
#!/bin/bash
# Bash script to get a report of which sites are running a module, at which version.
# 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"
. "$DIR/functions/drupal/drupal-get-drush-version"
#set -x
MODULE=$1
if [[ -z "$MODULE" ]]; then
read -p "${UNDERLINE}What module do you want a report about? Enter its machine name. e.g. print To test Drupal Core, type system:${NOUNDERLINE} [system] " MODULE
if [[ -z "$MODULE" ]]; then
MODULE='system'
fi
fi
VERBOSITY=$2
if [[ -z "$VERBOSITY" ]]; then
read -p "${UNDERLINE}Also list sites that don't have the module? (Y/${BOLD}N${NOBOLD})${NOUNDERLINE} [N] " VERBOSITY
case $VERBOSITY in
[Yy])
VERBOSITY=y
;;
*)
VERBOSITY=n
;;
esac
fi
ORG=$3
if [[ -z "$ORG" ]]; then
read -p "${UNDERLINE}Do you want to check sites in a specific Pantheon organization? Enter the organization name, e.g. four-kitchens:${NOUNDERLINE} [ ] " ORG
fi
TAG=$4
if [[ -z "$TAG" && -n "$ORG" ]]; then
read -p "${UNDERLINE}Do you want to check sites with a certain tag? Enter the tag name, e.g. cc-d7, cc-d9, cc-drupal:${NOUNDERLINE} [ ] " TAG
echo -e "${PROTIP} You can use these answers as arguments of this script to get to this point faster. E.g. \`pantheon-module-report system n four-kitchens cc-drupal\`"
fi
echo -e "Searching sites..."
if [[ -n "$ORG" ]]; then
if [[ -n "$TAG" ]]; then
sites=$(terminus org:site:list ${ORG} --format=list --field=name --filter="frozen!=1" --tag=${TAG} | sort)
else
sites=$(terminus org:site:list ${ORG} --format=list --field=name --filter="frozen!=1" | sort)
fi
else
sites=$(terminus site:list --format=list --field=name --filter="frozen!=1" | sort)
fi
# for debugging purposes, you may want to set 'sites' to a specific site or string of sites
#sites=('bric')
for site in $sites; do
FRAMEWORK=''
get_framework "$site" FRAMEWORK
case $FRAMEWORK in
drupal|drupal8)
# Sometimes the live environment doesn't exist yet, or there are errors in settings.php that prevent CLI commands.
for environment in 'live' 'dev'; do
drushmajorversion=''
drushminorversion=''
drushpointversion=''
drupal_get_drush_version "$site" $FRAMEWORK "$environment" drushmajorversion drushminorversion drushpointversion
# Unfortunately, there are different commands depending on what version of Drush.
if [ "$drushmajorversion" -ge 9 ]; then
drushoutput=$(terminus drush ${site}.${environment} -- pm-list --fields=name,status,version --format=string --filter="name=$MODULE" 2>&1 | fgrep -v 'not found' | fgrep -v 'Could not resolve hostname' | fgrep -v 'Permanently added the' | fgrep -v 'Permission denied')
else
drushoutput=$(terminus drush ${site}.${environment} -- pm-info --fields=extension,modulestatus,status,version --format=csv "$MODULE" 2>&1 | fgrep -v 'not found' | fgrep -v 'Could not resolve hostname' | fgrep -v 'Permanently added the' | fgrep -v 'Permission denied')
fi
modulestatus=$(echo "$drushoutput" | fgrep -i 'enabled')
trynext=$(echo "$drushoutput" | grep 'needs a higher bootstrap level\|command terminated abnormally\|option does not exist')
if [ -n "$trynext" ]; then
if [ "$environment" == 'dev' ]; then
echo "$site: Could not run drush commands against the live or dev environments."
break
fi
else
if [ "$modulestatus" == "" ] && [ $VERBOSITY == 'y' ]; then
echo "$site.$environment : not found or not enabled"
elif [ "$modulestatus" ]; then
echo "$site.$environment : $modulestatus"
fi
# Don't check the next environment, we have a valid result.
break
fi
done
;;
*)
if [ $VERBOSITY == 'y' ]; then
echo "$site : not drupal"
fi
;;
esac
done
echo -e "Thanks. All done."