Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Chromoting helper to install/uninstall host and replace pref pane.""" | |
| 7 | |
| 8 import abc | |
| 9 import os | |
| 10 import shutil | |
| 11 import sys | |
| 12 import subprocess | |
| 13 | |
| 14 | |
| 15 class ChromotingHelper(object): | |
| 16 """Chromoting helper base class.""" | |
| 17 __metaclass__ = abc.ABCMeta | |
| 18 | |
| 19 @abc.abstractmethod | |
| 20 def InstallHost(self, bin_dir): | |
| 21 """Installs the chromoting host""" | |
| 22 return | |
| 23 | |
| 24 def UninstallHost(self, bin_dir): | |
|
Nirnimesh
2012/08/14 22:09:30
this method isn't abstract?
yihongg
2012/08/15 17:48:38
Done.
| |
| 25 """Uninstalls the chromoting host""" | |
| 26 return | |
| 27 | |
| 28 | |
| 29 class ChromotingHelperMac(ChromotingHelper): | |
| 30 """Chromoting Helper class for Mac. | |
| 31 | |
| 32 Installs/uninstalls host and replace the pref pane for testing purpose. | |
| 33 """ | |
| 34 | |
| 35 def InstallHost(self, bin_dir): | |
| 36 """Installs host on Mac.""" | |
| 37 assert os.geteuid() == 0, 'Need superuser privileges' | |
| 38 | |
| 39 # Run most of the steps here with login user | |
| 40 login_uid = os.getuid() | |
| 41 os.seteuid(login_uid) | |
| 42 | |
| 43 # Change the working dir to the dir that has the host zip file | |
| 44 current_dir = os.getcwd() | |
| 45 os.chdir(bin_dir) | |
| 46 host_dir = 'remoting-me2me-host-mac' | |
| 47 output_dir = os.path.join(host_dir, 'output') | |
| 48 | |
| 49 # Remove remoting-me2me-host-mac dir just in case | |
| 50 #subprocess.call('rm -f -R ' + host_dir, shell=True) | |
| 51 shutil.rmtree(host_dir, True) | |
| 52 | |
| 53 # Unzip the host archive and prepare the files/dirs | |
| 54 subprocess.call('unzip remoting-me2me-host-mac.zip', shell=True) | |
| 55 subprocess.call('mkdir ' + output_dir, shell=True) | |
| 56 | |
| 57 # Prepare security identity for code signing purpose | |
| 58 os.seteuid(0) | |
| 59 key_chain = '/Library/Keychains/ChromotingTest' | |
| 60 password = '1111' | |
| 61 key = os.path.join(current_dir, 'chrome', 'test', | |
| 62 'pyautolib', 'chromoting_key.p12') | |
| 63 cert = os.path.join(current_dir, 'chrome', 'test', | |
| 64 'pyautolib', 'chromoting_cert.p12') | |
| 65 subprocess.call(['security', 'delete-keychain', key_chain]) | |
| 66 subprocess.call(['security', 'create-keychain', '-p', | |
| 67 password, key_chain]) | |
| 68 subprocess.call(['security', 'import', key, | |
| 69 '-k', key_chain, '-P', password, '-A']) | |
| 70 subprocess.call(['security', 'import', cert, | |
| 71 '-k', key_chain, '-P', password]) | |
| 72 os.seteuid(login_uid) | |
| 73 | |
| 74 # Sign the host | |
| 75 do_signing = os.path.join(host_dir, 'do_signing.sh') | |
| 76 subprocess.call(do_signing + ' ' + output_dir + ' ' + host_dir + ' ' + | |
| 77 key_chain + ' "Chromoting Test"', shell=True) | |
| 78 | |
| 79 # Remove security identify | |
| 80 os.seteuid(0) | |
| 81 subprocess.call(['security', 'delete-keychain', key_chain]) | |
| 82 os.seteuid(login_uid) | |
| 83 | |
| 84 # Figure out the dmg name | |
| 85 version = "" | |
| 86 for output_file in os.listdir(output_dir): | |
| 87 if output_file.endswith('.dmg'): | |
| 88 version = os.path.basename(output_file)[len('ChromotingHost-'):-4] | |
| 89 | |
| 90 # Mount before installation | |
| 91 dmg = os.path.join(output_dir, 'ChromotingHost-' + version + '.dmg') | |
| 92 subprocess.call('hdiutil' + ' mount ' + dmg, shell=True) | |
| 93 | |
| 94 # Install host | |
| 95 os.seteuid(0) | |
| 96 mpkg = os.path.join('/Volumes', 'Chromoting Host ' + version, | |
| 97 'Chromoting Host.mpkg') | |
| 98 subprocess.call(['/usr/sbin/installer', '-pkg', | |
| 99 mpkg, '-target', '/']) | |
| 100 os.seteuid(login_uid) | |
| 101 | |
| 102 # Unmount after installation | |
| 103 mounted = os.path.join('/Volumes', 'Chromoting Host ' + version) | |
| 104 subprocess.call('hdiutil unmount "' + mounted + '"', shell=True) | |
| 105 | |
| 106 # Clean up remoting-me2me-host-mac dir | |
| 107 #subprocess.call('rm -f -R ' + host_dir, shell=True) | |
|
Nirnimesh
2012/08/14 22:09:30
remove commented out code
yihongg
2012/08/15 17:48:38
Done.
| |
| 108 shutil.rmtree(host_dir, True) | |
| 109 | |
| 110 # Resume the original working dir | |
| 111 os.chdir(current_dir) | |
| 112 | |
| 113 def UninstallHost(self, bin_dir): | |
| 114 """Uninstalls host on Mac.""" | |
| 115 assert os.geteuid() == 0, 'Need superuser privileges' | |
| 116 uninstall_app = os.path.join('/', 'Applications', | |
| 117 'Chromoting Host Uninstaller.app') | |
| 118 subprocess.call(['open', '-a', uninstall_app]) | |
| 119 | |
| 120 def ReplacePrefPaneMac(self, operation): | |
| 121 """Constructs mock pref pane to replace the actual pref pane on Mac.""" | |
| 122 assert os.geteuid() == 0, 'Need superuser privileges' | |
| 123 | |
| 124 pref_pane_dir = os.path.join('/Library', 'PreferencePanes') | |
| 125 | |
| 126 mock_pref_pane = os.path.join(pref_pane_dir, 'mock_pref_pane') | |
| 127 pref_pane = os.path.join(pref_pane_dir, 'org.chromium.chromoting.prefPane') | |
| 128 mock_pref_pane_python = os.path.join(os.getcwd(), 'chrome', 'test', | |
| 129 'functional', 'chromoting', | |
| 130 'mock_pref_pane.py') | |
| 131 | |
| 132 #subprocess.call(['rm', '-rf', mock_pref_pane]) | |
| 133 shutil.rmtree(mock_pref_pane, True) | |
| 134 | |
| 135 mock_pref_pane_file = open(mock_pref_pane, 'w') | |
| 136 mock_pref_pane_file.write('#!/bin/bash\n') | |
| 137 mock_pref_pane_file.write('\n') | |
| 138 mock_pref_pane_file.write('suid-python' + | |
| 139 ' ' + mock_pref_pane_python + ' ' + operation) | |
| 140 mock_pref_pane_file.close() | |
| 141 | |
| 142 subprocess.call(['chmod', 'a+x', mock_pref_pane]) | |
| 143 #subprocess.call(['rm', '-rf', pref_pane]) | |
| 144 shutil.rmtree(pref_pane, True) | |
| 145 subprocess.call(['ln', '-s', mock_pref_pane, pref_pane]) | |
| 146 | |
|
Nirnimesh
2012/08/14 22:09:30
need another blank line
yihongg
2012/08/15 17:48:38
Done.
| |
| 147 class ChromotingHelperWindows(ChromotingHelper): | |
| 148 """Chromoting Helper class for Windows for installing/uninstalling host.""" | |
| 149 | |
| 150 def InstallHost(self, bin_dir): | |
| 151 """Installs host on Windows.""" | |
| 152 host_msi = os.path.join(bin_dir, 'remoting-host.msi') | |
| 153 subprocess.Popen(['msiexec', '/i', host_msi, '/passive']).wait() | |
| 154 | |
| 155 def UninstallHost(self, bin_dir): | |
| 156 """Uninstalls host on Windows.""" | |
| 157 host_msi = os.path.join(bin_dir, 'remoting-host.msi') | |
| 158 subprocess.Popen(['msiexec', '/x', host_msi, '/passive']).wait() | |
| 159 | |
| 160 | |
| 161 def Main(): | |
| 162 """Main function to dispatch operations.""" | |
| 163 assert sys.platform.startswith('win') or \ | |
| 164 sys.platform.startswith('darwin'), \ | |
| 165 'Only support Windows and Mac' | |
| 166 | |
| 167 if sys.platform.startswith('win'): | |
| 168 helper = ChromotingHelperWindows() | |
| 169 elif sys.platform.startswith('darwin'): | |
| 170 helper = ChromotingHelperMac() | |
| 171 | |
| 172 if sys.argv[1] == 'install': | |
| 173 helper.InstallHost(sys.argv[2]) | |
| 174 elif sys.argv[1] == 'uninstall': | |
| 175 helper.UninstallHost(sys.argv[2]) | |
| 176 elif sys.argv[1] in ['enable', 'disable', 'changepin']: | |
| 177 assert sys.platform.startswith('darwin'), \ | |
| 178 'Replacing pref pane is Mac specific' | |
| 179 helper.ReplacePrefPaneMac(sys.argv[1]) | |
| 180 else: | |
| 181 print >>sys.stderr, 'Invalid syntax' | |
| 182 return 1 | |
| 183 | |
| 184 | |
| 185 if __name__ == '__main__': | |
| 186 Main() | |
| OLD | NEW |