@@ -55,7 +55,7 @@ def deplog(text):
5555
5656def iaslog (text ):
5757 try :
58- NSLog ('[InstallApplications] ' + text )
58+ NSLog ('[InstallApplications] %s' % text )
5959 except Exception :
6060 print (text )
6161 pass
@@ -220,21 +220,24 @@ def runrootscript(pathname, donotwait):
220220 if donotwait :
221221 iaslog ('Do not wait triggered' )
222222 proc = subprocess .Popen (pathname )
223- iaslog ('Running Script: %s ' % ( str ( pathname )) )
223+ iaslog ('Running Script: %s ' % pathname )
224224 else :
225+ iaslog ('Running Script: %s ' % pathname )
225226 proc = subprocess .Popen (pathname , stdout = subprocess .PIPE ,
226227 stderr = subprocess .PIPE )
227- iaslog ('Running Script: %s ' % (str (pathname )))
228228 (out , err ) = proc .communicate ()
229- iaslog ('Output from %s: %s' % (pathname , out ))
229+ iaslog ('Output on stdout:' )
230+ iaslog (out .decode ('utf-8' ))
230231 if err and proc .returncode == 0 :
231- iaslog ('Output from %s on stderr but ran successfully: %s' %
232- ( pathname , err ))
232+ iaslog ('Output on stderr but ran successfully:' )
233+ iaslog ( err . decode ( 'utf-8' ))
233234 elif proc .returncode > 0 :
234- iaslog ('Received non-zero exit code: ' + str (err ))
235+ iaslog ('Received non-zero exit code:' )
236+ iaslog (err .decode ('utf-8' ))
235237 return False
236238 except OSError as err :
237- iaslog ('Failure running script: ' + str (err ))
239+ iaslog ('Failure running script:' )
240+ iaslog (str (err .decode ('utf-8' )))
238241 return False
239242 return True
240243
@@ -248,20 +251,22 @@ def runuserscript(iauserscriptpath):
248251 os .remove (pathname )
249252 return True
250253 try :
254+ iaslog ('Running Script: %s ' % pathname )
251255 proc = subprocess .Popen (pathname , stdout = subprocess .PIPE ,
252256 stderr = subprocess .PIPE )
253- iaslog ('Running Script: %s ' % (str (pathname )))
254257 (out , err ) = proc .communicate ()
255- iaslog ('Output from %s: %s' % (pathname , out ))
258+ iaslog ('Output on stdout:' )
259+ iaslog (out .decode ('utf-8' ))
256260 if err and proc .returncode == 0 :
257- iaslog (
258- 'Output from %s on stderr but ran successfully: %s' %
259- (pathname , err ))
261+ iaslog ('Output on stderr but ran successfully:' )
262+ iaslog (err .decode ('utf-8' ))
260263 elif proc .returncode > 0 :
261- iaslog ('Failure running script: ' + str (err ))
264+ iaslog ('Received non-zero exit code:' )
265+ iaslog (err .decode ('utf-8' ))
262266 return False
263267 except OSError as err :
264- iaslog ('Failure running script: ' + str (err ))
268+ iaslog ('Failure running script:' )
269+ iaslog (str (err .decode ('utf-8' )))
265270 return False
266271 os .remove (pathname )
267272 return True
@@ -286,7 +291,7 @@ def download_if_needed(item, stage, type, opts, depnotifystatus):
286291 if opts .follow_redirects :
287292 item .update ({'follow_redirects' : True })
288293 # Download the file once:
289- iaslog ('Starting download: %s' % ( urllib .parse .unquote (itemurl ) ))
294+ iaslog ('Starting download: %s' % urllib .parse .unquote (itemurl ))
290295 if opts .depnotify :
291296 if stage == 'setupassistant' :
292297 iaslog ('Skipping DEPNotify notification due to setupassistant.'
@@ -332,22 +337,22 @@ def touch(path):
332337
333338def cleanup (exit_code ):
334339 # Attempt to remove the LaunchDaemon
335- iaslog ('Attempting to remove LaunchDaemon: ' + ialdpath )
340+ iaslog ('Attempting to remove LaunchDaemon: %s' % ialdpath )
336341 try :
337342 os .remove (ialdpath )
338343 except : # noqa
339344 pass
340345
341346 # Attempt to remove the LaunchAgent
342- iaslog ('Attempting to remove LaunchAgent: ' + ialapath )
347+ iaslog ('Attempting to remove LaunchAgent: %s' % ialapath )
343348 try :
344349 os .remove (ialapath )
345350 except : # noqa
346351 pass
347352
348353 # Attempt to remove the launchagent from the user's list
349- iaslog ('Targeting user id for LaunchAgent removal: ' + userid )
350- iaslog ('Attempting to remove LaunchAgent: ' + laidentifier )
354+ iaslog ('Targeting user id for LaunchAgent removal: %s' % userid )
355+ iaslog ('Attempting to remove LaunchAgent: %s' % laidentifier )
351356 launchctl ('/bin/launchctl' , 'asuser' , userid ,
352357 '/bin/launchctl' , 'remove' , laidentifier )
353358
@@ -367,13 +372,13 @@ def cleanup(exit_code):
367372 pass
368373
369374 # Attempt to kill InstallApplications' path
370- iaslog ('Attempting to remove InstallApplications directory: ' + iapath )
375+ iaslog ('Attempting to remove InstallApplications directory: %s' % iapath )
371376 try :
372377 shutil .rmtree (iapath )
373378 except : # noqa
374379 pass
375380
376- iaslog ('Attempting to remove LaunchDaemon: ' + ldidentifier )
381+ iaslog ('Attempting to remove LaunchDaemon: %s' % ldidentifier )
377382 launchctl ('/bin/launchctl' , 'remove' , ldidentifier )
378383 iaslog ('Cleanup done. Exiting.' )
379384 sys .exit (exit_code )
@@ -442,19 +447,19 @@ def main():
442447 iauserscriptpath = os .path .join (iapath , 'userscripts' )
443448 iatmppath = '/var/tmp/installapplications'
444449 ialogpath = '/var/log/installapplications'
445- iaslog ('InstallApplications path: ' + str ( iapath ) )
450+ iaslog ('InstallApplications path: %s' % iapath )
446451 global ldidentifier
447452 ldidentifier = opts .ldidentifier
448453 ldidentifierplist = opts .ldidentifier + '.plist'
449454 global ialdpath
450455 ialdpath = os .path .join ('/Library/LaunchDaemons' , ldidentifierplist )
451- iaslog ('InstallApplications LaunchDaemon path: ' + str ( ialdpath ) )
456+ iaslog ('InstallApplications LaunchDaemon path: %s' % ialdpath )
452457 global laidentifier
453458 laidentifier = opts .laidentifier
454459 laidentifierplist = opts .laidentifier + '.plist'
455460 global ialapath
456461 ialapath = os .path .join ('/Library/LaunchAgents' , laidentifierplist )
457- iaslog ('InstallApplications LaunchAgent path: ' + str ( ialapath ) )
462+ iaslog ('InstallApplications LaunchAgent path: %s' % ialapath )
458463 depnotifystatus = True
459464 global userid
460465 userid = str (getconsoleuser ()[1 ])
@@ -463,7 +468,7 @@ def main():
463468
464469 # hardcoded json fileurl path
465470 jsonpath = os .path .join (iapath , 'bootstrap.json' )
466- iaslog ('InstallApplications json path: ' + str ( jsonpath ) )
471+ iaslog ('InstallApplications json path: %s' % jsonpath )
467472
468473 # User script touch path
469474 userscripttouchpath = '/var/tmp/installapplications/.userscript'
@@ -504,7 +509,7 @@ def main():
504509 if 'DEPNotifySkipStatus' in notification :
505510 depnotifystatus = False
506511 else :
507- iaslog ('Sending %s to DEPNotify' % ( str ( notification )) )
512+ iaslog ('Sending %s to DEPNotify' % notification )
508513 deplog (notification )
509514
510515 # Make the temporary folder
@@ -537,8 +542,8 @@ def main():
537542
538543 # If the file doesn't exist, grab it and wait half a second to save.
539544 while not os .path .isfile (jsonpath ):
540- iaslog ('Starting download: %s' % ( urllib .parse .unquote (
541- json_data ['url' ])))
545+ iaslog ('Starting download: %s' % urllib .parse .unquote (
546+ json_data ['url' ]))
542547 downloadfile (json_data )
543548 time .sleep (0.5 )
544549
@@ -566,7 +571,7 @@ def main():
566571
567572 # Process all stages
568573 for stage in stages :
569- iaslog ('Beginning %s' % ( stage ) )
574+ iaslog ('Beginning %s' % stage )
570575 if stage == 'preflight' :
571576 # Ensure we actually have a preflight key in the json
572577 try :
@@ -624,8 +629,8 @@ def main():
624629 else :
625630 depnotifystring = 'depnotifycmd = ' \
626631 """['/usr/bin/open', '""" + depnotifypath + "']"
627- iaslog ('Launching DEPNotify with: %s' % ( depnotifystring ) )
628- depnotifyscript = "#!/Library/installapplications/Python.framework/Versions/3.8 /bin/python3"
632+ iaslog ('Launching DEPNotify with: %s' % depnotifystring )
633+ depnotifyscript = "#!/Library/installapplications/Python.framework/Versions/Current /bin/python3"
629634 depnotifyscript += '\n ' + "import subprocess"
630635 depnotifyscript += '\n ' + depnotifystring
631636 depnotifyscript += '\n ' + 'subprocess.call(depnotifycmd)'
@@ -671,7 +676,7 @@ def main():
671676 # pkg is not a required install
672677 if LooseVersion (checkreceipt (packageid )) >= LooseVersion (
673678 version ) and not pkg_required :
674- iaslog ('Skipping %s - already installed.' % ( name ) )
679+ iaslog ('Skipping %s - already installed.' % name )
675680 else :
676681 # Download the package if it isn't already on disk.
677682 download_if_needed (item , stage , type , opts ,
@@ -692,7 +697,7 @@ def main():
692697 if 'url' in item :
693698 download_if_needed (item , stage , type , opts ,
694699 depnotifystatus )
695- iaslog ('Starting root script: %s' % ( path ) )
700+ iaslog ('Starting root script: %s' % path )
696701 try :
697702 donotwait = item ['donotwait' ]
698703 except KeyError as e :
@@ -719,24 +724,24 @@ def main():
719724 if stage == 'setupassistant' :
720725 iaslog ('Detected setupassistant and user script. '
721726 'User scripts cannot work in setupassistant stage! '
722- 'Removing %s' % ( path ) )
727+ 'Removing %s' % path )
723728 os .remove (path )
724729 continue
725- iaslog ('Triggering LaunchAgent for user script: %s' % ( path ) )
730+ iaslog ('Triggering LaunchAgent for user script: %s' % path )
726731 touch (userscripttouchpath )
727732 if opts .depnotify :
728733 if depnotifystatus :
729- deplog ('Status: Installing: %s' % ( name ) )
734+ deplog ('Status: Installing: %s' % name )
730735 while os .path .isfile (userscripttouchpath ):
731- iaslog ('Waiting for user script to complete: %s' % ( path ) )
736+ iaslog ('Waiting for user script to complete: %s' % path )
732737 time .sleep (0.5 )
733738
734739 # Trigger the final DEPNotify events
735740 if opts .depnotify :
736741 for varg in opts .depnotify :
737742 notification = str (varg )
738743 if any (x in notification for x in deptriggers ):
739- iaslog ('Sending %s to DEPNotify' % ( str ( notification )) )
744+ iaslog ('Sending %s to DEPNotify' % notification )
740745 deplog (notification )
741746 else :
742747 iaslog (
0 commit comments