#!/bin/bash
instance=$1
if [ -z "$instance" ]; then
    echo "Usage: $0 instance"
    exit 1
fi
AUTO_CNF_PLACE="/opt/mysql.$instance/auto.cnf"
if echo $instance | grep -q 'ppcdata'
   then AUTO_CNF_PLACE="/opt/mysql.$instance/data/auto.cnf"
fi
echo "before: $(grep uuid $AUTO_CNF_PLACE)"
perl -e 'chomp($host = qx(hostname -f)); @md5 = split //, qx(echo "$host" | md5sum); printf "[auto]\nserver-uuid=%s\n", join "-", map { join("", @md5[@{$_}]) } ([0..7], [8..11], [12..15], [16..19], [20..31])' > "$AUTO_CNF_PLACE"
chown mysql: "$AUTO_CNF_PLACE"
echo "after:  $(grep uuid $AUTO_CNF_PLACE)"
