#!/usr/bin/env python # CCS Computer Science # Change Shell # # Douglas Thrift # # $Id$ import admin import common import ldap import re if __name__ == '__main__': parser = admin.parser(description = 'Change CCS CS Lab user', usage = '%%prog [options] %s' % ' '.join(map(lambda system: '[%s]' % system.upper(), common.SYSTEMS))) shells = map(lambda shells: shells[0], common.SHELLS) parser.add_option('-u', '--user', default = '', help = 'change shell of USER (only works when run as root)') parser.add_option('-s', '--shell', choices = shells, help = 'set the shell to SHELL') options, args = parser.parse_args() try: user = admin.user(options) shell = options.shell while shell not in shells: shell = raw_input('Shell (%s): ' % ', '.join(shells)) if shell == 'custom': shells = dict(common.SHELLS)[shell] path = re.compile('^/.*[^/]$') for system in common.SYSTEMS: try: shells[system] = args.pop(0) except IndexError: pass while shells[system] is None or path.match(shells[system]) is None: shells[system] = raw_input(common.capitalize(system) + ': ') else: shells = None if admin.master(): admin.chsh(user, shell, shells) admin.run(common.chsh_all(user, shell, shells)) except (IOError, ldap.LDAPError), error: admin.error(error) except (EOFError, KeyboardInterrupt): admin.eof() # vim: noexpandtab tabstop=4