blob: 7d8bb11e07a29fea5a7560fef42b2ee048616069 [file] [log] [blame]
asharifd8136e42013-02-15 23:18:03 +00001#!/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
11import datetime
12import fcntl
13import getpass
14import glob
15import optparse
16import os
17import pickle
18import socket
19import sys
20import time
21from utils import logger
22from utils import command_executer
23
24LOGIN_PROMPT_VISIBLE_MAGIC_FILE = '/tmp/uptime-login-prompt-visible'
25LOGGED_IN_MAGIC_FILE = '/var/run/state/logged-in'
26
27
asharifd2ced682013-02-16 01:05:17 +000028script_header="""
asharifd8136e42013-02-15 23:18:03 +000029import os
30import autox
31import time
asharifd2ced682013-02-16 01:05:17 +000032"""
33
34wait_for_login_screen="""
asharifd8136e42013-02-15 23:18:03 +000035
36while 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
43time.sleep(20)
asharifd2ced682013-02-16 01:05:17 +000044""" % LOGIN_PROMPT_VISIBLE_MAGIC_FILE
asharifd8136e42013-02-15 23:18:03 +000045
asharifd2ced682013-02-16 01:05:17 +000046
47do_login="""
asharifd8136e42013-02-15 23:18:03 +000048xauth_filename = '/home/chronos/.Xauthority'
49os.environ.setdefault('XAUTHORITY', xauth_filename)
50os.environ.setdefault('DISPLAY', ':0.0')
51
52print 'Now sending the hotkeys for logging in.'
53ax = autox.AutoX()
54# navigate to login screen
55ax.send_hotkey('Ctrl+Shift+q')
56ax.send_hotkey('Ctrl+Alt+l')
57# escape out of any login screen menus (e.g., the network select menu)
58time.sleep(2)
59ax.send_hotkey('Escape')
60time.sleep(2)
61ax.send_hotkey('Tab')
62time.sleep(0.5)
63ax.send_hotkey('Tab')
64time.sleep(0.5)
65ax.send_hotkey('Tab')
66time.sleep(0.5)
67ax.send_hotkey('Tab')
68time.sleep(0.5)
69ax.send_hotkey('Return')
70print 'Waiting for Chrome to appear...'
71while True:
72 if os.path.isfile('%s'):
73 break
74 time.sleep(1)
75print 'Done'
asharifd2ced682013-02-16 01:05:17 +000076""" % LOGGED_IN_MAGIC_FILE
asharifd8136e42013-02-15 23:18:03 +000077
asharifd2ced682013-02-16 01:05:17 +000078def RestartUI(remote, chromeos_root, login=True):
asharifd8136e42013-02-15 23:18:03 +000079 chromeos_root = os.path.expanduser(chromeos_root)
80 ce = command_executer.GetCommandExecuter()
81 # First, restart ui.
asharifd2ced682013-02-16 01:05:17 +000082 command = 'rm -rf %s && restart ui' % LOGIN_PROMPT_VISIBLE_MAGIC_FILE
asharifd8136e42013-02-15 23:18:03 +000083 ce.CrosRunCommand(command, machine=remote,
84 chromeos_root=chromeos_root)
85 login_script = '/tmp/login.py'
asharifd2ced682013-02-16 01:05:17 +000086 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
asharifd8136e42013-02-15 23:18:03 +000092 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
105def 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
121if __name__ == '__main__':
122 retval = Main(sys.argv)
asharif5ab1c7d2013-02-15 23:43:58 +0000123 sys.exit(retval)