Created
September 16, 2015 14:48
-
-
Save PavelVanecek/49761662fc237ba8f6c0 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 | |
CONF_FILE=~/.aws/credentials | |
function usage { | |
echo "Export AWS API keys" | |
echo "Will read $CONF_FILE and export the api keys as environment variables" | |
echo "Usage: $0 --profile <profile>" | |
} | |
# read parameters | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
-h|--help) | |
usage | |
exit 0 | |
;; | |
-p|--profile) | |
PROFILE="$2" | |
shift | |
;; | |
esac | |
shift | |
done | |
if [ -z "$PROFILE" ]; then | |
usage | |
exit 1 | |
fi | |
cat "$CONF_FILE" |\ | |
grep -F "[$PROFILE]" -A3 |\ | |
tail -n+2 |\ | |
sed "s/aws_security_token=\(.*\)/aws_security_token=\1\naws_session_token=\1/" |\ | |
sed "s/\([^=]*\)=/export \U\1=/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment