Skip to content
Snippets Groups Projects
0_setup.py 705 B
Newer Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import utils


def setup(interactive=True):
    db_host = utils.get_conf('DB_HOST')
Nicolas KAROLAK's avatar
Nicolas KAROLAK committed
    db_port = utils.get_conf('DB_PORT')
    if (db_host and not db_host.startswith('127') and db_host != 'localhost') or db_port != 5432:
        utils.log('Skipping postgresql setup because the database host is set to "%s:%i".' % (db_host, db_port))
        return
    cmds = [
        'DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql',
    ]
    root_pwd = utils.get_conf('DB_PG_ROOT_PWD')
    if root_pwd:
        cmds.append('sudo su - postgres -c "psql -w -q -A -c \\"ALTER USER postgres WITH PASSWORD \'%s\';\\""' % root_pwd)
    utils.run_commands(cmds)