Add make_normal_user() function

also add `disabled_password` kwarg for `make_system_user()`
This commit is contained in:
Lance Edgar 2023-02-17 11:00:31 -06:00
parent 9e0a1cde19
commit a76d38c201
2 changed files with 20 additions and 3 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -33,6 +33,7 @@ from .core import (
get_ubuntu_version, get_ubuntu_version,
Deployer, Deployer,
make_deploy, make_deploy,
make_normal_user,
make_system_user, make_system_user,
mkdir, mkdir,
rsync, rsync,

View file

@ -128,7 +128,21 @@ def mkdir(c, paths, owner=None, mode=None,
func('chmod {} {}'.format(mode, ' '.join(paths))) func('chmod {} {}'.format(mode, ' '.join(paths)))
def make_system_user(c, name, home=None, uid=None, shell=None): def make_normal_user(c, name, full_name=None, disabled_login=True):
"""
Make a new "normal" user account.
"""
if not c.run('getent passwd {}'.format(name), warn=True).failed:
return
disabled_login = '--disabled-login' if disabled_login else ''
c.sudo("adduser --gecos '{}' {} {}".format(full_name or name,
disabled_login,
name))
def make_system_user(c, name, home=None, uid=None, shell=None,
disabled_password=None):
""" """
Make a new system user account, with the given home folder and shell path. Make a new system user account, with the given home folder and shell path.
""" """
@ -138,7 +152,9 @@ def make_system_user(c, name, home=None, uid=None, shell=None):
home = '--home {}'.format(home) if home else '' home = '--home {}'.format(home) if home else ''
uid = '--uid {}'.format(uid) if uid else '' uid = '--uid {}'.format(uid) if uid else ''
shell = '--shell {}'.format(shell) if shell else '' shell = '--shell {}'.format(shell) if shell else ''
c.sudo('adduser --system --group {} {} {} {}'.format(name, home, uid, shell)) disabled_password = '--disabled-password' if disabled_password else ''
c.sudo('adduser --system --group {} {} {} {} {}'.format(name, home, uid, shell,
disabled_password))
def set_timezone(c, timezone): def set_timezone(c, timezone):