#!/usr/bin/env bash
# 文件名: replication-setup.sh

source $(dirname $0)/.vars.conf

sed  -e "s!#mysql_repl_user#!${mysql_repl_user}!" \
     -e "s!#mysql_repl_pass#!${mysql_repl_pass}!" \
     templates/master.sh.tpl > templates/master.sh

sed  -e "s!#mysql_master_ip#!${mysql_master_ip}!" \
     -e "s!#mysql_repl_user#!${mysql_repl_user}!" \
     -e "s!#mysql_repl_pass#!${mysql_repl_pass}!" \
     templates/slave.sh.tpl > templates/slave.sh

for ip in ${mysql_master_ip}
do
    scp ${ssh_options} templates/master.sh ${ip}:/tmp
    ssh ${ssh_options} root@${ip} "bash /tmp/master.sh"
done

for ip in ${mysql_slave_ip}
do
    scp ${ssh_options} templates/slave.sh ${ip}:/tmp
    ssh ${ssh_options} root@${ip} "bash /tmp/slave.sh"
done
