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 zipfile | |
| 10 import subprocess | |
| 11 | |
| 12 def replacePrefPane(mock_pref_pane): | |
| 13 pref_pane_dir = "/Library/PreferencePanes" | |
| 14 chromoting_test_dir = "chrome/test/functional/chromoting" | |
|
Nirnimesh
2012/07/31 20:15:10
use os.path.join
yihongg1
2012/08/03 00:40:06
Done.
| |
| 15 subprocess.call(["rm", "-rf", pref_pane_dir + "/" + mock_pref_pane]) | |
| 16 subprocess.call(["cp", "-f", chromoting_test_dir + "/" + mock_pref_pane, pref_ pane_dir]) | |
| 17 subprocess.call(["chmod", "a+x", pref_pane_dir + "/" + mock_pref_pane]) | |
| 18 subprocess.call(["rm", "-rf", pref_pane_dir + "/org.chromium.chromoting.prefPa ne"]) | |
| 19 subprocess.call(["ln", "-s", pref_pane_dir + "/" + mock_pref_pane, | |
| 20 pref_pane_dir + "/org.chromium.chromoting.prefPane"]) | |
| 21 | |
| 22 def main(): | |
| 23 if sys.argv[1] == 'install': | |
| 24 if sys.platform.startswith('win'): | |
| 25 host_msi = sys.argv[2] + "\\remoting-host.msi" | |
| 26 subprocess.Popen(["msiexec", "/i", host_msi, "/passive"]).wait() | |
| 27 elif sys.platform.startswith('darwin'): | |
| 28 assert os.geteuid() == 0, 'Need superuser privileges' | |
| 29 | |
| 30 # Run most of the steps here with login user | |
| 31 login_uid = os.getuid() | |
| 32 os.seteuid(login_uid) | |
| 33 | |
| 34 # Change the working dir to the dir that has the host zip file | |
| 35 current_dir = os.getcwd() | |
| 36 bin_dir = sys.argv[2] | |
| 37 os.chdir(bin_dir) | |
| 38 | |
| 39 # Remove remoting-me2me-host-mac dir just in case | |
| 40 subprocess.call("rm -f -R remoting-me2me-host-mac", shell=True) | |
| 41 | |
| 42 # Unzip the host archive and prepare the files/dirs | |
| 43 subprocess.call("unzip remoting-me2me-host-mac.zip", shell=True) | |
| 44 subprocess.call("mkdir remoting-me2me-host-mac/output", shell=True) | |
| 45 | |
| 46 # Prepare security identity for code signing purpose | |
| 47 os.seteuid(0) | |
| 48 key_chain = "/Library/Keychains/ChromotingTest" | |
| 49 password = "1111" | |
| 50 chromoting_test_dir = current_dir + "/chrome/test/functional/chromoting" | |
| 51 subprocess.call(["security", "delete-keychain", key_chain]) | |
| 52 subprocess.call(["security", "create-keychain", "-p", password, key_chain] ) | |
| 53 subprocess.call(["security", "import", chromoting_test_dir + "/chromoting_ key.p12", | |
| 54 "-k", key_chain, "-P", password, "-A"]) | |
| 55 subprocess.call(["security", "import", chromoting_test_dir + "/chromoting_ cert.p12", | |
| 56 "-k", key_chain, "-P", password]) | |
| 57 os.seteuid(login_uid) | |
| 58 | |
| 59 # Sign the host | |
| 60 subprocess.call("./remoting-me2me-host-mac/do_signing.sh remoting-me2me-ho st-mac/output remoting-me2me-host-mac " | |
| 61 + key_chain + " \"Chromoting Test\"", shell=True) | |
| 62 | |
| 63 # Remove security identify | |
| 64 os.seteuid(0) | |
| 65 subprocess.call(["security", "delete-keychain", key_chain]) | |
| 66 os.seteuid(login_uid) | |
| 67 | |
| 68 # Figure out the dmg name | |
| 69 version = "" | |
| 70 for file in os.listdir("remoting-me2me-host-mac/output"): | |
| 71 if file.endswith(".dmg"): | |
| 72 version = os.path.basename(file)[len("ChromotingHost-"):-4] | |
| 73 | |
| 74 # Mount before installation | |
| 75 subprocess.call("hdiutil mount remoting-me2me-host-mac/output/ChromotingHo st-" + version + ".dmg", shell=True) | |
| 76 | |
| 77 # Install host | |
| 78 os.seteuid(0) | |
| 79 subprocess.call(["/usr/sbin/installer", | |
| 80 "-pkg", "/Volumes/Chromoting Host " + version + "/Chromot ing Host.mpkg", | |
| 81 "-target", "/"]) | |
| 82 os.seteuid(login_uid) | |
| 83 | |
| 84 # Unmount after installation | |
| 85 subprocess.call("hdiutil unmount \"/Volumes/Chromoting Host " + version + "\"", shell=True) | |
| 86 | |
| 87 # Clean up remoting-me2me-host-mac dir | |
| 88 subprocess.call("rm -f -R remoting-me2me-host-mac", shell=True) | |
| 89 | |
| 90 # Resume the original working dir | |
| 91 os.chdir(current_dir) | |
| 92 else: | |
| 93 print("Nothing to be done for install") | |
| 94 elif sys.argv[1] == 'uninstall': | |
| 95 if sys.platform.startswith('win'): | |
| 96 host_msi = sys.argv[2] + "\\remoting-host.msi" | |
| 97 subprocess.Popen(["msiexec", "/x", host_msi, "/passive"]).wait() | |
| 98 elif sys.platform.startswith('darwin'): | |
| 99 assert os.geteuid() == 0, 'Need superuser privileges' | |
| 100 subprocess.call(["open", "-a", "/Applications/Chromoting Host Uninstaller. app"]) | |
| 101 else: | |
| 102 print("Nothing to be done for uninstall") | |
| 103 elif sys.argv[1] == 'enable': | |
| 104 if sys.platform.startswith('darwin'): | |
| 105 assert os.geteuid() == 0, 'Need superuser privileges' | |
| 106 replacePrefPane("mock_pref_pane_enable") | |
| 107 else: | |
| 108 print("Nothing to be done for enable") | |
| 109 elif sys.argv[1] == 'disable': | |
| 110 if sys.platform.startswith('darwin'): | |
| 111 assert os.geteuid() == 0, 'Need superuser privileges' | |
| 112 replacePrefPane("mock_pref_pane_disable") | |
| 113 else: | |
| 114 print("Nothing to be done for disable") | |
| 115 elif sys.argv[1] == 'changepin': | |
| 116 if sys.platform.startswith('darwin'): | |
| 117 assert os.geteuid() == 0, 'Need superuser privileges' | |
| 118 replacePrefPane("mock_pref_pane_changepin") | |
| 119 else: | |
| 120 print("Nothing to be done for changepin") | |
| 121 else: | |
| 122 print >>sys.stderr, ( | |
| 123 'Invalid syntax') | |
| 124 return 1 | |
| 125 return 0 | |
| 126 | |
| 127 | |
| 128 if __name__ == '__main__': | |
| 129 sys.exit(main()) | |
| OLD | NEW |