asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 1 | #!/usr/bin/python2.6 |
| 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Script to get past the login screen of ChromeOS. |
| 6 | |
| 7 | """ |
| 8 | |
| 9 | __author__ = "asharif@google.com (Ahmad Sharif)" |
| 10 | |
| 11 | import datetime |
| 12 | import fcntl |
| 13 | import getpass |
| 14 | import glob |
| 15 | import optparse |
| 16 | import os |
| 17 | import pickle |
| 18 | import socket |
| 19 | import sys |
| 20 | import time |
| 21 | from utils import logger |
| 22 | from utils import command_executer |
| 23 | |
| 24 | LOGIN_PROMPT_VISIBLE_MAGIC_FILE = '/tmp/uptime-login-prompt-visible' |
| 25 | LOGGED_IN_MAGIC_FILE = '/var/run/state/logged-in' |
| 26 | |
| 27 | |
asharif | d2ced68 | 2013-02-16 01:05:17 +0000 | [diff] [blame^] | 28 | script_header=""" |
asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 29 | import os |
| 30 | import autox |
| 31 | import time |
asharif | d2ced68 | 2013-02-16 01:05:17 +0000 | [diff] [blame^] | 32 | """ |
| 33 | |
| 34 | wait_for_login_screen=""" |
asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 35 | |
| 36 | while True: |
| 37 | print 'Waiting for login screen to appear...' |
| 38 | if os.path.isfile('%s'): |
| 39 | break |
| 40 | time.sleep(1) |
| 41 | print 'Done' |
| 42 | |
| 43 | time.sleep(20) |
asharif | d2ced68 | 2013-02-16 01:05:17 +0000 | [diff] [blame^] | 44 | """ % LOGIN_PROMPT_VISIBLE_MAGIC_FILE |
asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 45 | |
asharif | d2ced68 | 2013-02-16 01:05:17 +0000 | [diff] [blame^] | 46 | |
| 47 | do_login=""" |
asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 48 | xauth_filename = '/home/chronos/.Xauthority' |
| 49 | os.environ.setdefault('XAUTHORITY', xauth_filename) |
| 50 | os.environ.setdefault('DISPLAY', ':0.0') |
| 51 | |
| 52 | print 'Now sending the hotkeys for logging in.' |
| 53 | ax = autox.AutoX() |
| 54 | # navigate to login screen |
| 55 | ax.send_hotkey('Ctrl+Shift+q') |
| 56 | ax.send_hotkey('Ctrl+Alt+l') |
| 57 | # escape out of any login screen menus (e.g., the network select menu) |
| 58 | time.sleep(2) |
| 59 | ax.send_hotkey('Escape') |
| 60 | time.sleep(2) |
| 61 | ax.send_hotkey('Tab') |
| 62 | time.sleep(0.5) |
| 63 | ax.send_hotkey('Tab') |
| 64 | time.sleep(0.5) |
| 65 | ax.send_hotkey('Tab') |
| 66 | time.sleep(0.5) |
| 67 | ax.send_hotkey('Tab') |
| 68 | time.sleep(0.5) |
| 69 | ax.send_hotkey('Return') |
| 70 | print 'Waiting for Chrome to appear...' |
| 71 | while True: |
| 72 | if os.path.isfile('%s'): |
| 73 | break |
| 74 | time.sleep(1) |
| 75 | print 'Done' |
asharif | d2ced68 | 2013-02-16 01:05:17 +0000 | [diff] [blame^] | 76 | """ % LOGGED_IN_MAGIC_FILE |
asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 77 | |
asharif | d2ced68 | 2013-02-16 01:05:17 +0000 | [diff] [blame^] | 78 | def RestartUI(remote, chromeos_root, login=True): |
asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 79 | chromeos_root = os.path.expanduser(chromeos_root) |
| 80 | ce = command_executer.GetCommandExecuter() |
| 81 | # First, restart ui. |
asharif | d2ced68 | 2013-02-16 01:05:17 +0000 | [diff] [blame^] | 82 | command = 'rm -rf %s && restart ui' % LOGIN_PROMPT_VISIBLE_MAGIC_FILE |
asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 83 | ce.CrosRunCommand(command, machine=remote, |
| 84 | chromeos_root=chromeos_root) |
| 85 | login_script = '/tmp/login.py' |
asharif | d2ced68 | 2013-02-16 01:05:17 +0000 | [diff] [blame^] | 86 | login_script_list = [script_header, wait_for_login_screen] |
| 87 | if login: |
| 88 | login_script_list.append(do_login) |
| 89 | |
| 90 | full_login_script_contents = "\n".join(login_script_list) |
| 91 | |
asharif | d8136e4 | 2013-02-15 23:18:03 +0000 | [diff] [blame] | 92 | with open(login_script, 'w') as f: |
| 93 | f.write(full_login_script_contents) |
| 94 | ce.CopyFiles(login_script, |
| 95 | login_script, |
| 96 | dest_machine=remote, |
| 97 | chromeos_root=chromeos_root, |
| 98 | recursive=False, |
| 99 | dest_cros=True) |
| 100 | return ce.CrosRunCommand('python %s' % login_script, |
| 101 | chromeos_root=chromeos_root, |
| 102 | machine=remote) |
| 103 | |
| 104 | |
| 105 | def Main(argv): |
| 106 | """The main function.""" |
| 107 | parser = optparse.OptionParser() |
| 108 | parser.add_option('-r', |
| 109 | '--remote', |
| 110 | dest='remote', |
| 111 | help='The remote ChromeOS box.') |
| 112 | parser.add_option('-c', |
| 113 | '--chromeos_root', |
| 114 | dest='chromeos_root', |
| 115 | help='The ChromeOS root.') |
| 116 | |
| 117 | options, args = parser.parse_args(argv) |
| 118 | |
| 119 | return LoginAsGuest(options.remote, options.chromeos_root) |
| 120 | |
| 121 | if __name__ == '__main__': |
| 122 | retval = Main(sys.argv) |
asharif | 5ab1c7d | 2013-02-15 23:43:58 +0000 | [diff] [blame] | 123 | sys.exit(retval) |