Created
September 25, 2011 14:47
-
-
Save whaley/1240666 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| BASE_DIRECTORY=$HOME/opt/ec2/credentials/ | |
| function outputChoices { | |
| local count=0 | |
| for directory in ${directories[@]} | |
| do | |
| echo -e "$count:\t$(basename $directory)" | |
| ((count++)) | |
| done | |
| echo -n "Select one of [0-$numberOfDirectories] - any other input leaves creds unchanged: " | |
| } | |
| function changeCredDirectory { | |
| if [[ -n $(echo -n $inputChoice | grep '^[0-9][0-9]*$') && $inputChoice -ge 0 && $inputChoice -le $numberOfDirectories ]] | |
| then | |
| newCredDirectory=${directories[$inputChoice]} | |
| ln -nsf $newCredDirectory $BASE_DIRECTORY/current | |
| echo; echo "Credentials set to $newCredDirectory" | |
| else | |
| echo ;echo "Invalid selection - creds unchanged" | |
| fi | |
| } | |
| alias echo="echo -e" | |
| directories=($(find $BASE_DIRECTORY -type d -maxdepth 1 -mindepth 1)) | |
| numberOfDirectories=$(( ${#directories[@]} - 1 )) | |
| outputChoices | |
| read inputChoice | |
| changeCredDirectory | |
| unalias echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment