Last active
August 29, 2015 14:05
-
-
Save kyleskrinak/1384d1419793ac310acb to your computer and use it in GitHub Desktop.
Create all drush site aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# determine location of this script | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# load server list that these functions loop through | |
source $DIR/aliasservers.sh | |
# identify all drupal sites | |
listAllSites () { | |
for i in ${allservers[@]} | |
do | |
ssh -tq $i bash -c "' | |
hostname | |
cd /var/www/drupal/sites | |
find . -maxdepth 1 -type d -not -path "./all*" -not -path "./RCS*" -not -path . | sort | |
echo | |
'" | |
done | |
} | |
# create a new alias file that points at all new sites | |
updateAllAliases () { | |
rHostname="" | |
echo "$INSERTPARENT" | |
echo | |
for i in ${allservers[@]} | |
do | |
# capture the currend IFS value, | |
# set it back when done | |
OLDIFS=$IFS | |
IFS='%' | |
# capture the server name | |
# we can determine live or staging based on it | |
rHostname=$(ssh $i "hostname") | |
# run drush sa on server | |
result=$(catchOutput $i) | |
# change the alias name to the first dot name | |
# if staging add '-staging' to alias name | |
DWSSTRING="" | |
# this helps drush identify the machine to target | |
# for the drush command | |
REMOTESTRING="'remote-host' => '${rHostname}'," | |
# does the server name have 'staging" in it? | |
# if so change the alias name and set the dws_sitescan name | |
# appropriately | |
if [[ $rHostname == *staging* ]] | |
then | |
result=`echo "$result" | sed "s/\(^\\$aliases\['[^.]*\)[^']*\('.*$\)/\1-staging\2/g"` | |
DWSSTRING=" 'dws_sitescan' => array('groups' => array('all','staging'))," | |
else | |
result=`echo "$result" | sed "s/\(^\\$aliases\['[^.]*\)[^']*\('.*$\)/\1\2/g"` | |
DWSSTRING="'dws_sitescan' => array('groups' => array('all','prod'))," | |
fi | |
# remove the unnecessary 'root' row from result | |
result=`echo "$result" | sed "/root/d"` | |
# add the drushal-up string | |
PARENTSTRING="'parent' => '@drushal-up'," | |
result=`echo "$result" | sed "/uri/ i\ | |
${PARENTSTRING}\ | |
"` | |
# Add the appropriate dws_sitescan info | |
result=`echo "$result" | sed "/uri/ a\ | |
"${DWSSTRING}"\ | |
"` | |
# Add the appropriate remote-host string | |
result=`echo "$result" | sed "/uri/ a\ | |
"${REMOTESTRING}"\ | |
"` | |
# How'm I doin? | |
echo "$result" | |
IFS=$OLDIFS | |
done | |
} | |
# pass the result of the drush sa function to a variable so we can process the strings | |
function catchOutput() { | |
ssh -tq $1 << EOF | |
/usr/local/etc/drush/drush -r /var/www/drupal sa @sites --full | sed -e 's/.var.www.drupal#//g' | |
EOF | |
} | |
# list all modules by dir name | |
listAllModules () { | |
for i in ${allservers[@]} | |
do | |
ssh -tq $i bash -c "' | |
hostname | |
cd /var/www/drupal/sites/all/modules | |
find . -maxdepth 1 -type d | sort | |
echo | |
'" | |
done | |
} | |
# list all modules all libraries by dir name | |
listAllModulesLibraries () { | |
for i in ${allservers[@]} | |
do | |
ssh -tq $i bash -c "' | |
hostname | |
cd /var/www/drupal/sites/all | |
find . -maxdepth 2 -type d | sort | |
echo | |
'" | |
done | |
} | |
# find the bloat | |
listAllHomeFiles () { | |
for i in ${allservers[@]} | |
do | |
ssh -tq $i bash -c "' | |
hostname | |
du -s --human-readable | sort --human-numeric-sort | |
'" | |
done | |
} | |
function duf { | |
du -k "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}t${fname}"; break; fi; size=$((size/1024)); done; done | |
} | |
# this line, below, lets you call a function by passing it's name as an argument | |
$@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment