#!/bin/bash
set -ex
source charms.reactive.sh
@when 'mysql.available'
@when 'apt.mysql-client.installed'
function run_mysql_commands(mysql) {
'' Run database migrations, not idempotent, and this method will
require additional work to pass review '''
# there is no library support here, so you will need to use a
# bash compliant tempting language if required. I chose sed for
# this operation. Comments left inline for clarity of approach.
# $ cat template.txt
# the number is ${i}
# the dog's name is ${name}
# $ cat replace.sed
# s/${i}/5/
# s/${name}/Fido/
sed -f replace.sed template.txt > out.txt
# $ cat out.txt
# the number is 5
# the dog's name is Fido
mysql -h ${mysql.host()}:${mysql.port()} -u ${mysql.username()} -p${mysql.password()}
}
reactive_handler_main