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

Commit 5775699

Browse files
niteskumnethip
authored andcommitted
AutoUpdate Mac Installer Script Administrator privileges changes (#656)
* Changes to run Update Script in elevated Mode * Removed Unintentional Changes * Correct File Permission check changes * Corrected remove Command * Addressed Review Comments
1 parent 7a30c21 commit 5775699

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

appshell/update_mac.mm

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ + (void) setParams:(NSMutableDictionary *)params {
6767
_params = params;
6868
}
6969

70+
7071
// Runs a script, given the script path, and args array.
7172
int RunScript(NSString* launchPath, NSArray* argsArray, BOOL waitUntilExit)
7273
{
@@ -172,9 +173,39 @@ + (void) RunAppUpdate{
172173
else {
173174
int pid = [self getCurrentProcessID];
174175
NSString* pidString = [NSString stringWithFormat:@"%d", pid];
175-
pArgs = [NSArray arrayWithObjects:shPath, scriptPath, @"-a", bracketsAppName, @"-b", installDir, @"-l", logFilePath, @"-m", mountPoint, @"-t", updateDir, @"-p", pidString, @"&", nil];
176-
177-
retval = RunScript(nohupPath, pArgs, false);
176+
BOOL isAdmin = NO;
177+
178+
NSString *installDirPath = installDir;
179+
installDirPath = [installDirPath stringByAppendingString:@"/"];
180+
NSString *bracketsAppPath = installDirPath;
181+
bracketsAppPath = [bracketsAppPath stringByAppendingString:bracketsAppName];
182+
183+
NSFileManager *fm = [NSFileManager defaultManager];
184+
if([fm isWritableFileAtPath:installDirPath] && [fm isWritableFileAtPath:bracketsAppPath] )
185+
{
186+
isAdmin = YES;
187+
}
188+
189+
190+
/*Build the Apple Script String*/
191+
NSAppleEventDescriptor *returnDescriptor = NULL;
192+
NSString * appleScriptString;
193+
194+
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];
195+
196+
if(!isAdmin) {
197+
appleScriptString = [appleScriptString stringByAppendingString:@" with administrator privileges"];
198+
}
199+
200+
NSAppleScript *theScript = [[NSAppleScript alloc] initWithSource:appleScriptString];
201+
202+
NSDictionary *theError = nil;
203+
204+
returnDescriptor = [theScript executeAndReturnError: &theError];
205+
if(returnDescriptor == NULL) {
206+
NSString *logStr = @"ERROR: scriptexecution Failed error: BA_06";
207+
[logStr writeToFile:installStatusFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
208+
}
178209
}
179210
}
180211
}

installer/mac/update.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ function updateBrackets(){
172172
printInfo "Unmounted the DMG and attempying to open Brackets ..."
173173
fi
174174

175+
rm -rf "$TEMP_DIR/$APP_NAME"
175176
open -a "$APP_DIR/$APP_NAME"
176177
exitStatus=$?
177178
if [ $exitStatus -ne 0 ]

0 commit comments

Comments
 (0)