@@ -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.
7172int 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 }
0 commit comments