File: users.py

package info (click to toggle)
python3-dmm 0.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 540 kB
  • sloc: python: 441; makefile: 2
file content (20 lines) | stat: -rw-r--r-- 857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""
create users, currently only in chroot
"""

import os
from command_runner import command_runner

def add_users(users, chroot):
    """
    Add one or more users to the system.
    """
    for user in users:
        password_hash = os.popen("mkpasswd --method=SHA-512 " + user['password']).read().replace('\n', '')
        ecode, result = command_runner("chroot %s useradd -p '%s' %s" % (chroot, password_hash, user['username']))
        ecode, result = command_runner("chroot %s mkdir home/%s" % (chroot, user['username']))
        ecode, result = command_runner("chroot %s chown %s home/%s" % (chroot, user['username'], user['username']))
        if user['sudo']:
            ecode, result = command_runner("chroot %s adduser %s sudo" % (chroot, user['username']))
            ecode, result = command_runner("chroot %s apt-get install sudo" % chroot)