#!/bin/sh
set -ex

# Author: Robie Basak <robie.basak@canonical.com>
# Test manual provider against localhost

# Avoid catching 127.0.0.1, since this can't be reached by a proxy if a proxy
# is in use.
ip=`ip -o -4 addr show|awk '{print $4}'|cut -f1 -d/|grep -v '^127.0.0.1$'|head -1`

mkdir -pm700 ~/.ssh
ssh-keygen -f ~/.ssh/id_rsa -N ''
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh-keyscan "$ip" >> ~/.ssh/known_hosts

mkdir -p ~/.local/share/juju/
cat > ~/.local/share/juju/clouds.yaml <<EOT
clouds:
  manual:
    type: manual
EOT
cat ~/.local/share/juju/clouds.yaml
juju bootstrap my-controller manual/$ip --upload-tools --debug
