Add password support for make_normal_user()

This commit is contained in:
Lance Edgar 2023-06-09 18:19:49 -05:00
parent 3f931445a0
commit 9eab7a7555

View file

@ -128,17 +128,25 @@ def mkdir(c, paths, owner=None, mode=None,
func('chmod {} {}'.format(mode, ' '.join(paths))) func('chmod {} {}'.format(mode, ' '.join(paths)))
def make_normal_user(c, name, full_name=None, disabled_login=True): def make_normal_user(c, username, full_name=None,
# TODO: ugh why is this true by default..should change that
disabled_login=True,
password=None):
""" """
Make a new "normal" user account. Make a new "normal" user account.
""" """
if not c.run('getent passwd {}'.format(name), warn=True).failed: if not c.run('getent passwd {}'.format(username), warn=True).failed:
return return
if password:
disabled_login = True
disabled_login = '--disabled-login' if disabled_login else '' disabled_login = '--disabled-login' if disabled_login else ''
c.sudo("adduser --gecos '{}' {} {}".format(full_name or name, c.sudo("adduser --gecos '{}' {} {}".format(full_name or username,
disabled_login, disabled_login,
name)) username))
if password:
c.sudo(f"bash -c 'echo {username}:{password} | chpasswd'",
echo=False)
def make_system_user(c, name, home=None, uid=None, shell=None, def make_system_user(c, name, home=None, uid=None, shell=None,