Skip to content

Commit

Permalink
Merge pull request #59 from erikng/fixrebootpy3
Browse files Browse the repository at this point in the history
redo reboot logic to address issue in python3 code
  • Loading branch information
erikng authored Jan 2, 2020
2 parents aabb83b + 9291a6b commit f18e864
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions payload/Library/installapplications/installapplications.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,32 @@ def cleanup(exit_code):
launchctl('/bin/launchctl', 'asuser', userid,
'/bin/launchctl', 'remove', laidentifier)

# Trigger a delayed reboot of 5 seconds
if reboot:
iaslog('Triggering reboot')
rebootcmd = [
'/usr/bin/osascript',
'-e',
'delay 5',
'-e',
'tell application "System Events" to restart'
]
try:
subprocess.Popen(rebootcmd, preexec_fn=os.setpgrp)
except: # noqa
pass

# Attempt to kill InstallApplications' path
iaslog('Attempting to remove InstallApplications directory: ' + iapath)
try:
shutil.rmtree(iapath)
except: # noqa
pass

if not reboot:
iaslog('Attempting to remove LaunchDaemon: ' + ldidentifier)
launchctl('/bin/launchctl', 'remove', ldidentifier)
iaslog('Cleanup done. Exiting.')
sys.exit(exit_code)
iaslog('Attempting to remove LaunchDaemon: ' + ldidentifier)
launchctl('/bin/launchctl', 'remove', ldidentifier)
iaslog('Cleanup done. Exiting.')
sys.exit(exit_code)


def main():
Expand Down Expand Up @@ -711,13 +725,9 @@ def main():
iaslog(
'Skipping DEPNotify notification event due to completion.')

# Cleanup and trigger a reboot if required.
# Cleanup and send good exit status
cleanup(0)

if reboot:
iaslog('Triggering reboot')
subprocess.call(['/sbin/shutdown', '-r', 'now'])


if __name__ == '__main__':
main()

0 comments on commit f18e864

Please sign in to comment.