Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import utils
def setup(interactive=True):
# TODO: setup IP
dir_path = utils.get_dir(__file__)
cmds = [
# Locale
'locale-gen en_GB.UTF-8',
'update-locale LANG=en_GB.UTF-8 LANGUAGE=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8',
# NTP
'echo "Replacing /etc/ntp.conf"',
dict(line='write', template='%s/ntp.conf' % dir_path, target='/etc/ntp.conf', params=(
('{{ system_ntp }}', utils.get_conf('system_ntp', 'ntp.ubuntu.com')),
)),
]
# Create / update ubicast account
cmds.append('echo "Checking ubicast account"')
code, out = utils.exec_cmd(['id', 'ubicast'], get_out=True)
if code != 0:
cmds.append('useradd -m -s /bin/bash ubicast')
out = ''
if 'sudo' not in out:
cmds.append('usermod -aG sudo ubicast')
# Add SSH key
cmds.append('echo "Checking ubicast and root SSH keys"')
# root
cmds.append('mkdir -p /root/.ssh')
cmds.append('chmod 700 /root/.ssh')
if utils.exec_cmd(['rgrep', 'support@ubicast', '/root/.ssh']) != 0:
cmds.append('cat "%s/ubicast_support.pub" >> /root/.ssh/authorized_keys' % dir_path)
# ubicast
cmds.append('mkdir -p /home/ubicast/.ssh')
cmds.append('chmod 700 /home/ubicast/.ssh')
if utils.exec_cmd(['rgrep', 'support@ubicast', '/home/ubicast/.ssh']) != 0:
cmds.append('cat "%s/ubicast_support.pub" >> /home/ubicast/.ssh/authorized_keys' % dir_path)
cmds.append('chown -R ubicast:ubicast /home/ubicast/.ssh')
utils.run_commands(cmds)