#!/bin/bash
set -eu

BASE=$(readlink -f $(dirname $0)/..)
VENV_HOME=$BASE/openstack-tools

if [ ! -f $VENV_HOME/bin/activate ]; then
  virtualenv --setuptools $VENV_HOME
fi

# NOTE(derekh): we need to use +u to workaround an issue with the activate script
# /opt/stack/new/tripleo-incubator/openstack-tools/bin/activate: line 8: _OLD_VIRTUAL_PATH: unbound variable
set +u
source $VENV_HOME/bin/activate
set -u

# Need setuptools>=1.0 to manage connections when
# downloading from pypi using http_proxy and https_proxy
pip install -U 'setuptools>=1.0'

# bug #1293812 : Avoid easy_install triggering on pbr as easy_install is
# fragile.
pip install -U 'pbr>=0.5.21,<1.0'

pip install -U python-cinderclient python-novaclient python-glanceclient python-heatclient python-keystoneclient python-neutronclient python-swiftclient python-ironicclient python-openstackclient python-ceilometerclient os-apply-config os-cloud-config

for tool in os-apply-config cinder nova glance heat keystone neutron swift ironic ceilometer openstack init-keystone generate-keystone-pki register-nodes setup-neutron; do
  ln -sf $VENV_HOME/bin/$tool $BASE/scripts/$tool ;
done
echo "Installed openstack client tool symlinks in $BASE/scripts"
