mirror of https://github.com/BOINC/boinc.git
Mac installer: replace Mac APIs deprecated in OS 10.10, fix bug in AddRemoveUser utility
This commit is contained in:
parent
7e213cf2f6
commit
bbc1c40d06
|
@ -37,7 +37,7 @@ static double dtime(void);
|
|||
static void SleepSeconds(double seconds);
|
||||
long GetBrandID(void);
|
||||
static int parse_posic_spawn_command_line(char* p, char** argv);
|
||||
static int callPosixSpawn(const char *cmd);
|
||||
int callPosixSpawn(const char *cmd);
|
||||
|
||||
#define NUMBRANDS 4
|
||||
static char *appName[NUMBRANDS];
|
||||
|
@ -64,13 +64,6 @@ int main(int argc, char *argv[])
|
|||
FILE *f;
|
||||
OSStatus err;
|
||||
|
||||
#ifndef _DEBUG
|
||||
if (getuid() != 0) {
|
||||
printf("This program must be run as root\n");
|
||||
printUsage();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
appName[0] = "BOINCManager";
|
||||
appPath[0] = "/Applications/BOINCManager.app";
|
||||
brandName[0] = "BOINC";
|
||||
|
@ -86,6 +79,14 @@ int main(int argc, char *argv[])
|
|||
|
||||
brandID = GetBrandID();
|
||||
|
||||
#ifndef _DEBUG
|
||||
if (getuid() != 0) {
|
||||
printf("This program must be run as root\n");
|
||||
printUsage(brandID);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (argc < 3) {
|
||||
printUsage(brandID);
|
||||
return 0;
|
||||
|
@ -536,7 +537,7 @@ static int parse_posic_spawn_command_line(char* p, char** argv) {
|
|||
|
||||
#include <spawn.h>
|
||||
|
||||
static int callPosixSpawn(const char *cmdline) {
|
||||
int callPosixSpawn(const char *cmdline) {
|
||||
char command[1024];
|
||||
char progName[1024];
|
||||
char progPath[MAXPATHLEN];
|
||||
|
|
|
@ -107,17 +107,17 @@ int main(int argc, char *argv[])
|
|||
|
||||
strlcat(pkgPath, ".pkg", sizeof(pkgPath));
|
||||
// Expand the installer package
|
||||
system("rm -dfR /tmp/BOINC.pkg");
|
||||
system("rm -dfR /tmp/expanded_BOINC.pkg");
|
||||
system("rm -dfR /tmp/PostInstall.app");
|
||||
system("rm -f /tmp/BOINC_preferred_languages");
|
||||
system("rm -f /tmp/BOINC_restart_flag");
|
||||
callPosixSpawn("rm -dfR /tmp/BOINC.pkg");
|
||||
callPosixSpawn("rm -dfR /tmp/expanded_BOINC.pkg");
|
||||
callPosixSpawn("rm -dfR /tmp/PostInstall.app");
|
||||
callPosixSpawn("rm -f /tmp/BOINC_preferred_languages");
|
||||
callPosixSpawn("rm -f /tmp/BOINC_restart_flag");
|
||||
|
||||
sprintf(temp, "cp -fpR \"%s\" /tmp/PostInstall.app", postInstallAppPath);
|
||||
err = system(temp);
|
||||
err = callPosixSpawn(temp);
|
||||
|
||||
sprintf(temp, "pkgutil --expand \"%s\" /tmp/expanded_BOINC.pkg", pkgPath);
|
||||
err = system(temp);
|
||||
err = callPosixSpawn(temp);
|
||||
|
||||
if (err == noErr) {
|
||||
GetPreferredLanguages();
|
||||
|
@ -130,17 +130,17 @@ int main(int argc, char *argv[])
|
|||
*p = '\0';
|
||||
ShowMessage((char *)_("Sorry, this version of %s requires system 10.6 or higher."), brand);
|
||||
|
||||
system("rm -dfR /tmp/BOINC_payload");
|
||||
callPosixSpawn("rm -dfR /tmp/BOINC_payload");
|
||||
return -1;
|
||||
}
|
||||
|
||||
system("rm -dfR /tmp/BOINC_payload");
|
||||
callPosixSpawn("rm -dfR /tmp/BOINC_payload");
|
||||
|
||||
// Remove previous installer package receipt so we can run installer again
|
||||
// (affects only older versions of OS X and fixes a bug in those versions)
|
||||
// "rm -rf /Library/Receipts/GridRepublic.pkg"
|
||||
sprintf(s, "rm -rf \"/Library/Receipts/%s.pkg\"", brand);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
restartNeeded = IsRestartNeeded();
|
||||
|
||||
|
@ -154,27 +154,27 @@ int main(int argc, char *argv[])
|
|||
if (restartNeeded) {
|
||||
if (err == noErr) {
|
||||
// Change onConclusion="none" to onConclusion="RequireRestart"
|
||||
err = system("sed -i \"\" s/\"onConclusion=\\\"none\\\"\"/\"onConclusion=\\\"RequireRestart\\\"\"/g /tmp/expanded_BOINC.pkg/Distribution");
|
||||
err = callPosixSpawn("sed -i \"\" s/\"onConclusion=\\\"none\\\"\"/\"onConclusion=\\\"RequireRestart\\\"\"/g /tmp/expanded_BOINC.pkg/Distribution");
|
||||
}
|
||||
if (err == noErr) {
|
||||
// Flatten the installer package
|
||||
sprintf(temp, "pkgutil --flatten /tmp/expanded_BOINC.pkg /tmp/%s.pkg", brand);
|
||||
err = system(temp);
|
||||
err = callPosixSpawn(temp);
|
||||
|
||||
system("rm -fR /tmp/expanded_BOINC.pkg");
|
||||
callPosixSpawn("rm -fR /tmp/expanded_BOINC.pkg");
|
||||
}
|
||||
|
||||
if (err == noErr) {
|
||||
sprintf(temp, "open \"/tmp/%s.pkg\" &", brand);
|
||||
system(temp);
|
||||
callPosixSpawn(temp);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
system("rm -fR /tmp/expanded_BOINC.pkg");
|
||||
callPosixSpawn("rm -fR /tmp/expanded_BOINC.pkg");
|
||||
|
||||
sprintf(temp, "open \"%s\" &", pkgPath);
|
||||
system(temp);
|
||||
callPosixSpawn(temp);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -297,10 +297,10 @@ static void GetPreferredLanguages() {
|
|||
FILE *f;
|
||||
|
||||
getcwd(savedWD, sizeof(savedWD));
|
||||
system("rm -dfR /tmp/BOINC_payload");
|
||||
callPosixSpawn("rm -dfR /tmp/BOINC_payload");
|
||||
mkdir("/tmp/BOINC_payload", 0777);
|
||||
chdir("/tmp/BOINC_payload");
|
||||
system("cpio -i < /tmp/expanded_BOINC.pkg/BOINC.pkg/Payload");
|
||||
callPosixSpawn("cpio -i < /tmp/expanded_BOINC.pkg/BOINC.pkg/Payload");
|
||||
chdir(savedWD);
|
||||
|
||||
// Create an array of all our supported languages
|
||||
|
|
|
@ -280,18 +280,18 @@ int main(int argc, char *argv[])
|
|||
|
||||
// "rm -rf /Applications/GridRepublic\\ Desktop.app"
|
||||
sprintf(s, "rm -rf %s", appPathEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
// "rm -rf /Library/Screen\\ Savers/GridRepublic.saver"
|
||||
sprintf(s, "rm -rf /Library/Screen\\ Savers/%s.saver", saverNameEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
// "rm -rf /Library/Receipts/GridRepublic.pkg"
|
||||
sprintf(s, "rm -rf %s", receiptNameEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
// We don't customize BOINC Data directory name for branding
|
||||
system ("rm -rf /Library/Application\\ Support/BOINC\\ Data");
|
||||
callPosixSpawn ("rm -rf /Library/Application\\ Support/BOINC\\ Data");
|
||||
|
||||
err = kill(installerPID, SIGKILL);
|
||||
|
||||
|
@ -385,21 +385,21 @@ int main(int argc, char *argv[])
|
|||
// Set owner of branded BOINCManager and contents, including core client
|
||||
// "chown -Rf username /Applications/GridRepublic\\ Desktop.app"
|
||||
sprintf(s, "chown -Rf %s %s", p, appPathEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
// Set owner of BOINC Screen Saver
|
||||
// "chown -Rf username /Library/Screen\\ Savers/GridRepublic.saver"
|
||||
sprintf(s, "chown -Rf %s /Library/Screen\\ Savers/%s.saver", p, saverNameEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
// We don't customize BOINC Data directory name for branding
|
||||
// "chown -Rf username /Library/Application\\ Support/BOINC\\ Data"
|
||||
sprintf(s, "chown -Rf %s /Library/Application\\ Support/BOINC\\ Data", p);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
// "chmod -R a+s /Applications/GridRepublic\\ Desktop.app"
|
||||
sprintf(s, "chmod -R a+s %s", appPathEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
#endif // ! defined(SANDBOX)
|
||||
|
||||
|
@ -409,15 +409,15 @@ int main(int argc, char *argv[])
|
|||
|
||||
// "rm -rf /Applications/GridRepublic\\ Desktop.app"
|
||||
sprintf(s, "rm -rf %s", appPathEscaped[i]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
// "rm -rf /Library/Screen\\ Savers/GridRepublic.saver"
|
||||
sprintf(s, "rm -rf /Library/Screen\\ Savers/%s.saver", saverNameEscaped[i]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
}
|
||||
|
||||
if (brandID == 0) { // Installing generic BOINC
|
||||
system ("rm -f /Library/Application\\ Support/BOINC\\ Data/Branding");
|
||||
callPosixSpawn ("rm -f /Library/Application\\ Support/BOINC\\ Data/Branding");
|
||||
}
|
||||
|
||||
CFStringRef CFAppPath = CFStringCreateWithCString(kCFAllocatorDefault, appPath[brandID],
|
||||
|
@ -572,7 +572,7 @@ int DeleteReceipt()
|
|||
// Remove installer package receipt so we can run installer again if needed to fix permissions
|
||||
// "rm -rf /Library/Receipts/GridRepublic.pkg"
|
||||
sprintf(s, "rm -rf %s", receiptNameEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
|
||||
if (!restartNeeded) {
|
||||
installerPID = getPidIfRunning("com.apple.installer");
|
||||
|
@ -683,14 +683,14 @@ void CheckUserAndGroupConflicts()
|
|||
}
|
||||
}
|
||||
if ((boinc_master_gid < 501) || (entryCount > 1)) {
|
||||
err = system ("dscl . -delete /groups/boinc_master");
|
||||
err = callPosixSpawn ("dscl . -delete /groups/boinc_master");
|
||||
// User boinc_master must have group boinc_master as its primary group.
|
||||
// Since this group no longer exists, delete the user as well.
|
||||
if (err) {
|
||||
fprintf(stdout, "dscl . -delete /groups/boinc_master returned %d\n", err);
|
||||
fflush(stdout);
|
||||
}
|
||||
err = system ("dscl . -delete /users/boinc_master");
|
||||
err = callPosixSpawn ("dscl . -delete /users/boinc_master");
|
||||
if (err) {
|
||||
fprintf(stdout, "dscl . -delete /users/boinc_master returned %d\n", err);
|
||||
fflush(stdout);
|
||||
|
@ -719,14 +719,14 @@ void CheckUserAndGroupConflicts()
|
|||
}
|
||||
|
||||
if ((boinc_project_gid < 501) || (entryCount > 1)) {
|
||||
err = system ("dscl . -delete /groups/boinc_project");
|
||||
err = callPosixSpawn ("dscl . -delete /groups/boinc_project");
|
||||
if (err) {
|
||||
fprintf(stdout, "dscl . -delete /groups/boinc_project returned %d\n", err);
|
||||
fflush(stdout);
|
||||
}
|
||||
// User boinc_project must have group boinc_project as its primary group.
|
||||
// Since this group no longer exists, delete the user as well.
|
||||
err = system ("dscl . -delete /users/boinc_project");
|
||||
err = callPosixSpawn ("dscl . -delete /users/boinc_project");
|
||||
if (err) {
|
||||
fprintf(stdout, "dscl . -delete /users/boinc_project returned %d\n", err);
|
||||
fflush(stdout);
|
||||
|
@ -757,7 +757,7 @@ void CheckUserAndGroupConflicts()
|
|||
}
|
||||
|
||||
if (entryCount > 1) {
|
||||
err = system ("dscl . -delete /users/boinc_master");
|
||||
err = callPosixSpawn ("dscl . -delete /users/boinc_master");
|
||||
if (err) {
|
||||
fprintf(stdout, "dscl . -delete /users/boinc_master returned %d\n", err);
|
||||
fflush(stdout);
|
||||
|
@ -784,7 +784,7 @@ void CheckUserAndGroupConflicts()
|
|||
}
|
||||
|
||||
if (entryCount > 1) {
|
||||
system ("dscl . -delete /users/boinc_project");
|
||||
callPosixSpawn ("dscl . -delete /users/boinc_project");
|
||||
if (err) {
|
||||
fprintf(stdout, "dscl . -delete /users/boinc_project returned %d\n", err);
|
||||
fflush(stdout);
|
||||
|
@ -1550,10 +1550,10 @@ OSErr UpdateAllVisibleUsers(long brandID)
|
|||
if (setSaverForAllUsers) {
|
||||
if (compareOSVersionTo(10, 6) < 0) {
|
||||
sprintf(s, "sudo -u \"%s\" defaults -currentHost write com.apple.screensaver moduleName %s", pw->pw_name, saverNameEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
sprintf(s, "sudo -u \"%s\" defaults -currentHost write com.apple.screensaver modulePath /Library/Screen\\ Savers/%s.saver",
|
||||
pw->pw_name, saverNameEscaped[brandID]);
|
||||
system (s);
|
||||
callPosixSpawn (s);
|
||||
} else {
|
||||
seteuid(pw->pw_uid); // Temporarily set effective uid to this user
|
||||
sprintf(s, "/Library/Screen Savers/%s.saver", saverName[brandID]);
|
||||
|
|
Loading…
Reference in New Issue