From 8c4cbcd21b9872b766413f17f1ea9be1e3648d0b Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Mon, 22 Nov 2010 13:37:04 +0000 Subject: [PATCH] Mac Installer: command-line installs test for existence of files /tmp/nonadminusersok.txt and /tmp/setboincsaver.txt svn path=/branches/boinc_core_release_6_12/; revision=22731 --- checkin_notes | 15 ++++++++ mac_installer/PostInstall.cpp | 64 ++++++++++++++++++++++++++++------- mac_installer/postinstall | 11 ++++-- mac_installer/postupgrade | 9 +++-- 4 files changed, 82 insertions(+), 17 deletions(-) diff --git a/checkin_notes b/checkin_notes index 7072fb029c..65e8fee999 100644 --- a/checkin_notes +++ b/checkin_notes @@ -7833,3 +7833,18 @@ Charlie 19 Nov 2010 mac_installer/ PostInstall.cpp + +Charlie 19 Nov 2010 + - Mac Installer: It turns out that the command-line installer clears all + environment variables, so instead of checking environment variables + during command-line installs, we check for the existence of files + /tmp/nonadminusersok.txt and /tmp/setboincsaver.txt. In normal GUI + installs, these are ignored and the normal BOINC installer dialogs + are used to determine these options. See the comments at the top of + PostInstall.cpp for details of doing command-line installs on remote + Macs. + + mac_installer/ + PostInstall.cpp + postinstall + postupgrade diff --git a/mac_installer/PostInstall.cpp b/mac_installer/PostInstall.cpp index ab10dc17ea..8f223ebe7e 100755 --- a/mac_installer/PostInstall.cpp +++ b/mac_installer/PostInstall.cpp @@ -17,15 +17,40 @@ /* PostInstall.cpp */ -// SUPPORTED ENVIRONMENT VARIABLES: -// COMMAND_LINE_INSTALL set if running the installer from the command line; -// suppresses all dialogs. If set, the following 2 -// environment variables are also recognized: +// Notes on command-line installation to a remote Mac: // -// NONADMINUSERSOK Allow users without administrator privileges to -// run BOINC Manager +// When the installer is run from the Finder, this Postinstall.app will +// display up to two dialogs, asking the user whether or not to: +// [1] allow non-administrative users to run the BOINC Manager +// (asked only if this Mac has any non-administrative users) +// [2] set BOINC as the screensaver for all users who can run BOINC +// (asked only if BOINC screensaver is not already set for them) // -// SETBOINCSAVER Set BOINCSaver as screensaver for all BOINC users +// The installer can also be run from the command line. This is useful +// for installation on remote Macs. However, there is no way to respond +// to dialogs during a command-line install. +// +// The command-line installer sets the following environment variable: +// COMMAND_LINE_INSTALL=1 +// The postinstall script, postupgrade script, and this Postinstall.app +// detect this environment variable and do the following: +// * Redirect the Postinstall.app log output to a file +// /tmp/BOINCInstallLog.txt +// * Suppress the 2 dialogs +// * test for the existence of a file /tmp/nonadminusersok.txt; if the +// file exists, allow non-administrative users to run BOINC Manager +// * test for the existence of a file /tmp/setboincsaver.txt; if the +// file exists, set BOINC as the screensaver for all BOINC users. +// +// Example: To install on a remote Mac from the command line, allowing +// non-admin users to run the BOINC Manager and setting BOINC as the +// screensaver: +// * First SCP the "BOINC Installer.pkg" to the remote Mac's /tmp +// directory, then SSh into the remote mac and enter the following +// $ touch /tmp/nonadminusersok.txt +// $ touch /tmp/setboincsaver.txt +// $ sudo installer -pkg "/tmp/BOINC Installer.pkg" -tgt / +// $ sudo reboot // #define CREATE_LOG 1 /* for debugging */ @@ -157,11 +182,17 @@ int main(int argc, char *argv[]) receiptNameEscaped[2] = "/Library/Receipts/Progress\\ Thru\\ Processors.pkg"; ::GetCurrentProcess (&ourProcess); - + + puts("Starting PostInstall app\n"); + fflush(stdout); // getlogin() gives unreliable results under OS 10.6.2, so use environment strncpy(loginName, getenv("USER"), sizeof(loginName)-1); + printf("login name = %s\n", loginName); + if (getenv("COMMAND_LINE_INSTALL") != NULL) { gCommandLineInstall = true; + puts("command-line install\n"); + fflush(stdout); } err = Gestalt(gestaltSystemVersion, &OSVersion); @@ -343,6 +374,7 @@ int main(int argc, char *argv[]) #ifdef SANDBOX err = CheckLogoutRequirement(&finalInstallAction); + printf("CheckLogoutRequirement returned %d\n", finalInstallAction); if (finalInstallAction == launchWhenDone) { // Wait for BOINC's RPC socket address to become available to user boinc_master, in @@ -473,7 +505,6 @@ int DeleteReceipt() Initialize(); err = CheckLogoutRequirement(&finalInstallAction); - err = FindProcess ('APPL', 'xins', &installerPSN); if (err == noErr) err = GetProcessPID(&installerPSN , &installerPID); @@ -552,7 +583,7 @@ OSStatus CheckLogoutRequirement(int *finalAction) ++i; } } - +printf("In CheckLogoutRequirement: isMember=%d, currentUserCanRunBOINC=%d\n", (int)isMember, (int)currentUserCanRunBOINC); if (!isMember && !currentUserCanRunBOINC) { *finalAction = nothingrequired; return noErr; @@ -939,6 +970,7 @@ OSErr UpdateAllVisibleUsers(long brandID) FILE *f; OSStatus err; Boolean isGroupMember; + struct stat sbuf; #ifdef SANDBOX char *p; short i; @@ -1064,7 +1096,11 @@ OSErr UpdateAllVisibleUsers(long brandID) puts("[2] All non-admin users are already members of group boinc_master\n"); } else { if (gCommandLineInstall) { - if (getenv("NONADMINUSERSOK") != NULL) { + err = stat("/tmp/nonadminusersok.txt", &sbuf); + if (err == noErr) { + puts("nonadminusersok.txt file detected\n"); + fflush(stdout); + unlink("/tmp/nonadminusersok.txt"); allowNonAdminUsersToRunBOINC = true; currentUserCanRunBOINC = true; saverAlreadySetForAll = false; @@ -1088,7 +1124,11 @@ OSErr UpdateAllVisibleUsers(long brandID) if (! saverAlreadySetForAll) { if (gCommandLineInstall) { - if (getenv("SETBOINCSAVER") != NULL) { + err = stat("/tmp/setboincsaver.txt", &sbuf); + if (err == noErr) { + puts("setboincsaver.txt file detected\n"); + fflush(stdout); + unlink("/tmp/setboincsaver.txt"); setSaverForAllUsers = true; } } else { diff --git a/mac_installer/postinstall b/mac_installer/postinstall index e695cefb03..8a99ee3fb5 100644 --- a/mac_installer/postinstall +++ b/mac_installer/postinstall @@ -1,7 +1,7 @@ #!/bin/sh ## -# post-Install Script for Macintosh BOINC Manager for OS X revised 2/10/10 +# post-Install Script for Macintosh BOINC Manager for OS X revised 11/22/10 ## echo "initial directory = $PWD" @@ -17,9 +17,14 @@ if [ -f "Contents/Resources/acct_mgr_url.xml" ]; then cp -fp Contents/Resources/acct_mgr_url.xml "/Library/Application Support/BOINC Data/acct_mgr_url.xml" fi -# Run the Postinstall Application + Run the Postinstall Application +if [ "${COMMAND_LINE_INSTALL}" = "1" ]; then +rm -f /tmp/BOINCInstallLog.txt +Contents/Resources/PostInstall.app/Contents/MacOS/PostInstall -part1 >> /tmp/BOINCInstallLog.txt +Contents/Resources/PostInstall.app/Contents/MacOS/PostInstall -part2 & >> /tmp/BOINCInstallLog.txt +else Contents/Resources/PostInstall.app/Contents/MacOS/PostInstall -part1 - Contents/Resources/PostInstall.app/Contents/MacOS/PostInstall -part2 & +fi exit 0 diff --git a/mac_installer/postupgrade b/mac_installer/postupgrade index d1840d076e..583577652b 100755 --- a/mac_installer/postupgrade +++ b/mac_installer/postupgrade @@ -1,7 +1,7 @@ #!/bin/sh ## -# post-Upgrade Script for Macintosh BOINC Manager for OS X revised 2/10/10 +# post-Upgrade Script for Macintosh BOINC Manager for OS X revised 11/22/10 ## echo "initial directory = $PWD" @@ -18,8 +18,13 @@ if [ -f "Contents/Resources/acct_mgr_url.xml" ]; then fi # Run the Postinstall Application +if [ "${COMMAND_LINE_INSTALL}" = "1" ]; then +rm -f /tmp/BOINCInstallLog.txt +Contents/Resources/PostInstall.app/Contents/MacOS/PostInstall -part1 >> /tmp/BOINCInstallLog.txt +Contents/Resources/PostInstall.app/Contents/MacOS/PostInstall -part2 & >> /tmp/BOINCInstallLog.txt +else Contents/Resources/PostInstall.app/Contents/MacOS/PostInstall -part1 - Contents/Resources/PostInstall.app/Contents/MacOS/PostInstall -part2 & +fi exit 0