Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

AutoUpdate Mac Installer Script Administrator privileges changes #656

Merged
merged 5 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions appshell/update_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ + (void) setParams:(NSMutableDictionary *)params {
_params = params;
}


// Runs a script, given the script path, and args array.
int RunScript(NSString* launchPath, NSArray* argsArray, BOOL waitUntilExit)
{
Expand Down Expand Up @@ -172,9 +173,39 @@ + (void) RunAppUpdate{
else {
int pid = [self getCurrentProcessID];
NSString* pidString = [NSString stringWithFormat:@"%d", pid];
pArgs = [NSArray arrayWithObjects:shPath, scriptPath, @"-a", bracketsAppName, @"-b", installDir, @"-l", logFilePath, @"-m", mountPoint, @"-t", updateDir, @"-p", pidString, @"&", nil];

retval = RunScript(nohupPath, pArgs, false);
BOOL isAdmin = NO;

NSString *installDirPath = installDir;
installDirPath = [installDirPath stringByAppendingString:@"/"];
NSString *bracketsAppPath = installDirPath;
bracketsAppPath = [bracketsAppPath stringByAppendingString:bracketsAppName];

NSFileManager *fm = [NSFileManager defaultManager];
if([fm isWritableFileAtPath:installDirPath] && [fm isWritableFileAtPath:bracketsAppPath] )
{
isAdmin = YES;
}


/*Build the Apple Script String*/
NSAppleEventDescriptor *returnDescriptor = NULL;
NSString * appleScriptString;

appleScriptString = [NSString stringWithFormat:@"do shell script \"%@ %@ %@ -a %@ -b '%@' -l '%@' -m %@ -t '%@' -p %@ > /dev/null 2>&1 &\"", nohupPath, shPath, scriptPath, bracketsAppName, installDir, logFilePath, mountPoint, updateDir, pidString];

if(!isAdmin) {
appleScriptString = [appleScriptString stringByAppendingString:@" with administrator privileges"];
}

NSAppleScript *theScript = [[NSAppleScript alloc] initWithSource:appleScriptString];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theScript string needs be freed. But anyways since this in the destruction sequence I guess we can live with it.


NSDictionary *theError = nil;

returnDescriptor = [theScript executeAndReturnError: &theError];
if(returnDescriptor == NULL) {
NSString *logStr = @"ERROR: scriptexecution Failed error: BA_06";
[logStr writeToFile:installStatusFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions installer/mac/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function updateBrackets(){
printInfo "Unmounted the DMG and attempying to open Brackets ..."
fi

rm -rf "$TEMP_DIR/$APP_NAME"
open -a "$APP_DIR/$APP_NAME"
exitStatus=$?
if [ $exitStatus -ne 0 ]
Expand Down