Exemplo n.º 1
0
def add_user(users):
    for user in users:
        key_path = os.path.join(os.path.dirname(__file__),
                                '../ssh_key_' + user + '.pub')

        if not fabuser.exists(user):
            fabuser.create(user, password='******', shell='/bin/bash')

            try:
                fabuser.modify(user, ssh_public_keys=key_path)
            except FileNotFoundError:
                pass
Exemplo n.º 2
0
def add_key(user='', key=''):
    if not user:
        raise ValueError("Username cannot be empty.")

    if confirm("Add key/user to: " + env.host_string + "?"):
        key_path = os.path.join(os.path.dirname(__file__), key)

        if not fabuser.exists(user):
            fabuser.create(user, password='******', shell='/bin/bash')
            fabuser.modify(user, group='sudo')

        try:
            fabuser.modify(user, ssh_public_keys=key_path)
        except FileNotFoundError:
            print("Could not find SSH key at the specified location.")
Exemplo n.º 3
0
def env_base_requirement(direct=True, sync_dotfiles='fabrecipes'):
    """
    Install requirement base system
    """
    pkgs = [
        'zsh',
        'wget',
        'netctl',
        'dialog',
        'yaourt',
        'python2',
        'ifplugd',
        'net-tools',
        'wpa_actiond',
        'wpa_supplicant',
    ]

    # Check if a custom package for computer
    env_section = inspect.stack()[0][3]
    if 'pkgs' in env and env_section in env.pkgs:
        pkgs = list(set(pkgs + env.pkgs[env_section]))

    # Install required packages
    run_as_root('dirmngr </dev/null')
    run_as_root('pacman-key --init')
    run_as_root('pacman-key --populate archlinux')
    run_as_root('pacman-key --refresh-keys')
    run_as_root('pacman --noconfirm -Syyu')
    run_as_root('pacman-db-upgrade')
    require.arch.packages(pkgs, options=["--noconfirm"])

    # Install oh-my-zsh
    ohmyzsh = '$HOME/.oh-my-zsh'
    if not is_dir(ohmyzsh):
        run(
            'git clone git://github.com/robbyrussell/oh-my-zsh.git %(ohmyzsh)s'
            % locals()
        )

    # Set default ZSH shell for user
    if user.exists(env.useraccount):
        user.modify(env.useraccount, shell='/usr/bin/zsh')

    # Synchronize user dotfiles
    sync_dotfiles = 'fabrecipes/autoinstall/%(env_section)s' % locals()
    dotfiles.sync('%(sync_dotfiles)s/user/' % locals(), '$HOME/')
    dotfiles.sync('%(sync_dotfiles)s/sys/' % locals(), '/', use_sudo='true')
Exemplo n.º 4
0
def env_base_requirement(direct=True, sync_dotfiles='fabrecipes'):
    """
    Install requirement base system
    """
    pkgs = [
        'zsh',
        'wget',
        'netctl',
        'dialog',
        'yaourt',
        'python2',
        'ifplugd',
        'net-tools',
        'wpa_actiond',
        'wpa_supplicant',
    ]

    # Check if a custom package for computer
    env_section = inspect.stack()[0][3]
    if 'pkgs' in env and env_section in env.pkgs:
        pkgs = list(set(pkgs + env.pkgs[env_section]))

    # Install required packages
    run_as_root('dirmngr </dev/null')
    run_as_root('pacman-key --init')
    run_as_root('pacman-key --populate archlinux')
    run_as_root('pacman-key --refresh-keys')
    run_as_root('pacman --noconfirm -Syyu')
    run_as_root('pacman-db-upgrade')
    require.arch.packages(pkgs, options=["--noconfirm"])

    # Install oh-my-zsh
    ohmyzsh = '$HOME/.oh-my-zsh'
    if not is_dir(ohmyzsh):
        run(
            'git clone git://github.com/robbyrussell/oh-my-zsh.git %(ohmyzsh)s'
            % locals()
        )

    # Set default ZSH shell for user
    if user.exists(env.useraccount):
        user.modify(env.useraccount, shell='/usr/bin/zsh')

    # Synchronize user dotfiles
    sync_dotfiles = 'fabrecipes/autoinstall/%(env_section)s' % locals()
    dotfiles.sync('%(sync_dotfiles)s/user/' % locals(), '$HOME/')
    dotfiles.sync('%(sync_dotfiles)s/sys/' % locals(), '/', use_sudo='true')
Exemplo n.º 5
0
def user(name, comment=None, home=None, create_home=None, skeleton_dir=None,
         group=None, create_group=True, extra_groups=None, password=None,
         system=False, shell=None, uid=None, ssh_public_keys=None,
         non_unique=False):
    """
    Require a user and its home directory.

    See :func:`fabtools.user.create` for a detailed description of
    arguments.

    ::

        from fabtools import require

        # This will also create a home directory for alice
        require.user('alice')

        # Sometimes we don't need a home directory
        require.user('mydaemon', create_home=False)

        # Require a user without shell access
        require.user('nologin', shell='/bin/false')

    .. note:: This function can be accessed directly from the
              ``fabtools.require`` module for convenience.

    """

    from fabtools.require import directory as require_directory

    # Make sure the user exists
    if not exists(name):
        create(name, comment=comment, home=home, create_home=create_home,
               skeleton_dir=skeleton_dir, group=group,
               create_group=create_group, extra_groups=extra_groups,
               password=password, system=system, shell=shell, uid=uid,
               ssh_public_keys=ssh_public_keys, non_unique=non_unique)
    else:
        modify(name, comment=comment, home=home, group=group,
               extra_groups=extra_groups, password=password,
               shell=shell, uid=uid, ssh_public_keys=ssh_public_keys,
               non_unique=non_unique)

    # Make sure the home directory exists and is owned by user
    if home:
        require_directory(home, owner=name, use_sudo=True)
Exemplo n.º 6
0
def user(name,
         comment=None,
         home=None,
         create_home=None,
         skeleton_dir=None,
         group=None,
         create_group=True,
         extra_groups=None,
         password=None,
         system=False,
         shell=None,
         uid=None):
    """
    Require a user and its home directory.

    See :func:`fabtools.user.create` for a detailed description of
    arguments.

    ::

        from fabtools import require

        # This will also create a home directory for alice
        require.user('alice')

        # Sometimes we don't need a home directory
        require.user('mydaemon', create_home=False)

        # Require a user without shell access
        require.user('nologin', shell='/bin/false')

    .. note:: This function can be accessed directly from the
              ``fabtools.require`` module for convenience.

    """

    from fabtools.require import directory as require_directory

    # Make sure the user exists
    if not exists(name):
        create(name,
               comment=comment,
               home=home,
               create_home=create_home,
               skeleton_dir=skeleton_dir,
               group=group,
               create_group=create_group,
               extra_groups=extra_groups,
               password=password,
               system=system,
               shell=shell,
               uid=uid)
    else:
        modify(name,
               comment=comment,
               home=home,
               group=group,
               extra_groups=extra_groups,
               password=password,
               shell=shell,
               uid=uid)

    # Make sure the home directory exists and is owned by user
    if home:
        require_directory(home, owner=name, use_sudo=True)
Exemplo n.º 7
0
def configure_postgres_user():

    if system_user.exists("postgres"):
        system_user.modify("postgres", password=env.postgresql_user_password)
Exemplo n.º 8
0
def add_user_to_sudo(users):
    for user in users:
        fabuser.modify(user, group='sudo')
Exemplo n.º 9
0
def configure_postgres_user():

    if system_user.exists("postgres"):
        system_user.modify("postgres", password=env.postgresql_user_password)