From 6b154216515f910e7ecce3bc7a9db0da3107bc4c Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Thu, 15 Aug 2013 20:59:12 +0400 Subject: Added create_user() --- install | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'install') diff --git a/install b/install index 0d4d863..2e392e8 100755 --- a/install +++ b/install @@ -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() -- cgit v1.2.3