def install_pyenv():
    user_info       = config['user']
    pyenv           = config['pyenv']
    python          = config['python']
    users           = user_info['accounts']
    git_url         = pyenv['git_url']
    git_update_url  = pyenv['update_git_url']
    
    pi_user = User(install_user, False, True)
    pi_user.password = install_password
    users.append(pi_user)

    for user in users:
        switch_user(user.name, user.password)

        home_path   = get_user_home_dir(user.name)
        pyenv_path  = os.path.join(home_path, '.pyenv')
        update_path = os.path.join(pyenv_path, 'plugins', 'pyenv-update')

        cmd = 'mkdir -p %s' % (pyenv_path)
        run(cmd)

        cmd = 'git clone %s %s' % (git_url, pyenv_path)
        run(cmd)

        update_path = os.path.join(pyenv_path, 'plugins', 'pyenv-update')
        cmd = 'git clone %s %s' % (git_update_url, update_path)
        run(cmd)

        setup_pyenv(user)
        setup_python(user, python)
def remove_pi_user():
    user_info = config['user']
    admin_user = get_admin_user(user_info)

    switch_user(admin_user.name, admin_user.password)

    cmd = 'deluser -r pi'
    sudo(cmd)
def cleanup_opt():
    unwanted_apps = ['minecraft-pi', 'sonic-pi', 'Wolfram']
    switch_user(install_user, install_password)

    for app in unwanted_apps:
        app_path = os.path.join('/opt', app)
        cmd = 'rm -rf {}'.format(app_path)
        sudo(cmd)
def install_service():
    service_file = config['service_file']

    switch_user(install_user, install_password)
    put(service_file, '/etc/systemd/system/home-assistant.service', use_sudo=True)

    cmd = 'systemctl enable home-assistant'
    sudo(cmd)

    cmd = 'systemctl start home-assistant'
    sudo(cmd)
def create_users():
    user_info   = config['user']
    users       = user_info['accounts']
    dirs        = user_info['dirs']

    for user in users:
        switch_user(install_user, install_password)
        create_user(user)

        if not user.home_assistant_user:
            switch_user(user.name, user.password)
            create_user_dirs(user, dirs)
def test():
    switch_user(install_user, install_password)
    cmd = 'ps -ef | grep python'
    result = run(cmd)

    lines = result.split('\n')

    print(len(lines))
    print(lines[0].split()[1])
    print(lines[0].split())
    print(lines[1].split())

    if len(lines) > 2:
        print(lines[2].split())
def install_firewall():
    firewall = config['firewall']

    if firewall['enable']:
        switch_user(install_user, install_password)
        packages = ['ufw', 'GUFW']
        install_native(packages)

        cmd = 'ufw default deny incoming'
        sudo(cmd)

        cmd = 'ufw default allow outgoing'
        sudo(cmd)

        for app in firewall['allowed']:
            cmd = 'ufw allow %s' % (app)
            sudo(cmd)

        cmd = """echo "y" | sudo ufw enable"""
        run(cmd)
def install_mqtt():
    user_info               = config['user']
    admin_user              = get_admin_user(user_info)
    mos_srv_user            = get_mosquitto_user(user_info)
    mqtt                    = config['mqtt']
    app_dir                 = mqtt['dir']
    system_libs             = mqtt['system_libs']
    users                   = mqtt['users']

    switch_user(admin_user.name, admin_user.password)

    app_path = os.path.join('/opt', app_dir)
    cmd = 'mkdir -p {}'.format(app_path)
    sudo(cmd)

    with cd(app_path):
        run("wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key")
        sudo("apt-key add mosquitto-repo.gpg.key")

        with cd("/etc/apt/sources.list.d/"):
            sudo("wget http://repo.mosquitto.org/debian/mosquitto-jessie.list")
            install_native(system_libs)

            with cd("/etc/mosquitto"):
                put("./files/mosquitto.conf", "mosquitto.conf", use_sudo=True)
                sudo('chown root:root mosquitto.conf')
                sudo("touch pwfile")

                cmd = 'chown {}:{} pwfile'.format(mos_srv_user.name, mos_srv_user.name)
                sudo(cmd)
                sudo("chmod 0600 pwfile")

                switch_user(mos_srv_user.name, mos_srv_user.password)

                for user in users:
                    cmd = 'sudo mosquitto_passwd -b pwfile {} {}'.format(user.name, user.password)
                    sudo(cmd)

    cmd = 'chown -R {}:{} {}'.format(mos_srv_user.name, mos_srv_user.name, app_path)
    sudo(cmd)
def install_openzwave_ctrl():
    user_info               = config['user']
    ha_user                 = get_ha_user(user_info)
    ha_path                 = os.path.join('/srv', root_path)
    openzwave_ctrl          = config['openzwave_ctrl']
    openzwave_dir           = openzwave_ctrl['dir']
    install_dir             = openzwave_ctrl['install_dir']
    git_url                 = openzwave_ctrl['git_url']

    switch_user(install_user, install_password)

    openzwave_path = os.path.join('/srv', openzwave_dir)
    cmd = 'mkdir -p {}'.format(openzwave_path)
    sudo(cmd)

    switch_user(ha_user.name, ha_user.password)

    install_path = os.path.join(openzwave_path, install_dir)
    cmd = 'git clone {} {}'.format(git_url, install_path)
    run(cmd)

    with cd(install_path):
        put('./files/openzwave_ctrl_makefile', 'Makefile')
        run("make")

        switch_user(install_user, install_password)
        sudo("ln -sd /srv/home_assistant/ha_env/lib/python3.6/site-packages/libopenzwave-0.3.1-py3.6-linux-armv7l.egg/config")
Ejemplo n.º 10
0
def install_home_assistant():
    user_info       = config['user']
    home_assistant  = config['home_assistant']
    git_src_url     = home_assistant['git_src_url']
    root_path       = home_assistant['root_dir']
    source_dir      = home_assistant['source_dir']
    venv_dir        = home_assistant['venv_dir']
    use_git_config  = home_assistant['use_git_config']
    config_dir      = home_assistant['config_dir']
    git_config_url  = home_assistant['git_config_url']
    ha_user         = get_ha_user(user_info)

    switch_user(install_user, install_password)

    ha_path = os.path.join('/srv', root_path)
    cmd = 'mkdir -p %s' % (ha_path)
    sudo(cmd)

    cmd = 'chown -R {}:{} {}'.format(ha_user.name, ha_user.name, ha_path)
    sudo(cmd)

    switch_user(ha_user.name, ha_user.password)

    src_path = os.path.join(ha_path, source_dir)
    cmd = 'mkdir -p %s' % (src_path)
    run(cmd)

    cmd = 'git clone %s %s' % (git_src_url, src_path)
    run(cmd)

    config_path = os.path.join(ha_path, config_dir)
    cmd = 'mkdir -p %s' % (config_path)
    run(cmd)

    if use_git_config and git_config_url:
        cmd = 'git clone %s %s' % (git_config_url, config_path)
        run(cmd)

    install_home_assistant_deps()
Ejemplo n.º 11
0
def install_home_assistant_deps():
    user_info       = config['user']
    home_assistant  = config['home_assistant']
    venv_dir        = home_assistant['venv_dir']
    root_path       = home_assistant['root_dir']
    source_dir      = home_assistant['source_dir']
    pyenv           = config['pyenv']
    python          = config['python']
    ha_user         = get_ha_user(user_info)
    home_path       = get_user_home_dir(ha_user.name)
    pyenv_path      = os.path.join(home_path, '.pyenv')
    ha_path         = os.path.join('/srv', root_path)
    src_path        = os.path.join(ha_path, source_dir)

    switch_user(ha_user.name, ha_user.password)

    cmd1 = 'PYENV_ROOT="{}"'.format(pyenv_path)
    cmd2 = 'PATH="$PYENV_ROOT/bin:$PATH"'
    cmd3 = 'eval "$(pyenv init -)"'
    cmd_str = '{}; {}; {}'.format(cmd1, cmd2, cmd3)

    with prefix(cmd_str):
        cmd = 'pip install virtualenv'
        run(cmd)

        cmd = 'cd {}'.format(ha_path)

        with prefix(cmd):
            cmd = 'virtualenv %s' % (venv_dir)
            run(cmd)

            venv_path = os.path.join(ha_path, venv_dir)
            venv_activate = os.path.join(venv_path, 'bin', 'activate')
            cmd = '. {}'.format(venv_activate)

            with prefix(cmd):
                cmd = 'pip install -e %s' % (src_path)
                run(cmd)
Ejemplo n.º 12
0
def install_micro_httpd():
    user_info               = config['user']
    home_assistant          = config['home_assistant']
    root_path               = home_assistant['root_dir']
    admin_user              = get_admin_user(user_info)
    libmicrohttpd           = config['libmicrohttpd']
    install_dir             = libmicrohttpd['install_dir']
    lib                     = libmicrohttpd['lib']
    ftp_site                = libmicrohttpd['ftp_site']
    system_libs             = libmicrohttpd['system_libs']

    switch_user(install_user, install_password)
    install_native(system_libs)

    install_path = os.path.join('/opt', install_dir)
    cmd = 'mkdir -p {}'.format(install_path)
    sudo(cmd)

    cmd = 'chown -R {}:{} {}'.format(admin_user.name, admin_user.name, install_path)
    sudo(cmd)

    switch_user(admin_user.name, admin_user.password)

    with cd(install_path):
        ftp_path = os.path.join(ftp_site, lib)
        cmd = 'wget {}'.format(ftp_path)
        run(cmd)

        cmd = 'tar zxvf {}'.format(lib)
        run(cmd)

        lib_dir = '.'.join(lib.split('.')[:-2])

        with cd(lib_dir):
            run('./configure')
            run('make')
            sudo('make install')
Ejemplo n.º 13
0
# Globals
# --------------------------------------------------------------------------
debug = False
root_path = os.path.dirname(os.path.realpath(__file__))


# Environment
# --------------------------------------------------------------------------
install_user = '******'
install_password = '******'
env.hosts = [config['system']['hostname']]
env.shell = "/bin/sh -c"
env.warn_only = True
env.use_ssh_config = False

switch_user(install_user, install_password)


# Setup functions
# --------------------------------------------------------------------------
@task
def install_system_apps():
    system_apps = config['system_apps']
    switch_user(install_user, install_password)
    install_native(system_apps)

@task
def install_python_libs():
    python_system_libs = config['python_system_libs']
    switch_user(install_user, install_password)
    install_native(python_system_libs)
Ejemplo n.º 14
0
def install_python_libs():
    python_system_libs = config['python_system_libs']
    switch_user(install_user, install_password)
    install_native(python_system_libs)
Ejemplo n.º 15
0
def install_system_apps():
    system_apps = config['system_apps']
    switch_user(install_user, install_password)
    install_native(system_apps)
Ejemplo n.º 16
0
def install_openzwave():
    user_info               = config['user']
    openzwave               = config['openzwave']
    openzwave_system_libs   = openzwave['system_libs']
    openzwave_python_libs   = openzwave['python_libs']
    openzwave_git_url       = openzwave['git_url']
    openzwave_dir           = openzwave['dir']
    home_assistant          = config['home_assistant']
    venv_dir                = home_assistant['venv_dir']
    root_path               = home_assistant['root_dir']
    ha_user                 = get_ha_user(user_info)
    ha_path                 = os.path.join('/srv', root_path)
    home_path               = get_user_home_dir(ha_user.name)
    pyenv_path              = os.path.join(home_path, '.pyenv')

    switch_user(install_user, install_password)
    install_native(openzwave_system_libs)

    openzwave_path = os.path.join('/srv', openzwave_dir)
    cmd = 'mkdir -p {}'.format(openzwave_path)
    sudo(cmd)

    cmd = 'chown -R {}:{} {}'.format(ha_user.name, ha_user.name, openzwave_path)
    sudo(cmd)

    sudo('service home-assistant stop')
    switch_user(ha_user.name, ha_user.password)

    cmd1 = 'PYENV_ROOT="{}"'.format(pyenv_path)
    cmd2 = 'PATH="$PYENV_ROOT/bin:$PATH"'
    cmd3 = 'eval "$(pyenv init -)"'
    cmd_str = '{}; {}; {}'.format(cmd1, cmd2, cmd3)

    with prefix(cmd_str):
        cmd = 'cd {}'.format(ha_path)
        run(cmd)

        venv_path = os.path.join(ha_path, venv_dir)
        venv_activate = os.path.join(venv_path, 'bin', 'activate')
        cmd = '. {}'.format(venv_activate)

        with prefix(cmd):
            libs = ' '.join(openzwave_python_libs)
            cmd = 'pip install {}'.format(libs)
            run(cmd)
            py_openzwave_path = os.path.join(openzwave_path, 'python_openzwave')

            cmd = 'rm -rf {}'.format(py_openzwave_path)
            run(cmd)

            cmd = 'git clone {} {}'.format(openzwave_git_url, py_openzwave_path)
            run(cmd)

            with cd(py_openzwave_path):
                cmd = 'git checkout --track origin/python3'
                run(cmd)

                cmd = 'make build'
                run(cmd)

                cmd = 'make install'
                run(cmd)

    switch_user(install_user, install_password)
    sudo('service home-assistant start')
Ejemplo n.º 17
0
def create_all_aliases():
    users       = config['user']['accounts']

    for user in users:
        switch_user(user.name, user.password)
        create_user_alias(user)