#!/bin/bash set -e if [ -d '/var/lib/mysql' ]; then read -p 'mariadb seems to be installed already - I will remove it first.' -r s if [ -n "${s}" ]; then echo 'Aborted.' exit fi sudo systemctl stop mysqld || true sudo systemctl disable mysqld || true sudo pacman -Rs mariadb || true sudo rm -rf --one-file-system '/var/lib/mysql' '/etc/mysql' fi if [ -d '/etc/stunnel' ]; then read -p 'stunnel seems to be installed already - I will remove it first.' -r s if [ -n "${s}" ]; then echo 'Aborted.' exit fi sudo systemctl stop stunnel || true sudo systemctl disable stunnel || true sudo pacman -Rs stunnel || true sudo rm -rf --one-file-system '/etc/stunnel' fi read -p 'enter new root-pw: ' -s -r root_pw printf '\n' read -p 'enter replikat-pw: ' -s -r replikat_pw printf '\n' sudo pacman -S --noconfirm mariadb stunnel # set up mariadb sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql sudo sed -i ' /^\s*\[mysqld]\s*$/ a group_concat_max_len = 4096 \ server-id = '"$RANDOM"' \ skip-networking ' '/etc/my.cnf.d/server.cnf' sudo systemctl start mysqld sudo systemctl enable mysqld printf '\n\n\n%s\n%s\n\n\n\n\n' "${root_pw}" "${root_pw}" | \ sudo mysql_secure_installation # set up stunnel sudo tee /etc/stunnel/stunnel.conf > /dev/null < "${tmp_file}" { printf 'SHOW SLAVE STATUS;\n' printf "CREATE USER 'webserver'@'localhost' IDENTIFIED BY 'empty';\n" \ printf "GRANT USAGE ON *.* TO 'webserver'@'localhost' IDENTIFIED BY 'empty';\n" printf "GRANT REPLICATION CLIENT ON *.* TO 'webserver'@'localhost';\n" printf 'GRANT %s ON buildmaster.* TO '"'"'webserver'"'"'@'"'"'localhost'"'"';\n' \ 'CREATE TEMPORARY TABLES' \ 'SELECT' \ 'SHOW VIEW' printf "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%s, MASTER_USER='%s', MASTER_PASSWORD='%s';\n" \ '127.0.0.1' \ 33061 \ 'replikat' \ "${replikat_pw}" xzcat "${tmp_file}" | pv xzgrep -- '^-- CHANGE MASTER TO ' "${tmp_file}" | \ sed 's/^-- //' printf 'START SLAVE;\n' printf 'SHOW SLAVE STATUS;\n' } | \ mysql -u root -p"${root_pw}" printf '\n\nAll set up successfully.\n'