mirror of
https://github.com/munki/munki.git
synced 2026-05-05 03:49:22 -05:00
write the installatstartup file as a plist instead of plaintext
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
C0546BDC20FE961E003FE5A6 /* MSCPasswordAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0546BDB20FE961E003FE5A6 /* MSCPasswordAlertController.swift */; };
|
||||
C05F87932105587A000DB8D8 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C05F87952105587A000DB8D8 /* Localizable.strings */; };
|
||||
C0B2E4D921460E7D00FA9806 /* MSCWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0B2E4D821460E7D00FA9806 /* MSCWebView.swift */; };
|
||||
C0BCAD7D2442A0B3001D2FDD /* appleupdates.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0BCAD7C2442A0B3001D2FDD /* appleupdates.swift */; };
|
||||
C0C5DF6C20F5C27700CA0687 /* MSCStatusController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0C5DF6B20F5C27700CA0687 /* MSCStatusController.swift */; };
|
||||
C0D30BEB20CA445A005E876E /* MunkiItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0D30BEA20CA445A005E876E /* MunkiItems.swift */; };
|
||||
C0E2599E210AD8CE00C3A3D9 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0E2599D210AD8CD00C3A3D9 /* Socket.swift */; };
|
||||
@@ -135,6 +136,7 @@
|
||||
C05F87A921055F04000DB8D8 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
C05F87AA21055F10000DB8D8 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
C0B2E4D821460E7D00FA9806 /* MSCWebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSCWebView.swift; sourceTree = "<group>"; };
|
||||
C0BCAD7C2442A0B3001D2FDD /* appleupdates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = appleupdates.swift; sourceTree = "<group>"; };
|
||||
C0C5DF6B20F5C27700CA0687 /* MSCStatusController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MSCStatusController.swift; sourceTree = "<group>"; };
|
||||
C0D30BEA20CA445A005E876E /* MunkiItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MunkiItems.swift; sourceTree = "<group>"; };
|
||||
C0E2599D210AD8CD00C3A3D9 /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = "<group>"; };
|
||||
@@ -220,6 +222,7 @@
|
||||
C05F878F21055746000DB8D8 /* Info.plist */,
|
||||
C04F829C20BB5B9E00F9C57D /* MSCToolbarButton.swift */,
|
||||
C04F829E20BB713B00F9C57D /* munki.swift */,
|
||||
C0BCAD7C2442A0B3001D2FDD /* appleupdates.swift */,
|
||||
C04F82A020BB77CF00F9C57D /* FoundationPlist.swift */,
|
||||
C03107C020C77E5A007FE337 /* MSCBadgedTemplateImage.swift */,
|
||||
C03107C220C8B65E007FE337 /* msclib.swift */,
|
||||
@@ -434,6 +437,7 @@
|
||||
C0E2599E210AD8CE00C3A3D9 /* Socket.swift in Sources */,
|
||||
C01603D120D0A7FA00DEF9E4 /* SelfService.swift in Sources */,
|
||||
C04F82A120BB77CF00F9C57D /* FoundationPlist.swift in Sources */,
|
||||
C0BCAD7D2442A0B3001D2FDD /* appleupdates.swift in Sources */,
|
||||
C04CA61E20E6ADA100711461 /* MainWindowController.swift in Sources */,
|
||||
C01603CF20CF8B6100DEF9E4 /* iconutils.swift in Sources */,
|
||||
C04CA61C20E68B1800711461 /* authrestart.swift in Sources */,
|
||||
|
||||
+8
-10
@@ -147,16 +147,14 @@ class MSCAlertController: NSObject {
|
||||
msc_log("user", "agreed_apple_updates")
|
||||
// make sure this alert panel is gone before we proceed
|
||||
alert.window.orderOut(self)
|
||||
if let softwareUpdatePrefsPane = URL(string: "x-apple.systempreferences:com.apple.preferences.softwareupdate") {
|
||||
NSWorkspace.shared.open(softwareUpdatePrefsPane)
|
||||
//NSApp.terminate(self)
|
||||
// wait 2 seconds, then quit
|
||||
timer = Timer.scheduledTimer(timeInterval: 2.0,
|
||||
target: NSApp,
|
||||
selector: #selector(NSApp.terminate),
|
||||
userInfo: self,
|
||||
repeats: false)
|
||||
}
|
||||
openSoftwareUpdatePrefsPane()
|
||||
//NSApp.terminate(self)
|
||||
// wait 2 seconds, then quit
|
||||
timer = Timer.scheduledTimer(timeInterval: 2.0,
|
||||
target: NSApp,
|
||||
selector: #selector(NSApp.terminate),
|
||||
userInfo: self,
|
||||
repeats: false)
|
||||
} else {
|
||||
// cancelled
|
||||
msc_log("user", "deferred_apple_updates")
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// appleupdates.swift
|
||||
// Managed Software Center
|
||||
//
|
||||
// Created by Greg Neagle on 4/11/20.
|
||||
// Copyright © 2020 The Munki Project. All rights reserved.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import Foundation
|
||||
|
||||
let INSTALLATSTARTUPFILE = "/Users/Shared/.com.googlecode.munki.installatstartup"
|
||||
|
||||
func writeInstallAtStartupFlagFile() {
|
||||
// writes out a file to trigger Munki to install Munki updates at next restart
|
||||
let plist = ["AppleUpdateAttemptMade": true]
|
||||
do {
|
||||
try writePlist(plist, toFile: INSTALLATSTARTUPFILE)
|
||||
} catch {
|
||||
// unfortunate, but not fatal.
|
||||
msc_log("MSC", "cant_write_file", msg: "Couldn't write \(INSTALLATSTARTUPFILE) -- \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func openSoftwareUpdatePrefsPane() {
|
||||
if let softwareUpdatePrefsPane = URL(string: "x-apple.systempreferences:com.apple.preferences.softwareupdate") {
|
||||
writeInstallAtStartupFlagFile()
|
||||
NSWorkspace.shared.open(softwareUpdatePrefsPane)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// Copyright © 2018-2020 The Munki Project. All rights reserved.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import Foundation
|
||||
import SystemConfiguration
|
||||
import IOKit
|
||||
@@ -375,8 +376,9 @@ func startUpdateCheck(_ suppress_apple_update_check: Bool = false) throws {
|
||||
do {
|
||||
try writePlist(plist, toFile: UPDATECHECKLAUNCHFILE)
|
||||
} catch {
|
||||
throw ProcessStartError.error(
|
||||
description: "Could not create file \(UPDATECHECKLAUNCHFILE) -- \(error)")
|
||||
let message = "Could not create file \(UPDATECHECKLAUNCHFILE) -- \(error)"
|
||||
msc_log("MSC", "cant_write_file", msg: message)
|
||||
throw ProcessStartError.error(description: message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +408,6 @@ def munkiUpdatesContainStartOSInstallItem():
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def munkiUpdatesContainAppleItems():
|
||||
"""Return True if there are any Apple items in the list of updates"""
|
||||
install_info = os.path.join(
|
||||
@@ -711,11 +710,13 @@ def main():
|
||||
# triggered the update before logging out, or we triggered it before
|
||||
# restarting.
|
||||
user_triggered = False
|
||||
flagfiles = [constants.CHECKANDINSTALLATSTARTUPFLAG,
|
||||
flagfiles = (constants.CHECKANDINSTALLATSTARTUPFLAG,
|
||||
constants.INSTALLATSTARTUPFLAG,
|
||||
constants.INSTALLATLOGOUTFLAG]
|
||||
constants.INSTALLATLOGOUTFLAG)
|
||||
for filename in flagfiles:
|
||||
if os.path.exists(filename):
|
||||
munkilog.log(
|
||||
"managedsoftwareupdate run triggered by %s" % filename)
|
||||
user_triggered = True
|
||||
if filename == constants.CHECKANDINSTALLATSTARTUPFLAG:
|
||||
runtype = 'checkandinstallatstartup'
|
||||
@@ -729,9 +730,32 @@ def main():
|
||||
if networkUp():
|
||||
break
|
||||
time.sleep(1)
|
||||
else:
|
||||
# delete triggerfile if _not_ checkandinstallatstartup
|
||||
os.unlink(filename)
|
||||
break
|
||||
elif filename == constants.INSTALLATSTARTUPFLAG:
|
||||
runtype = 'installatstartup'
|
||||
# check to see if we should do some special handling;
|
||||
# we might have installed Apple updates right before a
|
||||
# restart
|
||||
try:
|
||||
launch_options = FoundationPlist.readPlist(filename)
|
||||
if launch_options.get("AppleUpdateAttemptMade"):
|
||||
munkilog.log("AppleUpdateAttemptMade is True")
|
||||
appleupdates.clearAppleUpdateInfo()
|
||||
options.munkipkgsonly = True
|
||||
except FoundationPlist.FoundationPlistException as err:
|
||||
pass
|
||||
break
|
||||
|
||||
# delete any triggerfile that isn't checkandinstallatstartup
|
||||
# so it's not hanging around at the next logout or restart
|
||||
for triggerfile in (constants.INSTALLATSTARTUPFLAG,
|
||||
constants.INSTALLATLOGOUTFLAG):
|
||||
if os.path.exists(triggerfile):
|
||||
try:
|
||||
os.unlink(triggerfile)
|
||||
except (OSError, IOError):
|
||||
pass
|
||||
|
||||
if not user_triggered:
|
||||
# no trigger file was found -- how'd we get launched?
|
||||
osutils.cleanUpTmpDir()
|
||||
@@ -743,6 +767,10 @@ def main():
|
||||
launchdtriggerfile = \
|
||||
'/private/tmp/.com.googlecode.munki.managedinstall.launchd'
|
||||
if os.path.exists(launchdtriggerfile):
|
||||
munkilog.log(
|
||||
"managedsoftwareupdate run triggered by %s"
|
||||
% launchdtriggerfile
|
||||
)
|
||||
# remove it so we aren't automatically relaunched
|
||||
os.unlink(launchdtriggerfile)
|
||||
runtype = 'installwithnologout'
|
||||
@@ -756,6 +784,10 @@ def main():
|
||||
launchdtriggerfile = \
|
||||
'/private/tmp/.com.googlecode.munki.updatecheck.launchd'
|
||||
if os.path.exists(launchdtriggerfile):
|
||||
munkilog.log(
|
||||
"managedsoftwareupdate run triggered by %s"
|
||||
% launchdtriggerfile
|
||||
)
|
||||
try:
|
||||
launch_options = FoundationPlist.readPlist(launchdtriggerfile)
|
||||
options.munkipkgsonly = launch_options.get(
|
||||
@@ -890,12 +922,7 @@ def main():
|
||||
# we need to delete AppleUpdates.plist so that other code doesn't
|
||||
# mistakenly alert for forced installs it isn't actually going to
|
||||
# install.
|
||||
appleupdates_plist = os.path.join(
|
||||
prefs.pref('ManagedInstallDir'), 'AppleUpdates.plist')
|
||||
try:
|
||||
os.unlink(appleupdates_plist)
|
||||
except OSError:
|
||||
pass
|
||||
appleupdates.clearAppleUpdateInfo()
|
||||
else:
|
||||
# check the normal preferences
|
||||
should_do_apple_updates = prefs.pref('InstallAppleSoftwareUpdates')
|
||||
@@ -954,6 +981,14 @@ def main():
|
||||
mustlogout = False
|
||||
notify_user = False
|
||||
force_action = None
|
||||
|
||||
if runtype == 'installatstartup':
|
||||
# turn off options.installonly; we need options.auto behavior from here
|
||||
# on out because if FileVault is active we may actually be logged in
|
||||
# at this point!
|
||||
options.installonly = False
|
||||
options.auto = True
|
||||
|
||||
if updatesavailable or appleupdatesavailable:
|
||||
if options.installonly or options.logoutinstall:
|
||||
# just install
|
||||
|
||||
Reference in New Issue
Block a user