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