#!/usr/bin/python3
# Copyright (c) 2008 Alon Swartz <alon@turnkeylinux.org> - all rights reserved

import os

from common import dilive_system, is_mounted

sys_paths = {'dev': 0o755, 'proc': 0o555, 'sys': 0o555,
             'run': 0o755, 'tmp': 0o1777}


def _chkdirs(path='/target'):
    """Check that /target dir is mounted; then check that important sys dirs
       (e.g. dev, proc, etc) exist - if not create them, with correct
       permissions."""
    if is_mounted(path):
        for directory, permissions in sys_paths.items():
            directory = os.path.join(path, directory)
            if not os.path.isdir(directory):
                os.mkdir(directory, permissions)


def main():
    _chkdirs('/target')
    dilive_system(['/lib/live-installer/live-installer'])


if __name__ == "__main__":
    main()
