Skip to content
Snippets Groups Projects
0_setup.py 1.02 KiB
Newer Older
#!/usr/bin/env python3
Stéphane Diemer's avatar
Stéphane Diemer committed
# -*- coding: utf-8 -*-
import utils


def setup(interactive=True):
    dir_path = utils.get_dir(__file__)
    cmds = [
        'DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server mysql-client',
        'cp "%s/mysql.cnf" "/etc/mysql/mysql.cnf"' % dir_path,
        '[ -L /etc/mysql/my.cnf ] || (mv /etc/mysql/my.cnf /etc/mysql/my.cnf.back && ln -sfn /etc/mysql/mysql.cnf /etc/mysql/my.cnf)',  # Compatibility with mysql 5.5
        'mkdir -p /etc/systemd/system/mysql.service.d',
        'cp "%s/override.conf" "/etc/systemd/system/mysql.service.d/override.conf"' % dir_path,
        '/etc/init.d/mysql restart',
    ]
    MYSQL_ROOT_PWD = utils.get_conf('MYSQL_ROOT_PWD')
    if MYSQL_ROOT_PWD:
Stéphane Diemer's avatar
Stéphane Diemer committed
        # Set password if any
        cmds.append('mysqladmin -u root password "%s"' % MYSQL_ROOT_PWD)
Stéphane Diemer's avatar
Stéphane Diemer committed
    utils.run_commands(cmds)

    if not MYSQL_ROOT_PWD:
Stéphane Diemer's avatar
Stéphane Diemer committed
        utils.log('No root password was set in the configuration file.\nUse the following command to change it:\n    mysqladmin -u root password <pwd>')