3cd12006bb
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
101 lines
3.7 KiB
Bash
Executable File
101 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
MAX_OPENRC_LEN=100
|
|
read -p "Pre-store Keystone user credentials for this session? (y/N): " confirm
|
|
confirm=${confirm,,}
|
|
|
|
if [ "$confirm" == "y" ] || [ "$confirm" = "yes" ]; then
|
|
if [ -z "$OPENRC_TEMPLATE" ] || [ ! -f `echo $OPENRC_TEMPLATE` ]; then
|
|
read -p "env[OPENRC_TEMPLATE] not set.
|
|
Hints will not be available for certain options. Continue anyways? (Y/n): " confirm
|
|
confirm=${confirm,,}
|
|
([ "$confirm" == "n" ] || [ "$confirm" == "no" ]) && exit 0
|
|
else
|
|
# Check if we are to run Muted
|
|
[ "$1" = "--mute" ] && MUTE=1
|
|
|
|
# Load default values for System URL, Region and Keystone URL
|
|
defEnv=( $(cat $OPENRC_TEMPLATE) )
|
|
defEnvLen=${#defEnv[@]}
|
|
[ "$defEnvLen" -gt "$MAX_OPENRC_LEN" ] && \
|
|
defEnvLen="$MAX_OPENRC_LEN"
|
|
for (( i=0; i<$defEnvLen; i++));
|
|
do
|
|
if [[ ${defEnv[$i]} =~ OS_AUTH_URL=(.*)$ ]]; then
|
|
def_os_auth_url=${BASH_REMATCH[1]}
|
|
elif [[ ${defEnv[$i]} =~ OS_REGION_NAME=(.*)$ ]]; then
|
|
def_os_region_name=${BASH_REMATCH[1]}
|
|
elif [[ ${defEnv[$i]} =~ OS_PROJECT_NAME=(.*)$ ]]; then
|
|
def_os_project_name=${BASH_REMATCH[1]}
|
|
elif [[ ${defEnv[$i]} =~ OS_USER_DOMAIN_NAME=(.*)$ ]]; then
|
|
def_os_user_domain_name=${BASH_REMATCH[1]}
|
|
elif [[ ${defEnv[$i]} =~ OS_PROJECT_DOMAIN_NAME=(.*)$ ]]; then
|
|
def_os_project_domain_name=${BASH_REMATCH[1]}
|
|
fi
|
|
done
|
|
fi
|
|
|
|
read -p "Enter Keystone username [$USER]: " os_user
|
|
[ -z "$os_user" ] && os_user="$USER"
|
|
|
|
read -p "Enter Keystone user domain name: " os_user_domain_name
|
|
[ -z "$os_user_domain_name" ] && os_user_domain_name="$def_os_user_domain_name"
|
|
|
|
read -p "Enter Project name: " os_project_name
|
|
[ -z "$os_project_name" ] && os_project_name="$def_os_project_name"
|
|
|
|
read -p "Enter Project domain name: " os_project_domain_name
|
|
[ -z "$os_project_domain_name" ] && os_project_domain_name="$def_os_project_domain_name"
|
|
|
|
read -s -p "Enter Keystone password: " os_pass
|
|
[ -z "$os_pass" ] && \
|
|
echo -n "Invalid password entry. Aborting!" && exit 1
|
|
|
|
# if we are not in mute mode then ask for these
|
|
# from user as input
|
|
if [ -z "$MUTE" ]; then
|
|
if [ -z "$def_os_region_name" ]; then
|
|
read -p "\n\nEnter Keystone Region Name: " os_region
|
|
else
|
|
read -p "Enter Keystone Region Name [$def_os_region_name]: " os_region
|
|
[ -z "$os_region" ] && os_region="$def_os_region_name"
|
|
fi
|
|
|
|
if [ -z "$def_os_auth_url" ]; then
|
|
read -p "Enter Keystone Authentication URL: " os_auth_url
|
|
else
|
|
read -p "Enter Keystone Authentication URL [$def_os_auth_url]: " os_auth_url
|
|
[ -z "$os_auth_url" ] && os_auth_url="$def_os_auth_url"
|
|
fi
|
|
else
|
|
# In MUTE mode
|
|
os_region="$def_os_region_name"
|
|
echo ""; echo ""
|
|
echo "Using default Openstack Region Name: $os_region"
|
|
os_auth_url="$def_os_auth_url"
|
|
echo "Using default Openstack Authentication URL: $os_auth_url"
|
|
echo "To set these to non-default, run \"source ~/$(basename $BASH_SOURCE)\" in your shell"
|
|
fi
|
|
|
|
|
|
# set user environment which will be valid for
|
|
# the duration of this session
|
|
# Since lshell is running for internal clients
|
|
# move OS ENDPOINT TYPE to internalURL
|
|
export OS_ENDPOINT_TYPE="internalURL"
|
|
export CINDER_ENDPOINT_TYPE="internalURL"
|
|
export OS_INTERFACE="internal"
|
|
export OS_USERNAME="$os_user"
|
|
export OS_PASSWORD="$os_pass"
|
|
export OS_PROJECT_NAME="$os_project_name"
|
|
export OS_USER_DOMAIN_NAME="$os_user_domain_name"
|
|
export OS_PROJECT_DOMAIN_NAME="$os_project_domain_name"
|
|
export OS_AUTH_URL="$os_auth_url"
|
|
export OS_IDENTITY_API_VERSION=3
|
|
export OS_REGION_NAME="$os_region"
|
|
# modify PS1 prompt
|
|
newprompt="[\u@\h \W($os_user)]\$ "
|
|
export PS1="$newprompt"
|
|
echo ""
|
|
echo "Keystone credentials preloaded!"
|
|
fi
|