Created
January 22, 2015 22:04
-
-
Save clarete/aca8232bb8a9278fe0e5 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/sh | |
BOTOFILE=${HOME}/.boto | |
### Helpers | |
helper_profile_name() { | |
printf $(basename $1) | cut -d. -f3 | |
} | |
### List all the configuration files we have for boto | |
botocfg_list() { | |
for i in $(ls ${HOME}/.boto.*) ; do | |
chosen=" " | |
name=$(helper_profile_name $i) | |
[ "$name" = "$(botocfg_get)" ] && chosen=* | |
printf " [ %s ] %s (%s)\n" "$chosen" "$name" "$i" | |
done | |
} | |
### Get the current boto file in use | |
botocfg_get() { | |
if [ -f $BOTOFILE ] ; then | |
file=$(readlink $BOTOFILE) | |
helper_profile_name $file | |
fi | |
} | |
### Set the current | |
botocfg_set() { | |
name=$1 | |
# clean up old references if it's a link | |
[ -L $BOTOFILE ] && rm $BOTOFILE; | |
# We should bail out if the .boto file is not a link. We don't | |
# want to delete user created data | |
[ -f $BOTOFILE ] && { | |
echo "ERROR: This script doesn't know how to manage your file '$BOTOFILE'" | |
echo | |
echo "Move your '$BOTOFILE' to '$BOTOFILE.something' and then call" | |
echo "this script with -s specifying which file should be the main one:" | |
echo | |
echo " $ $(basename $0) -s something" | |
exit 1 | |
} | |
# Create the link between $BOTOFILE.$name and $BOTOFILE | |
if [ -f $BOTOFILE.$name ] ; then | |
ln -s $BOTOFILE.$name $BOTOFILE | |
else | |
echo "ERROR: File $BOTOFILE.$name does not exist, can't proceed." | |
fi | |
} | |
### Parse arguments and call one of the `botocfg_*` functions | |
ARGS=$(getopt -o lgs:a: -l "list,get,set:,add:" -n "$1" -- "$@"); | |
eval set -- "$ARGS"; | |
while true ; do | |
case "$1" in | |
-l|--list) botocfg_list ; shift ;; | |
-g|--get) botocfg_get ; shift ;; | |
-s|--set) botocfg_set $2 ; shift 2 ;; | |
-a|--add) botocfg_add $2 ; shift 2 ;; | |
--) shift ; break ;; | |
*) "Failed to parse command line arguments" ; exit 1 ;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment