#!/bin/bash function check() { PREFIX="recipe:mariadb:check" dpkg -l mariadb-client | grep -q ^ii || return 9 container_running "$CONTAINER" || return 10 cat </dev/null ss -tlnp | grep 0.0.0.0:3306 | grep -q maria test -f /etc/default/automysqlbackup grep -q BACKUPDIR=\"/mnt/BACKUP/mariadb\" /etc/default/automysqlbackup EOF echo "container <$CONTAINER> approved successfully!" return 0 } function build_device_backup() { PREFIX="recipe:mariadb:backup" if ! (lxc config device list "$CONTAINER" | grep -q BACKUP); then local backup_dir="$HOME/LXD/BACKUP/databases-$CONTAINER" mkdir -p "$backup_dir" lxc config device add "$CONTAINER" BACKUP disk source=$backup_dir path=mnt/BACKUP fi } function install() { sudo_required PREFIX="recipe:mariadb:install" : $PREFIX sudo /opt/miaou-bash/tools/idem_apt_install mariadb-client echowarn "initializing ..." launch_container "$CONTAINER" build_device_backup echowarn "executing various commands onto container <$CONTAINER>, please be patient ..." lxc exec "$CONTAINER" -- bash </dev/null . /opt/miaou-bash/lib/functions.sh apt update && apt dist-upgrade -y /opt/miaou-bash/tools/idem_apt_install mariadb-server automysqlbackup echo "change bind-adress" /opt/miaou-bash/tools/append_or_replace "^bind-address.*$" "bind-address = 0.0.0.0" /etc/mysql/mariadb.conf.d/50-server.cnf systemctl restart mariadb.service function systemctl-exists() ([ \$(systemctl list-unit-files "\${1}*" | wc -l) -gt 3 ]) systemctl-exists exim4.service && systemctl stop exim4.service && systemctl disable exim4.service /opt/miaou-bash/tools/append_or_replace "^BACKUPDIR=.*$" "BACKUPDIR=\"/mnt/BACKUP/mariadb\"" /etc/default/automysqlbackup exit 0 EOF echo DONE } # MAIN . "$MIAOU_BASEDIR/lib/init.sh" arg1_required "$@" readonly CONTAINER="$1" check || ( install check )