diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2013-08-15 20:59:12 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2013-08-15 20:59:12 +0400 |
commit | 6b154216515f910e7ecce3bc7a9db0da3107bc4c (patch) | |
tree | c81daafaa4e3ed17bc349b10c2b1f83b73bd075e | |
parent | 2e8b822934344ea3f3555a5f5e6cd134a2de8cfa (diff) | |
download | live-6b154216515f910e7ecce3bc7a9db0da3107bc4c.tar.gz |
Added create_user()
-rwxr-xr-x | install | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -854,6 +854,58 @@ def set_root_password(): chpasswd_cmd = Popen(['chpasswd', '-R', rootdir], stderr=PIPE, stdout=PIPE, stdin=PIPE) chpasswd_cmd.communicate(input='root:'+passwd) +def create_user(): + login = Entry(width = 30, password = 0, returnExit = 0) + passwd1 = Entry(width = 30, password = 1, returnExit = 0) + passwd2 = Entry(width = 30, password = 1, returnExit = 1) + realname = Entry(width = 30, password = 0, returnExit = 1) + userid = Entry(width = 30, password = 0, returnExit = 1) + while True: + choice, entries = EntryWindow(screen, title='Create a regular user', + text='Enter user login and password. ' + 'The password is not shown, you have to type it twice. ' + 'Real name is optional. User ID will be set automatically, if empty.', + prompts=[ + ('Login', login), + ('Password', passwd1), + ('Password again', passwd2), + ('Real name', realname), + ('User ID', userid), + ], + width=50, entryWidth=30, buttons=['Ok', 'Skip']) + if choice == 'skip': + break + if passwd1.value() != passwd2.value(): + ButtonChoiceWindow(screen, title='Error', + text='Password entries do not match. Try again.', buttons=['Ok']) + continue + if not login.value(): + ButtonChoiceWindow(screen, title='Error', + text='User login name cannot be empty.', buttons=['Ok']) + continue + adduser = ['adduser', '--shell', '/usr/bin/bash', '--add_extra_groups', '--disabled-login'] + if userid.value(): + if userid.value().isdigit(): + adduser += ['--uid', userid.value()] + else: + ButtonChoiceWindow(screen, title='Error', + text='User ID must be a number, not {}'.format(userid.value()), buttons=['Ok']) + continue + if realname.value(): + adduser += ['--gecos', realname.value()] + + adduser.append(login.value()) + ret, stdout, stderr = in_bootenv(adduser) + if ret == 0: + chpasswd_cmd = Popen(['chpasswd', '-R', rootdir], stderr=PIPE, stdout=PIPE, stdin=PIPE) + chpasswd_cmd.communicate(input='{}:{}'.format(login.value(), passwd1.value())) + break + else: + ButtonChoiceWindow(screen, title='Failed to create user', + text=stderr, buttons=['Ok']) + continue + + def configure_bootenv(): write_vfstab() mount_in_bootenv() @@ -869,6 +921,7 @@ def configure_bootenv(): except: pass set_root_password() + create_user() create_bootarchive() configure_smf() |