#!/bin/bash

# Pre-exec
status-set maintenance "installing charm helpers"
if [[ -d exec.d ]]; then
    shopt -s nullglob
    for f in exec.d/*/charm-pre-install; do
    [[ -x "$f" ]] || continue
    ${SHELL} -c "$f"|| {
        ## bail out if anyone fails
        juju-log -l ERROR "$f: returned exit_status=$? "
        exit 1
    }
    done
fi

status-set maintenance "installing dependencies"
apt-get update
apt-get install -y debconf-utils python-mysqldb uuid pwgen dnsutils || exit 1

PASSFILE=/var/lib/mysql/mysql.passwd
if ! [ -f $PASSFILE ] ; then
  mkdir -p /var/lib/mysql
  touch $PASSFILE
fi
chmod 0600 $PASSFILE
if ! [ -s $PASSFILE ] ; then
  uuid > $PASSFILE
fi
