#!/usr/bin/env python3
# encoding: utf-8
# === openmamba-postinstall module for Calamares - <http://github.com/calamares> ===
#
# Copyright 2015-2022, Silvan Calarco <silvan.calarco@mambasoft.it>
#

import libcalamares


def run():
    """ Complete setup after openmamba installation  """

    # fix root path ('/') permissions
    libcalamares.utils.target_env_call(['chmod', '0755', '/'])

    # remove bluetooth config with livecd hostname
    libcalamares.utils.target_env_call(['rm', '-f', '/var/lib/bluetooth/*/config'])

    # remove ssh host keys
    libcalamares.utils.target_env_call(['rm', '-f', '/etc/ssh/ssh_host_*'])

    # run setup for secure boot
    libcalamares.utils.target_env_call(['sb-setup'])

    # create user home
    username = libcalamares.globalstorage.value("username")

    libcalamares.utils.target_env_call(['cp', '-r', '/etc/skel/.', '/home/%s' % username ])
    libcalamares.utils.target_env_call(['chmod', '0711', '/home/%s' % username ])
    libcalamares.utils.target_env_call(['mkdir', '-p', '/home/%s/.config/autostart' % username ])
    libcalamares.utils.target_env_call(['ln', '-s', '/usr/share/mambabase/mambabase-autostart.desktop',
                                    '/home/%s/.config/autostart/mambabase.desktop' % username ])
    libcalamares.utils.target_env_call(['chown', '-R', '%s:users' % username, '/home/%s' % username ])
    libcalamares.utils.target_env_call(['chown', '-R', '%s:users' % username, '/home/%s/.config' % username ])

    return None
