+ echo -e " --charmed: Deploy and operate OSM with Charms on k8s"
+ echo -e " [--bundle <bundle path>]: Specify with which bundle to deploy OSM with charms (--charmed option)"
+ echo -e " [--k8s <kubeconfig path>]: Specify with which kubernetes to deploy OSM with charms (--charmed option)"
+ echo -e " [--vca <name>]: Specifies the name of the controller to use - The controller must be already bootstrapped (--charmed option)"
+ echo -e " [--small-profile]: Do not install and configure LXD which aims to use only K8s Clouds (--charmed option)"
+ echo -e " [--lxd <yaml path>]: Takes a YAML file as a parameter with the LXD Cloud information (--charmed option)"
+ echo -e " [--lxd-cred <yaml path>]: Takes a YAML file as a parameter with the LXD Credentials information (--charmed option)"
+ echo -e " [--microstack]: Installs microstack as a vim. (--charmed option)"
+ echo -e " [--overlay]: Add an overlay to override some defaults of the default bundle (--charmed option)"
+ echo -e " [--ha]: Installs High Availability bundle. (--charmed option)"
+ echo -e " [--tag]: Docker image tag. (--charmed option)"
+ echo -e " [--registry]: Docker registry with optional credentials as user:pass@hostname:port (--charmed option)"
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+# takes a juju/accounts.yaml file and returns the password specific
+# for a controller. I wrote this using only bash tools to minimize
+# additions of other packages
+function parse_juju_password {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ password_file="${HOME}/.local/share/juju/accounts.yaml"
+ local controller_name=$1
+ local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034')
+ sed -ne "s|^\($s\):|\1|" \
+ -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
+ -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file |
+ awk -F$fs -v controller=$controller_name '{
+ indent = length($1)/2;
+ vname[indent] = $2;
+ for (i in vname) {if (i > indent) {delete vname[i]}}
+ if (length($3) > 0) {
+ vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
+ if (match(vn,controller) && match($2,"password")) {
+ printf("%s",$3);
+ }
+ }
+ }'
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function set_vca_variables() {
+ OSM_VCA_CLOUDNAME="lxd-cloud"
+ [ -n "$OSM_VCA_HOST" ] && OSM_VCA_CLOUDNAME="localhost"
+ if [ -z "$OSM_VCA_HOST" ]; then
+ [ -z "$CONTROLLER_NAME" ] && OSM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_NAMESPACE"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
+ [ -n "$CONTROLLER_NAME" ] && OSM_VCA_HOST=`juju show-controller $CONTROLLER_NAME |grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
+ [ -z "$OSM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
+ fi
+ if [ -z "$OSM_VCA_SECRET" ]; then
+ [ -z "$CONTROLLER_NAME" ] && OSM_VCA_SECRET=$(parse_juju_password $OSM_NAMESPACE)
+ [ -n "$CONTROLLER_NAME" ] && OSM_VCA_SECRET=$(parse_juju_password $CONTROLLER_NAME)
+ [ -z "$OSM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
+ fi
+ if [ -z "$OSM_VCA_PUBKEY" ]; then
+ OSM_VCA_PUBKEY=$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)
+ [ -z "$OSM_VCA_PUBKEY" ] && FATAL "Cannot obtain juju public key"
+ fi
+ if [ -z "$OSM_VCA_CACERT" ]; then
+ [ -z "$CONTROLLER_NAME" ] && OSM_VCA_CACERT=$(juju controllers --format json | jq -r --arg controller $OSM_NAMESPACE '.controllers[$controller]["ca-cert"]' | base64 | tr -d \\n)
+ [ -n "$CONTROLLER_NAME" ] && OSM_VCA_CACERT=$(juju controllers --format json | jq -r --arg controller $CONTROLLER_NAME '.controllers[$controller]["ca-cert"]' | base64 | tr -d \\n)
+ [ -z "$OSM_VCA_CACERT" ] && FATAL "Cannot obtain juju CA certificate"
+ fi
+}
+
+function generate_secret() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function check_packages() {
+ NEEDED_PACKAGES="$1"
+ echo -e "Checking required packages: ${NEEDED_PACKAGES}"
+ for PACKAGE in ${NEEDED_PACKAGES} ; do
+ dpkg -L ${PACKAGE}
+ if [ $? -ne 0 ]; then
+ echo -e "Package ${PACKAGE} is not installed."
+ echo -e "Updating apt-cache ..."
+ sudo apt-get update
+ echo -e "Installing ${PACKAGE} ..."
+ sudo apt-get install -y ${PACKAGE} || FATAL "failed to install ${PACKAGE}"
+ fi
+ done
+ echo -e "Required packages are present: ${NEEDED_PACKAGES}"
+}
+
+function ask_user(){
+ # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
+ # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
+ # Return: true(0) if user type 'yes'; false (1) if user type 'no'
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ read -e -p "$1" USER_CONFIRMATION
+ while true ; do
+ [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
+ [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
+ [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
+ [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
+ read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
+ done
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function