diff --git a/rattail_fabric2/__init__.py b/rattail_fabric2/__init__.py index 6d916e6..d615338 100644 --- a/rattail_fabric2/__init__.py +++ b/rattail_fabric2/__init__.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -33,6 +33,7 @@ from .core import ( get_ubuntu_version, Deployer, make_deploy, + make_normal_user, make_system_user, mkdir, rsync, diff --git a/rattail_fabric2/core.py b/rattail_fabric2/core.py index 0868c15..97cd616 100644 --- a/rattail_fabric2/core.py +++ b/rattail_fabric2/core.py @@ -128,7 +128,21 @@ def mkdir(c, paths, owner=None, mode=None, 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. """ @@ -138,7 +152,9 @@ def make_system_user(c, name, home=None, uid=None, shell=None): home = '--home {}'.format(home) if home else '' uid = '--uid {}'.format(uid) if uid 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):