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


def setup(interactive=True):
    dir_path = utils.get_dir(__file__)
    servers = ''
    if utils.get_conf('NTP_SERVER'):
        for server in utils.get_conf('NTP_SERVER').split(','):
            if server.strip():
                servers += 'pool %s\n' % server.strip()
    if not servers:
        servers = 'pool ntp.ubuntu.com\n'
    cmds = [
        # NTP
        'DEBIAN_FRONTEND=noninteractive apt-get install -y ntp',
        'echo "Replacing /etc/ntp.conf"',
        dict(line='write', template='%s/ntp.conf' % dir_path, target='/etc/ntp.conf', params=(
            ('{{ servers }}', servers),
        )),
        'systemctl restart ntp.service',
    ]
    utils.run_commands(cmds)