-
-
Save nicjohnson/6186293 to your computer and use it in GitHub Desktop.
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 | |
while getopts "arp:d:" opt; do | |
case $opt in | |
a) | |
adding=true | |
;; | |
r) | |
adding=false | |
;; | |
p) | |
prefix=$OPTARG | |
;; | |
d) | |
drain=$OPTARG | |
;; | |
\?) | |
echo "Unknown option -$OPTARG" | |
exit 1; | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument" | |
exit 1; | |
esac | |
done | |
if [ -z $adding ] ; then | |
echo "usage (-a or -r) -d 'drainurl' [OPTIONAL: -p 'App_prefix']" | |
exit 1 | |
fi | |
if [ -z $drain ] ; then | |
echo "You haven't defined a drain" | |
exit 1 | |
fi | |
if [ -z $prefix ] ; then | |
read -r -p "Are you sure you have no app prefix? [y/N] " response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
;; | |
*) | |
echo 'Please try again' | |
exit 1; | |
;; | |
esac | |
fi | |
function processDrain { | |
if [[ $adding == true ]] ; then | |
addDrain $1 | |
else | |
removeDrain $1 | |
fi | |
} | |
function addDrain { | |
echo "Processing ${1}"; | |
heroku drains:add ${drain} -a ${1}; | |
} | |
function removeDrain { | |
echo "Processing ${1}"; | |
heroku drains:remove ${drain} -a ${1}; | |
} | |
for app in `heroku apps | grep -v =`; do | |
if [[ $app =~ "@" ]] ; then | |
true | |
elif [[ -z $prefix ]] ; then | |
processDrain $app | |
elif [[ $app =~ $prefix ]] ; then | |
processDrain $app | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment