Пример #1
0
def make(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.scratch import exists as scratch_exists
    from ixtlilton_tools.admin.directory.user.scratch import fix_owner as fix_scratch_owner

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    path = pathlib.Path('/scratch/' + username)

    if not scratch_exists(username):
        os.mkdir(path)
        fix_scratch_owner(username)

    pass
Пример #2
0
def make(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.home.local import exists as local_exists
    from ixtlilton_tools.admin.directory.user.home.local import fix_owner as fix_local_owner
    from ixtlilton_tools.admin.directory.user.home.local.bin import make as make_local_bin
    from ixtlilton_tools.admin.directory.user.home.local.etc import make as make_local_etc
    from ixtlilton_tools.admin.directory.user.home.local.opt import make as make_local_opt
    from ixtlilton_tools.admin.directory.user.home.local.include import make as make_local_include
    from ixtlilton_tools.admin.directory.user.home.local.lib import make as make_local_lib
    from ixtlilton_tools.admin.directory.user.home.local.lib32 import make as make_local_lib32
    from ixtlilton_tools.admin.directory.user.home.local.lib64 import make as make_local_lib64
    from ixtlilton_tools.admin.directory.user.home.local.man import make as make_local_man
    from ixtlilton_tools.admin.directory.user.home.local.share import make as make_local_share
    from ixtlilton_tools.admin.directory.user.home.local.src import make as make_local_src

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    path = pathlib.Path('/home/' + username + '/local')
    aux_path = pathlib.Path('/home/' + username + '/.local')

    if not local_exists(username):

        if not aux_path.exists():
            os.mkdir(aux_path)
            subprocess.run(
                ['chown', '-R', f'{username}:{username}',
                 str(aux_path)])

        os.symlink('/home/' + username + '/.local',
                   path,
                   target_is_directory=True)
        fix_local_owner(username)

        make_local_bin(username)
        make_local_etc(username)
        make_local_opt(username)
        make_local_include(username)
        make_local_lib(username)
        make_local_lib32(username)
        make_local_lib64(username)
        make_local_man(username)
        make_local_share(username)
        make_local_src(username)

    pass
Пример #3
0
def make(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.home.local.include import exists as include_exists
    from ixtlilton_tools.admin.directory.user.home.local.include import fix_owner as fix_include_owner

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    path = pathlib.Path('/home/' + username + '/local/include')

    if not include_exists(username):

        os.mkdir('/home/' + username + '/local/include')
        fix_include_owner(username)

    pass
Пример #4
0
def make(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.home.local.opt.modulefiles import exists as modulefiles_exists
    from ixtlilton_tools.admin.directory.user.home.local.opt.modulefiles import fix_owner as fix_modulefiles_owner

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    path = pathlib.Path('/home/' + username + '/local/opt/modulefiles')

    if not modulefiles_exists(username):

        os.mkdir('/home/' + username + '/local/opt/modulefiles')
        fix_modulefiles_owner(username)

    pass
Пример #5
0
def add_user(groupname, username):

    from ixtlilton_tools.admin import running_with_admin_rights
    from ixtlilton_tools.admin.group import exists as group_exists
    from ixtlilton_tools.admin.user import exists as user_exists

    if not running_with_admin_rights():
        raise NoAdminRights()

    if not group_exists(groupname):
        raise GroupDoesNotExist(groupname=groupname)

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    subprocess.run(['usermod', '-a', '-G', groupname, username])

    pass
Пример #6
0
def fix_owner(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.home.local.opt.apps import exists as apps_exists
    from ixtlilton_tools.admin.directory.user.home.local.opt.apps import fix_owner as fix_apps_owner

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    path = pathlib.Path('/home/'+username+'/local/opt/apps')

    if not apps_exists(username):
        raise DirectoryConflict('The apps directory of user {username} does not exists')
    else:
        owner = path.owner()
        group = path.group()
        if owner!=username or group!=username:
            subprocess.run(['chown', '-R', f'{username}:{username}', str(path)])

    pass
Пример #7
0
def remove(username):

    from ixtlilton_tools.admin import running_with_admin_rights
    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user import scratch, work, home

    if not running_with_admin_rights():
        raise NoAdminRights()

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    ## removing user

    subprocess.run(['userdel', username])

    ## removing mailbox file

    path = pathlib.Path('/var/spool/mail/' + username)
    if path.exists():
        os.remove(path)

    ## removing directories if empty

    scratch.remove(username)
    work.remove(username)
    home.local.opt.modulefiles.remove(username)
    home.local.opt.apps.remove(username)
    home.local.opt.remove(username)
    home.local.bin.remove(username)
    home.local.etc.remove(username)
    home.local.lib.remove(username)
    home.local.lib32.remove(username)
    home.local.lib64.remove(username)
    home.local.include.remove(username)
    home.local.src.remove(username)
    home.local.share.remove(username)
    home.local.man.remove(username)
    home.local.remove(username)
    home.remove(username)
Пример #8
0
def fix_owner(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.scratch import exists as scratch_exists
    from ixtlilton_tools.admin.directory.user.scratch import fix_owner as fix_scratch_owner

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    path = pathlib.Path('/scratch/' + username)

    if not scratch_exists(username):
        raise DirectoryConflict(
            'The scratch directory of user {username} does not exists')
    else:
        owner = path.owner()
        group = path.group()
        if owner != username or group != username:
            subprocess.run(
                ['chown', '-R', f'{username}:{username}',
                 str(path)])

    pass
Пример #9
0
def fix(username, fullname=None, phone=None, mail=None, category=None):

    from ixtlilton_tools.admin import running_with_admin_rights
    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user import scratch, work, home

    if not running_with_admin_rights():
        raise NoAdminRights()

    if not user_exists(username):
        raise UserDoesNotExist(user=username)

    # gecos fields

    if fullname is not None:
        subprocess.run(['chfn', '-f', fullname, username])

    if phone is not None:
        subprocess.run(['chfn', '-h', phone, username])

    if mail is not None:
        subprocess.run(['chfn', '-o', mail, username])

    # user directories

    work.make(username)
    work.fix_owner(username)

    scratch.make(username)
    scratch.fix_owner(username)

    home.local.make(username)
    home.local.fix_owner(username)

    home.local.bin.make(username)
    home.local.bin.fix_owner(username)

    home.local.etc.make(username)
    home.local.etc.fix_owner(username)

    home.local.include.make(username)
    home.local.include.fix_owner(username)

    home.local.lib.make(username)
    home.local.lib.fix_owner(username)

    home.local.lib32.make(username)
    home.local.lib32.fix_owner(username)

    home.local.man.make(username)
    home.local.man.fix_owner(username)

    home.local.share.make(username)
    home.local.share.fix_owner(username)

    home.local.src.make(username)
    home.local.src.fix_owner(username)

    home.local.opt.make(username)
    home.local.opt.fix_owner(username)

    home.local.opt.modulefiles.make(username)
    home.local.opt.modulefiles.fix_owner(username)

    home.local.opt.apps.make(username)
    home.local.opt.apps.fix_owner(username)

    pass