diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 18:45:33 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 18:45:33 +0000 |
commit | 259084b646d4add5ded8a786ec7f7c23e94b9b57 (patch) | |
tree | 76b46390f909bc9dc5775e1ff9a917da54b0068c /chrome/installer/gcapi_mac | |
parent | 050c876844e7a30b95fe4a724061fe2dce71b702 (diff) | |
download | chromium_src-259084b646d4add5ded8a786ec7f7c23e94b9b57.zip chromium_src-259084b646d4add5ded8a786ec7f7c23e94b9b57.tar.gz chromium_src-259084b646d4add5ded8a786ec7f7c23e94b9b57.tar.bz2 |
mac: Expand gcapi_example
Fix issues found by running it.
BUG=128462
TEST=Run this on machines without keystone and with keystone,
from a user account, and through sudo. Check the installed
chrome looks good, and that keystone gets installed if
necessary.
Review URL: https://chromiumcodereview.appspot.com/10446018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138849 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/gcapi_mac')
-rw-r--r-- | chrome/installer/gcapi_mac/gcapi.mm | 18 | ||||
-rw-r--r-- | chrome/installer/gcapi_mac/gcapi_example_client.mm | 73 |
2 files changed, 79 insertions, 12 deletions
diff --git a/chrome/installer/gcapi_mac/gcapi.mm b/chrome/installer/gcapi_mac/gcapi.mm index 226fb46..ff246ca 100644 --- a/chrome/installer/gcapi_mac/gcapi.mm +++ b/chrome/installer/gcapi_mac/gcapi.mm @@ -190,7 +190,7 @@ BOOL WriteMasterPrefs(const char* master_prefs_contents, } NSString* PathToFramework(NSString* app_path, NSDictionary* info_plist) { - NSString* version = [info_plist objectForKey:(NSString*)kCFBundleVersionKey]; + NSString* version = [info_plist objectForKey:@"CFBundleShortVersionString"]; if (!version) return nil; return [[[app_path @@ -201,7 +201,7 @@ NSString* PathToFramework(NSString* app_path, NSDictionary* info_plist) { NSString* PathToInstallScript(NSString* app_path, NSDictionary* info_plist) { return [PathToFramework(app_path, info_plist) stringByAppendingPathComponent: - @"Contents/Resources/install.sh"]; + @"Resources/install.sh"]; } NSString* PathToKeystoneResources( @@ -224,7 +224,7 @@ NSString* FindOrInstallKeystone(NSString* app_path, NSDictionary* info_plist) { @try { NSTask* task = [[[NSTask alloc] init] autorelease]; [task setLaunchPath:ks_install]; - [task setArguments:@[ks_tbz]]; + [task setArguments:@[@"--install", ks_tbz]]; [task launch]; [task waitUntilExit]; if ([task terminationStatus] == 0) @@ -254,7 +254,7 @@ int GoogleChromeCompatibilityCheck(unsigned* reasons) { if (HasChromeTicket(kSystemTicket)) local_reasons |= GCCC_ERROR_SYSTEMLEVELALREADYPRESENT; - if (HasChromeTicket(kUserTicket)) + if (geteuid() != 0 && HasChromeTicket(kUserTicket)) local_reasons |= GCCC_ERROR_USERLEVELALREADYPRESENT; if (![[NSFileManager defaultManager] isWritableFileAtPath:@"/Applications"]) @@ -286,8 +286,9 @@ int InstallGoogleChrome(const char* source_path, // Use install.sh from the Chrome app bundle to copy Chrome to its // destination. NSString* install_script = PathToInstallScript(app_path, info_plist); - if (!install_script) + if (!install_script) { return 0; + } @try { NSTask* task = [[[NSTask alloc] init] autorelease]; @@ -295,8 +296,9 @@ int InstallGoogleChrome(const char* source_path, [task setArguments:@[app_path, kChromeInstallPath]]; [task launch]; [task waitUntilExit]; - if ([task terminationStatus] != 0) + if ([task terminationStatus] != 0) { return 0; + } } @catch (id exception) { return 0; @@ -308,12 +310,12 @@ int InstallGoogleChrome(const char* source_path, [info_plist_brand respondsToSelector:@selector(UTF8String)]) brand_code = [info_plist_brand UTF8String]; - BOOL valid_brand_code = strlen(brand_code) == 4 && + BOOL valid_brand_code = brand_code && strlen(brand_code) == 4 && isbrandchar(brand_code[0]) && isbrandchar(brand_code[1]) && isbrandchar(brand_code[2]) && isbrandchar(brand_code[3]); NSString* brand_path = nil; - if (brand_code && valid_brand_code) + if (valid_brand_code) brand_path = WriteBrandCode(brand_code); // Write master prefs. diff --git a/chrome/installer/gcapi_mac/gcapi_example_client.mm b/chrome/installer/gcapi_mac/gcapi_example_client.mm index 4b27496..580419e 100644 --- a/chrome/installer/gcapi_mac/gcapi_example_client.mm +++ b/chrome/installer/gcapi_mac/gcapi_example_client.mm @@ -5,11 +5,76 @@ #include "chrome/installer/gcapi_mac/gcapi.h" #import <Foundation/Foundation.h> +#include <getopt.h> + +#include <string> + +void Usage() { + fprintf(stderr, +"usage: gcapi_example [options]\n" +"\n" +"options:\n" +" --force-reinstall delete Google Chrome from Applications first\n" +" --install <path> copy <path> to /Applications/Google Chrome.app, set up\n" +" --brand <CODE> set brandcode to <CODE> during installation\n" +" --launch launch Google Chrome when all is done\n" +" --help print this message\n" +); +} + +int main(int argc, char* argv[]) { + const option kLongOptions[] = { + { "force-reinstall", no_argument, NULL, 'r' }, + { "install", required_argument, NULL, 'i' }, + { "brand", required_argument, NULL, 'b' }, + { "launch", no_argument, NULL, 'l' }, + { "help", no_argument, NULL, 'h' }, + { NULL, 0, NULL, 0 } + }; + + std::string source_path; + std::string brand_code; + bool reinstall = false; + bool launch = false; + int opt; + while ((opt = getopt_long(argc, argv, "ri:b:lh", kLongOptions, NULL)) != -1) { + switch (opt) { + case 'r': + reinstall = true; + break; + case 'i': + source_path = optarg; + break; + case 'b': + brand_code = optarg; + break; + case 'l': + launch = true; + break; + case 'h': + default: + Usage(); + return 1; + } + } + + if (reinstall) { + [[NSFileManager defaultManager] + removeItemAtPath:@"/Applications/Google Chrome.app" error:nil]; + } -int main() { unsigned reasons; - int b = GoogleChromeCompatibilityCheck(&reasons); - NSLog(@"%d: %x", b, reasons); + int can_install = GoogleChromeCompatibilityCheck(&reasons); + NSLog(@"can_install: %d, reasons %x", can_install, reasons); + + if (can_install && !source_path.empty()) { + int install_result = InstallGoogleChrome( + source_path.c_str(), + brand_code.empty() ? NULL : brand_code.c_str(), + NULL, 0); + NSLog(@"install result: %d", install_result); + } - LaunchGoogleChrome(); + if (launch) + LaunchGoogleChrome(); } |