diff options
Diffstat (limited to 'utils/chsh.py')
-rwxr-xr-x | utils/chsh.py | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/utils/chsh.py b/utils/chsh.py index 30c5c12..2f81f13 100755 --- a/utils/chsh.py +++ b/utils/chsh.py @@ -31,14 +31,13 @@ import users # set up command line parser parser = argparse.ArgumentParser( - description='Change the user login shell in LDAP.', - epilog='Report bugs to <%s>.' % constants.PACKAGE_BUGREPORT - ) + description='Change the user login shell in LDAP.', + epilog='Report bugs to <%s>.' % constants.PACKAGE_BUGREPORT) parser.add_argument('-V', '--version', action=VersionAction) parser.add_argument('-s', '--shell', help='login shell for the user account') parser.add_argument('-l', '--list-shells', action=ListShellsAction) parser.add_argument('username', metavar='USER', nargs='?', - help="the user who's shell to change") + help="the user who's shell to change") def ask_shell(oldshell): @@ -47,24 +46,26 @@ def ask_shell(oldshell): return shell or oldshell -# parse arguments -args = parser.parse_args() -# check username part -user = users.User(args.username) -user.check() -# check the command line shell if one was provided (to fail early) -shell = args.shell -if shell is not None: - shells.check(shell, user.asroot) -# prompt for a password if required -password = user.get_passwd() -# prompt for a shell if it was not specified on the command line -if shell is None: - print 'Enter the new value, or press ENTER for the default' - shell = ask_shell(user.shell) - shells.check(shell, user.asroot) -# perform the modification -result = nslcd.usermod(user.username, user.asroot, password, { - constants.NSLCD_USERMOD_SHELL: shell, - }) -# TODO: print proper response +if __name__ == '__main__': + # parse arguments + args = parser.parse_args() + # check username part + user = users.User(args.username) + user.check() + # check the command line shell if one was provided (to fail early) + shell = args.shell + if shell is not None: + shells.check(shell, user.asroot) + # prompt for a password if required + password = user.get_passwd() + # prompt for a shell if it was not specified on the command line + if shell is None: + print 'Enter the new value, or press ENTER for the default' + shell = ask_shell(user.shell) + shells.check(shell, user.asroot) + # perform the modification + result = nslcd.usermod( + user.username, user.asroot, password, { + constants.NSLCD_USERMOD_SHELL: shell, + }) + # TODO: print proper response |