blob: 264b442905a770b407775f3f531a2775b3e8f726 [file] [log] [blame]
Mike Frysingerc7f15932013-03-20 13:43:35 -04001#!/usr/bin/python
asharifd8136e42013-02-15 23:18:03 +00002#
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
11import datetime
12import fcntl
13import getpass
14import glob
15import optparse
16import os
17import pickle
18import socket
19import sys
20import time
asharif54cf6782013-02-16 02:11:03 +000021import tempfile
asharifd8136e42013-02-15 23:18:03 +000022from utils import logger
23from utils import command_executer
24
25LOGIN_PROMPT_VISIBLE_MAGIC_FILE = '/tmp/uptime-login-prompt-visible'
26LOGGED_IN_MAGIC_FILE = '/var/run/state/logged-in'
27
28
asharifd2ced682013-02-16 01:05:17 +000029script_header="""
asharifd8136e42013-02-15 23:18:03 +000030import os
31import autox
32import time
asharifd2ced682013-02-16 01:05:17 +000033"""
34
35wait_for_login_screen="""
asharifd8136e42013-02-15 23:18:03 +000036
37while True:
38 print 'Waiting for login screen to appear...'
39 if os.path.isfile('%s'):
40 break
41 time.sleep(1)
42 print 'Done'
43
44time.sleep(20)
asharifd2ced682013-02-16 01:05:17 +000045""" % LOGIN_PROMPT_VISIBLE_MAGIC_FILE
asharifd8136e42013-02-15 23:18:03 +000046
asharifd2ced682013-02-16 01:05:17 +000047
48do_login="""
asharifd8136e42013-02-15 23:18:03 +000049xauth_filename = '/home/chronos/.Xauthority'
50os.environ.setdefault('XAUTHORITY', xauth_filename)
51os.environ.setdefault('DISPLAY', ':0.0')
52
53print 'Now sending the hotkeys for logging in.'
54ax = autox.AutoX()
55# navigate to login screen
56ax.send_hotkey('Ctrl+Shift+q')
57ax.send_hotkey('Ctrl+Alt+l')
58# escape out of any login screen menus (e.g., the network select menu)
59time.sleep(2)
60ax.send_hotkey('Escape')
61time.sleep(2)
62ax.send_hotkey('Tab')
63time.sleep(0.5)
64ax.send_hotkey('Tab')
65time.sleep(0.5)
66ax.send_hotkey('Tab')
67time.sleep(0.5)
68ax.send_hotkey('Tab')
69time.sleep(0.5)
70ax.send_hotkey('Return')
71print 'Waiting for Chrome to appear...'
72while True:
73 if os.path.isfile('%s'):
74 break
75 time.sleep(1)
76print 'Done'
asharifd2ced682013-02-16 01:05:17 +000077""" % LOGGED_IN_MAGIC_FILE
asharifd8136e42013-02-15 23:18:03 +000078
asharifd2ced682013-02-16 01:05:17 +000079def RestartUI(remote, chromeos_root, login=True):
asharifd8136e42013-02-15 23:18:03 +000080 chromeos_root = os.path.expanduser(chromeos_root)
81 ce = command_executer.GetCommandExecuter()
82 # First, restart ui.
asharifd2ced682013-02-16 01:05:17 +000083 command = 'rm -rf %s && restart ui' % LOGIN_PROMPT_VISIBLE_MAGIC_FILE
asharifd8136e42013-02-15 23:18:03 +000084 ce.CrosRunCommand(command, machine=remote,
85 chromeos_root=chromeos_root)
asharif54cf6782013-02-16 02:11:03 +000086 host_login_script = tempfile.mktemp()
87 device_login_script = '/tmp/login.py'
asharifd2ced682013-02-16 01:05:17 +000088 login_script_list = [script_header, wait_for_login_screen]
89 if login:
90 login_script_list.append(do_login)
91
92 full_login_script_contents = "\n".join(login_script_list)
93
asharif54cf6782013-02-16 02:11:03 +000094 with open(host_login_script, 'w') as f:
asharifd8136e42013-02-15 23:18:03 +000095 f.write(full_login_script_contents)
asharif54cf6782013-02-16 02:11:03 +000096 ce.CopyFiles(host_login_script,
97 device_login_script,
asharifd8136e42013-02-15 23:18:03 +000098 dest_machine=remote,
99 chromeos_root=chromeos_root,
100 recursive=False,
101 dest_cros=True)
asharif54cf6782013-02-16 02:11:03 +0000102 ret = ce.CrosRunCommand('python %s' % device_login_script,
103 chromeos_root=chromeos_root,
104 machine=remote)
105 if os.path.exists(host_login_script):
106 os.remove(host_login_script)
107 return ret
asharifd8136e42013-02-15 23:18:03 +0000108
109
110def Main(argv):
111 """The main function."""
112 parser = optparse.OptionParser()
113 parser.add_option('-r',
114 '--remote',
115 dest='remote',
116 help='The remote ChromeOS box.')
117 parser.add_option('-c',
118 '--chromeos_root',
119 dest='chromeos_root',
120 help='The ChromeOS root.')
121
122 options, args = parser.parse_args(argv)
123
asharif54cf6782013-02-16 02:11:03 +0000124 return RestartUI(options.remote, options.chromeos_root)
asharifd8136e42013-02-15 23:18:03 +0000125
126if __name__ == '__main__':
127 retval = Main(sys.argv)
asharif5ab1c7d2013-02-15 23:43:58 +0000128 sys.exit(retval)