mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Installation of the gitx command-line tool.
We use ln(1) via AuthorizationExecuteWithPrivileges() to create a symlink to gitx in /usr/bin.
This commit is contained in:
+34
-8
@@ -57,14 +57,40 @@
|
||||
|
||||
- (IBAction)installCliTool:(id)sender;
|
||||
{
|
||||
NSString* command = [NSString stringWithFormat:@"sudo ln -s '%@' /usr/bin/gitx", [[NSBundle mainBundle] pathForResource:@"gitx" ofType:@""]];
|
||||
[[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
|
||||
[[NSPasteboard generalPasteboard] setString:command forType:NSStringPboardType];
|
||||
[[NSAlert alertWithMessageText:@"Not Implemented"
|
||||
defaultButton:nil
|
||||
alternateButton:nil
|
||||
otherButton:nil
|
||||
informativeTextWithFormat:@"Sorry, automatic installation is not implemented yet. You can run the command\n\t%@\nto install it (I’ve copied this command to your clipboard).", command] runModal];
|
||||
BOOL success = NO;
|
||||
NSString* installationPath = @"/usr/bin/gitx";
|
||||
NSString* toolPath = [[NSBundle mainBundle] pathForResource:@"gitx" ofType:@""];
|
||||
if (toolPath) {
|
||||
AuthorizationRef auth;
|
||||
if (AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth) == errAuthorizationSuccess) {
|
||||
char const* arguments[] = { "-s", [toolPath UTF8String], [installationPath UTF8String], NULL };
|
||||
char const* helperTool = "/bin/ln";
|
||||
if (AuthorizationExecuteWithPrivileges(auth, helperTool, kAuthorizationFlagDefaults, (char**)arguments, NULL) == errAuthorizationSuccess) {
|
||||
int status;
|
||||
int pid = wait(&status);
|
||||
if (pid != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
||||
success = true;
|
||||
else
|
||||
errno = WEXITSTATUS(status);
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, kAuthorizationFlagDefaults);
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
[[NSAlert alertWithMessageText:@"Installation Complete"
|
||||
defaultButton:nil
|
||||
alternateButton:nil
|
||||
otherButton:nil
|
||||
informativeTextWithFormat:@"The gitx tool has been installed to %@", installationPath] runModal];
|
||||
} else {
|
||||
[[NSAlert alertWithMessageText:@"Installation Failed"
|
||||
defaultButton:nil
|
||||
alternateButton:nil
|
||||
otherButton:nil
|
||||
informativeTextWithFormat:@"Installation to %@ failed", installationPath] runModal];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) switchBranch: sender
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
911111E20E58BD5A00BF76B4 /* RepositoryWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 911111E00E58BD5A00BF76B4 /* RepositoryWindow.xib */; };
|
||||
911111F80E594F3F00BF76B4 /* PBRepositoryDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 911111F70E594F3F00BF76B4 /* PBRepositoryDocumentController.m */; };
|
||||
911112370E5A097800BF76B4 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 911112360E5A097800BF76B4 /* Security.framework */; };
|
||||
913D5E4D0E55644E00CECEA2 /* gitx.mm in Sources */ = {isa = PBXBuildFile; fileRef = 913D5E440E55640C00CECEA2 /* gitx.mm */; };
|
||||
913D5E500E55645900CECEA2 /* gitx in Resources */ = {isa = PBXBuildFile; fileRef = 913D5E490E55644600CECEA2 /* gitx */; };
|
||||
913D5E5F0E556A9300CECEA2 /* PBCLIProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 913D5E5E0E556A9300CECEA2 /* PBCLIProxy.mm */; };
|
||||
@@ -65,6 +66,7 @@
|
||||
911111E10E58BD5A00BF76B4 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/RepositoryWindow.xib; sourceTree = "<group>"; };
|
||||
911111F60E594F3F00BF76B4 /* PBRepositoryDocumentController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBRepositoryDocumentController.h; sourceTree = "<group>"; };
|
||||
911111F70E594F3F00BF76B4 /* PBRepositoryDocumentController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBRepositoryDocumentController.m; sourceTree = "<group>"; };
|
||||
911112360E5A097800BF76B4 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; };
|
||||
913D5E440E55640C00CECEA2 /* gitx.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = gitx.mm; sourceTree = "<group>"; };
|
||||
913D5E490E55644600CECEA2 /* gitx */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = gitx; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
913D5E5D0E556A9300CECEA2 /* PBCLIProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCLIProxy.h; sourceTree = "<group>"; };
|
||||
@@ -110,6 +112,7 @@
|
||||
files = (
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
|
||||
F56526240E03D85900F03B52 /* WebKit.framework in Frameworks */,
|
||||
911112370E5A097800BF76B4 /* Security.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -142,6 +145,7 @@
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
911112360E5A097800BF76B4 /* Security.framework */,
|
||||
77C82804067257F0000B614F /* CoreData.framework */,
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
|
||||
|
||||
Reference in New Issue
Block a user