Last active
July 15, 2016 16:01
-
-
Save al4/3fafd7636d2c2ada3b945f6cb9df5779 to your computer and use it in GitHub Desktop.
Prompt to select openstack environment
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
#!/usr/bin/env bash | |
function osauth() { | |
osauth_dir="~/.osauth" | |
# List files in ~/.osauth | |
tenant_paths=(~/.osauth/*.sh) | |
# Strip the leading path | |
tenant_files=(${tenant_paths[@]#~/.osauth/}) | |
# Strip the trailing file name | |
tenants=(${tenant_files[@]/-openrc.sh/}) | |
if [ ${#tenants[@]} -eq 1 ]; then | |
mytenant=${tenants[0]} | |
else | |
osauth_chooser | |
fi | |
echo "$mytenant selected" | |
for file in ${tenant_paths[@]}; do | |
# Determine if $file contains $mytenant | |
if contains "$file" "$mytenant"; then | |
source $file | |
fi | |
done | |
} | |
function osauth_chooser() { | |
PS3="Select an Openstack tenant: " | |
select option in ${tenants[@]}; do | |
mytenant=$option | |
break | |
done | |
} | |
function contains() { | |
string="$1" | |
substring="$2" | |
if test "${string#*$substring}" != "$string" | |
then | |
return 0 # $substring is in $string | |
else | |
return 1 # $substring is not in $string | |
fi | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment