-
-
Save fairchild/164053 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
export JAVA_HOME=/Library/Java/Home #/usr on ubuntu | |
#export EC2_HOME=~/opt/ec2 | |
export PATH=$EC2_HOME/bin:$PATH | |
export EC2_CONTEXTS_DIR=~/.ec2 | |
export EC2_CONFIG_DIR=$EC2_CONTEXTS_DIR/current | |
ec2-switch-context() { | |
unset EC2_URL | |
unset S3_URL | |
unset EC2_PRIVATE_KEY | |
unset EC2_CERT | |
unset EC2_ACCESS_KEY | |
unset EC2_SECRET_KEY | |
unset EC2_USER_ID | |
unset AWS_ACCESS_KEY | |
unset AWS_ACCESS_KEY_ID | |
unset AWS_SECRET_ACCESS_KEY | |
unset AWS_SECRET_ACCESS_KEY_ID | |
unset AMAZON_ACCESS_KEY_ID | |
unset AMAZON_SECRET_ACCESS_KEY | |
if [[ -z $1 || ! -d $EC2_CONTEXTS_DIR/$1 ]]; then | |
echo "Usage: ec2-switch-context <context_name>"; | |
return 1; | |
fi | |
echo "Switching to ec2 context: $1" | |
rm -rf $EC2_CONTEXTS_DIR/current | |
ln -Fs $EC2_CONTEXTS_DIR/$1 $EC2_CONTEXTS_DIR/current; | |
ec2-reload-current-context; | |
} | |
ec2-reload-current-context() { | |
if [ ! -d $EC2_CONFIG_DIR ]; then | |
echo "There's no 'current' context defined"; | |
return 1; | |
fi | |
if [ -f $EC2_CONFIG_DIR/pk-*.pem ]; then | |
export EC2_PRIVATE_KEY=`ls $EC2_CONFIG_DIR/*pk*.pem`; | |
fi | |
if [ -f $EC2_CONFIG_DIR/cert-*.pem ]; then | |
export EC2_CERT=`ls $EC2_CONFIG_DIR/*cert*.pem`; | |
fi | |
if [ -f $EC2_CONFIG_DIR/envrc ]; then | |
. $EC2_CONFIG_DIR/envrc; | |
fi | |
if [ -f $EC2_CONFIG_DIR/environment ]; then | |
. $EC2_CONFIG_DIR/environment; | |
fi | |
if [ -f $EC2_CONFIG_DIR/eucarc ]; then | |
. $EC2_CONFIG_DIR/eucarc; | |
fi | |
export AWS_SECRET_ACCESS_KEY=$EC2_SECRET_KEY | |
export AWS_ACCESS_KEY=$EC2_ACCESS_KEY | |
export AWS_ACCESS_KEY_ID=$EC2_ACCESS_KEY | |
export AWS_SECRET_ACCESS_KEY_ID=$EC2_SECRET_KEY | |
export AMAZON_ACCESS_KEY=$EC2_ACCESS_KEY | |
export AMAZON_ACCESS_KEY_ID=$EC2_ACCESS_KEY | |
export AMAZON_SECRET_ACCESS_KEY=$EC2_SECRET_KEY | |
return 0; | |
} | |
_ec2_contexts() { | |
COMPREPLY=($(compgen -W "$(ls $EC2_CONTEXTS_DIR | grep -v 'bin\|lib\|config\|current')" -- ${COMP_WORDS[COMP_CWORD]})); | |
return 0; | |
} | |
complete -F _ec2_contexts -o default ec2-switch-context; | |
ec2-reload-current-context &> /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment