Skip to content

Commit 26fa474

Browse files
authored
Merge pull request #6985 from BOINC/mac_fix_CLI_Install
Mac: in command-line installs don't ask about setting screensaver
2 parents deeb9b8 + 6f4229b commit 26fa474

2 files changed

Lines changed: 54 additions & 18 deletions

File tree

mac_installer/PostInstall.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,24 @@
2424
// [1] allow non-administrative users to run the BOINC Manager
2525
// (asked only if this Mac has any non-administrative users)
2626
// [2] set BOINC as the screensaver for all users who can run BOINC
27-
// (asked only if BOINC screensaver is not already set for them)
27+
// (only for MacOS < 14.0 Sonoma and only if BOINC screensaver is
28+
// not already set for them.)
2829
//
2930
// The installer can also be run from the command line. This is useful
3031
// for installation on remote Macs. However, there is no way to respond
3132
// to dialogs during a command-line install.
3233
//
3334
// Apple's command-line installer sets the following environment variable:
3435
// COMMAND_LINE_INSTALL=1
35-
// The postinstall script, postupgrade script, and this Postinstall.app
36-
// detect this environment variable and do the following:
37-
// * Redirect the Postinstall.app log output to a file
38-
// /tmp/BOINCInstallLog.txt
36+
// The postinstall script, postupgrade script, this Postinstall.app and
37+
// BOINC_Finish_Install.app detect this environment variable and do the
38+
// following:
3939
// * Suppress the 2 dialogs
4040
// * test for the existence of a file /tmp/nonadminusersok.txt; if the
4141
// file exists, allow non-administrative users to run BOINC Manager
4242
// * test for the existence of a file /tmp/setboincsaver.txt; if the
4343
// file exists, set BOINC as the screensaver for all BOINC users.
44+
// (available only for MacOS < 14.0 Sonoma.)
4445
//
4546
// The BOINC installer package to be used for command line installs can
4647
// be found embedded inside the GUI BOINC Installer application at:
@@ -219,6 +220,8 @@ int main(int argc, char *argv[])
219220
}
220221

221222
// getlogin() gives unreliable results under OS 10.6.2, so use environment
223+
// Note: command-line installer must be run as root, so loginName will
224+
// always be root for command-line installs
222225
strncpy(loginName, getenv("USER"), sizeof(loginName)-1);
223226
if (loginName[0] == '\0') {
224227
ShowMessage(false, (char *)_("Could not get user login name"));
@@ -786,6 +789,10 @@ Boolean IsRestartNeeded() {
786789
FILE *restartNeededFile;
787790
int value;
788791

792+
if (compareOSVersionTo(10, 9) >= 0) {
793+
return false;
794+
}
795+
789796
snprintf(s, sizeof(s), "/tmp/%s/BOINC_restart_flag", tempDirName);
790797
restartNeededFile = fopen(s, "r");
791798
if (restartNeededFile) {
@@ -1020,12 +1027,15 @@ Boolean SetLoginItemLaunchAgent(long brandID, long oldBrandID, Boolean deleteLog
10201027
#if COPY_FINISH_INSTALL_TO_USER_DIRECTORY
10211028
fprintf(f, "\t\t<string>/Users/%s/Library/Application Support/BOINC/%s_Finish_Install.app/Contents/MacOS/%s_Finish_Install</string>\n", pw->pw_name, brandName[brandID], brandName[brandID]);
10221029
#else
1023-
// For a reason I do't understand, setting the screensaver under MacOS 26
1030+
// For a reason I don't understand, setting the screensaver under MacOS 26
10241031
// works if we use the BOINC_Finish_Install in the BOINC Data directory
10251032
// but not one at /Users/%s/Library/Application Support/BOINC/ so we no
10261033
// longer put one in the usr's directory tree.
10271034
fprintf(f, "\t\t<string>/Library/Application Support/BOINC Data/%s_Finish_Install.app/Contents/MacOS/%s_Finish_Install</string>\n", brandName[brandID], brandName[brandID]);
10281035
#endif
1036+
if (gCommandLineInstall) {
1037+
fprintf(f, "\t\t<string>-c</string>\n");
1038+
}
10291039
if (deleteLogInItem) {
10301040
fprintf(f, "\t\t<string>-d</string>\n");
10311041
fprintf(f, "\t\t<string>%d</string>\n", (int)oldBrandID);
@@ -1558,17 +1568,20 @@ OSErr UpdateAllVisibleUsers(long brandID, long oldBrandID)
15581568
currentUserCanRunBOINC = true;
15591569
}
15601570

1561-
err = GetCurrentScreenSaverSelection(pw, s, sizeof(s) -1);
1562-
if (err == noErr) {
1563-
if (strcmp(s, saverName[brandID])) {
1564-
saverAlreadySetForAll = false;
1571+
if (compareOSVersionTo(14, 0) < 0) {
1572+
// As of MacOS 14.0 Sonoma, this code no longer
1573+
// will detect the current screensaver,
1574+
err = GetCurrentScreenSaverSelection(pw, s, sizeof(s) -1);
1575+
if (err == noErr) {
1576+
if (strcmp(s, saverName[brandID])) {
1577+
saverAlreadySetForAll = false;
1578+
}
15651579
}
1580+
printf("[1] Current Screensaver Selection for user %s is: \"%s\"\n", pw->pw_name, s);
1581+
fflush(stdout);
15661582
}
1567-
printf("[1] Current Screensaver Selection for user %s is: \"%s\"\n", pw->pw_name, s);
1568-
fflush(stdout);
15691583
} // End if (isGroupMember)
15701584
} // End for (userIndex=0; userIndex< human_user_names.size(); ++userIndex)
1571-
15721585
ResynchDSSystem();
15731586

15741587
if (allNonAdminUsersAreSet) {
@@ -1726,6 +1739,8 @@ OSErr UpdateAllVisibleUsers(long brandID, long oldBrandID)
17261739
// Set login item for this user
17271740
bool useOSASript = false;
17281741

1742+
// Note: command-line installer must be run as root, so
1743+
// loginName will be root if this is a commmand-line install
17291744
if ((compareOSVersionTo(10, 13) < 0)
17301745
|| (strcmp(loginName, human_user_name) == 0)
17311746
|| (strcmp(loginName, pw->pw_name) == 0)

mac_installer/finish_install.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ int main(int argc, const char * argv[]) {
8888
bool calledFromInstaller = false;
8989
bool createdByUninstaller = false;
9090
bool calledFromManager = false;
91+
bool commandLineInstall = false;
9192

9293
// Wait until we are the active login (in case of fast user switching)
9394
userName = getenv("USER");
@@ -114,7 +115,9 @@ int main(int argc, const char * argv[]) {
114115
} else if (strcmp(argv[i], "-u") == 0) {
115116
isUninstall = true;
116117
createdByUninstaller = true;
117-
}
118+
} else if (strcmp(argv[i], "-c") == 0) {
119+
commandLineInstall = true;
120+
}
118121
} // end for (i=i; i<argc; i+=2)
119122

120123
if (isUninstall) {
@@ -143,8 +146,10 @@ int main(int argc, const char * argv[]) {
143146
if (!success) {
144147
}
145148
if (compareOSVersionTo(26, 0) >= 0) {
146-
GetAndLoadPreferredLanguages();
147-
MaybeSetScreenSaver(iBrandId);
149+
if (! commandLineInstall){
150+
GetAndLoadPreferredLanguages();
151+
MaybeSetScreenSaver(iBrandId);
152+
}
148153
}
149154

150155
if (compareOSVersionTo(10, 13) >= 0) {
@@ -362,8 +367,8 @@ static Boolean IsUserActive(const char *userName){
362367

363368

364369
// It would be nice to check whether our screen saver is already set for
365-
// this user so we can ask wethr to set it only if necessary, but that
366-
// triggrs a scary warning asking for permission to let System Events
370+
// this user so we can ask whether to set it only if necessary, but that
371+
// triggers a scary warning asking for permission to let System Events
367372
// administer the Mac, so we don't. (If the user answers yes to setting
368373
// the screensaver, then the code which sets the screensaver will show
369374
// that warning, but this seems less scary than having it pop up for no
@@ -372,6 +377,22 @@ void MaybeSetScreenSaver(int brandId){
372377
char buf[MAXPATHLEN];
373378
char mySaverName[1024];
374379

380+
// The installer can also be run from the command line. This is useful
381+
// for installation on remote Macs. However, there is no way to respond
382+
// to dialogs during a command-line install.
383+
//
384+
// Apple's command-line installer sets the following environment variable:
385+
// COMMAND_LINE_INSTALL=1
386+
// The postinstall script, postupgrade script, Postinstall.app and
387+
// this BOINC_Finish_Install.app detect this environment variable and do
388+
// the following:
389+
// * Suppress the 2 dialogs
390+
// * test for the existence of a file /tmp/nonadminusersok.txt; if the
391+
// file exists, allow non-administrative users to run BOINC Manager
392+
// * test for the existence of a file /tmp/setboincsaver.txt; if the
393+
// file exists, set BOINC as the screensaver for all BOINC users.
394+
// (available only for MacOS < 14.0 Sonoma.)
395+
//
375396
if ((ShowMessage(true,
376397
(char *)_("Do you want to set %s as your screensaver?"),
377398
brandName[brandId], brandName[brandId])) == false) {

0 commit comments

Comments
 (0)