Last active
May 27, 2021 22:15
-
-
Save 0xced/002313ae4e56ecfcb0b636545c3c2fa7 to your computer and use it in GitHub Desktop.
Trying to ignore the macOS Big Sur update (unsuccessfully)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <sysexits.h> | |
/* | |
* Trying to bypass the fact that running `sudo /usr/sbin/softwareupdate --reset-ignored && sudo /usr/sbin/softwareupdate --ignore "macOS Big Sur"` | |
* does not work anymore on macOS Mojave 10.14.6 (ignored updates is empty) by using the underlying SoftwareUpdate framework directly. | |
* Unfortunately, this did not work as expected. The preference is written when this tool is run as root but opening the software update | |
* preference pane still displays the macOS Big Sur update :-( | |
* | |
* References | |
* - https://lapcatsoftware.com/articles/software-update.html | |
* - https://apple.stackexchange.com/questions/406413/how-do-i-stop-big-sur-from-installing-on-my-computer | |
*/ | |
int Run(NSArray *ignoreUpdates) | |
{ | |
NSString *softwareUpdatePath = @"/System/Library/PrivateFrameworks/SoftwareUpdate.framework"; | |
NSBundle *softwareUpdateBundle = [NSBundle bundleWithPath:softwareUpdatePath]; | |
NSError *error; | |
BOOL loaded = [softwareUpdateBundle loadAndReturnError:&error]; | |
if (!loaded) | |
{ | |
NSLog(@"Failed to load %@ \n%@", softwareUpdatePath, error ?: [NSString stringWithFormat:@"Make sure that %@ exists on disk", softwareUpdatePath]); | |
return EX_SOFTWARE; | |
} | |
Class SUSharedPrefs = NSClassFromString(@"SUSharedPrefs"); | |
if (SUSharedPrefs == Nil) | |
{ | |
NSLog(@"SUSharedPrefs class not found"); | |
return EX_SOFTWARE; | |
} | |
id sharedPrefManager = [SUSharedPrefs performSelector:@selector(sharedPrefManager)]; | |
if (sharedPrefManager == nil) | |
{ | |
NSLog(@"sharedPrefManager is nil"); | |
return EX_SOFTWARE; | |
} | |
[sharedPrefManager performSelector:@selector(setInactiveProductLabels:) withObject:ignoreUpdates]; | |
NSArray *inactiveProductLabels = [sharedPrefManager performSelector:@selector(inactiveProductLabels)]; | |
if (inactiveProductLabels.count == 0) | |
{ | |
NSLog(@"There are no ignored updates."); | |
} | |
else if (inactiveProductLabels.count == 1) | |
{ | |
NSLog(@"Ignored update: %@", inactiveProductLabels[0]); | |
} | |
else | |
{ | |
NSLog(@"Ignored updates: %@", @(inactiveProductLabels.count)); | |
for (id inactiveProductLabel in inactiveProductLabels) | |
{ | |
NSLog(@" * %@", inactiveProductLabel); | |
} | |
} | |
BOOL success = [inactiveProductLabels isEqualToArray:ignoreUpdates]; | |
if (!success) | |
{ | |
NSLog(@"Ignoring (%@) failed. Make sure to run this tool as root.", [ignoreUpdates componentsJoinedByString:@", "]); | |
} | |
NSString *softwareupdateCommand = @"/usr/sbin/softwareupdate --ignore"; | |
NSLog(@"Running %@", softwareupdateCommand); | |
system(softwareupdateCommand.fileSystemRepresentation); | |
return success ? EX_OK : EX_NOPERM; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
@autoreleasepool | |
{ | |
@try | |
{ | |
return Run(@[ @"macOS Big Sur" ]); | |
} | |
@catch (NSException *exception) | |
{ | |
NSLog(@"An unexpected error occurred: %@", exception); | |
return EX_SOFTWARE; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment