2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2006-04-28 12:26:19 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2022-04-06 08:26:49 +00:00
|
|
|
// Copyright (C) 2022 University of California
|
2006-04-28 12:26:19 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2006-04-28 12:26:19 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-04-28 12:26:19 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2006-04-28 12:26:19 +00:00
|
|
|
|
2005-03-30 09:56:55 +00:00
|
|
|
/*
|
2013-05-08 10:11:57 +00:00
|
|
|
* SetVersion.cpp
|
2005-03-30 09:56:55 +00:00
|
|
|
* boinc
|
|
|
|
*
|
|
|
|
*/
|
2005-05-17 11:27:08 +00:00
|
|
|
|
2021-06-19 08:29:48 +00:00
|
|
|
// Important: To ensure that the relevant *info.plist and *InfoPlist.strings
|
|
|
|
// files are available by the time they are needed for building a target:
|
|
|
|
// [1] include SetVersion in that target's "Target Dependencies" phase,
|
|
|
|
// [2] if a target is dependent on a file created by SetVersion, make sure
|
|
|
|
// the file is listed as an Output File for SetVersion's script phase.
|
|
|
|
// Otherwise, the build may fail due to a race condition.
|
|
|
|
//
|
|
|
|
// Also, make sure the template used by SetVersion to create the file exists
|
|
|
|
// in clientgui/mac/templates.
|
|
|
|
//
|
|
|
|
|
2005-05-17 11:27:08 +00:00
|
|
|
// Set STAND_ALONE TRUE if testing as a separate applicaiton
|
|
|
|
#define STAND_ALONE 0
|
2017-03-01 12:59:17 +00:00
|
|
|
#define VERBOSE_SPAWN 0 /* for debugging callPosixSpawn */
|
|
|
|
|
|
|
|
#include <Carbon/Carbon.h>
|
2005-05-17 11:27:08 +00:00
|
|
|
|
2005-03-30 09:56:55 +00:00
|
|
|
#include <stdio.h>
|
2005-05-17 11:27:08 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-04-28 12:26:19 +00:00
|
|
|
#include <unistd.h>
|
2014-06-16 10:02:04 +00:00
|
|
|
#include <time.h>
|
2013-05-08 10:11:57 +00:00
|
|
|
#include <sys/param.h> // for MAXPATHLEN
|
|
|
|
#include <sys/stat.h>
|
2005-03-30 09:56:55 +00:00
|
|
|
#include "version.h"
|
|
|
|
|
2013-05-08 10:11:57 +00:00
|
|
|
int file_exists(const char* path);
|
|
|
|
int FixInfoPlistFile(char* name);
|
2012-06-22 04:28:45 +00:00
|
|
|
int FixInfoPlist_Strings(char* myPath, char* name);
|
2012-01-06 10:44:53 +00:00
|
|
|
int MakeBOINCPackageInfoPlistFile(char* myPath, char* brand);
|
2013-06-11 12:22:12 +00:00
|
|
|
int MakeBOINCRestartPackageInfoPlistFile(char* myPath, char* brand);
|
2012-01-06 10:44:53 +00:00
|
|
|
int MakeMetaPackageInfoPlistFile(char* myPath, char* brand);
|
2017-03-01 12:59:17 +00:00
|
|
|
int callPosixSpawn(const char *cmd);
|
2005-05-17 11:27:08 +00:00
|
|
|
|
2005-03-30 09:56:55 +00:00
|
|
|
int main(int argc, char** argv) {
|
2005-05-17 11:27:08 +00:00
|
|
|
int retval = 0, err;
|
|
|
|
|
|
|
|
#if STAND_ALONE
|
|
|
|
char myPath[1024];
|
|
|
|
getcwd(myPath, sizeof(myPath));
|
|
|
|
printf("%s\n", myPath); // For debugging
|
|
|
|
#endif
|
|
|
|
|
2013-07-16 09:29:35 +00:00
|
|
|
if (!file_exists("./English.lproj")) {
|
|
|
|
retval = mkdir("./English.lproj", 0755);
|
|
|
|
if (retval) {
|
|
|
|
printf("Error %d creating directory English.lproj\n", retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-22 04:28:45 +00:00
|
|
|
// BOINC Manager
|
|
|
|
err = FixInfoPlist_Strings("./English.lproj/InfoPlist.strings", "BOINC Manager");
|
2006-01-21 12:42:04 +00:00
|
|
|
if (err) retval = err;
|
2013-05-08 10:11:57 +00:00
|
|
|
err = FixInfoPlistFile("Info.plist");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (err) retval = err;
|
2012-06-22 04:28:45 +00:00
|
|
|
|
|
|
|
// BOINC Installer
|
|
|
|
err = FixInfoPlist_Strings("./English.lproj/Installer-InfoPlist.strings", "BOINC Installer");
|
|
|
|
if (err) retval = err;
|
2013-05-08 10:11:57 +00:00
|
|
|
err = FixInfoPlistFile("Installer-Info.plist");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (err) retval = err;
|
2012-06-22 04:28:45 +00:00
|
|
|
|
|
|
|
// BOINC PostInstall app
|
|
|
|
err = FixInfoPlist_Strings("./English.lproj/PostInstall-InfoPlist.strings", "Install BOINC");
|
|
|
|
if (err) retval = err;
|
2013-05-08 10:11:57 +00:00
|
|
|
err = FixInfoPlistFile("PostInstall-Info.plist");
|
2006-06-27 12:56:11 +00:00
|
|
|
if (err) retval = err;
|
2012-06-22 04:28:45 +00:00
|
|
|
|
|
|
|
// BOINC Screen Saver
|
|
|
|
err = FixInfoPlist_Strings("./English.lproj/ScreenSaver-InfoPlist.strings", "BOINC Screen Saver");
|
|
|
|
if (err) retval = err;
|
2013-05-08 10:11:57 +00:00
|
|
|
err = FixInfoPlistFile("ScreenSaver-Info.plist");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (err) retval = err;
|
2012-06-22 04:28:45 +00:00
|
|
|
|
|
|
|
// BOINC Uninstaller
|
|
|
|
err = FixInfoPlist_Strings("./English.lproj/Uninstaller-InfoPlist.strings", "Uninstall BOINC");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (err) retval = err;
|
2013-05-08 10:11:57 +00:00
|
|
|
err = FixInfoPlistFile("Uninstaller-Info.plist");
|
2007-06-06 11:42:51 +00:00
|
|
|
if (err) retval = err;
|
2012-06-22 04:28:45 +00:00
|
|
|
|
2021-06-19 08:29:48 +00:00
|
|
|
// SystemMenu is not currently used
|
2013-05-08 10:11:57 +00:00
|
|
|
err = FixInfoPlistFile("SystemMenu-Info.plist");
|
2012-06-22 04:28:45 +00:00
|
|
|
if (err) retval = err;
|
|
|
|
|
2020-11-23 12:43:14 +00:00
|
|
|
// BOINCCmd
|
|
|
|
err = FixInfoPlistFile("BoincCmd-Info.plist");
|
|
|
|
if (err) retval = err;
|
|
|
|
|
2012-06-22 04:28:45 +00:00
|
|
|
// WaitPermissions is not currently used
|
2013-05-08 10:11:57 +00:00
|
|
|
err = FixInfoPlistFile("WaitPermissions-Info.plist");
|
2009-11-18 10:19:14 +00:00
|
|
|
if (err) retval = err;
|
2012-06-22 04:28:45 +00:00
|
|
|
|
2021-06-19 08:29:48 +00:00
|
|
|
// The following are not used by Xcode, and are probably obsolete
|
2012-01-06 10:44:53 +00:00
|
|
|
err = MakeBOINCPackageInfoPlistFile("./Pkg-Info.plist", "BOINC Manager");
|
|
|
|
if (err) retval = err;
|
2012-06-22 04:28:45 +00:00
|
|
|
|
2013-06-11 12:22:12 +00:00
|
|
|
err = MakeBOINCRestartPackageInfoPlistFile("./Pkg_Restart-Info.plist", "BOINC Manager");
|
|
|
|
if (err) retval = err;
|
|
|
|
|
2012-01-06 10:44:53 +00:00
|
|
|
err = MakeMetaPackageInfoPlistFile("./Mpkg-Info.plist", "BOINC Manager");
|
2005-05-17 11:27:08 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-08 10:11:57 +00:00
|
|
|
int file_exists(const char* path) {
|
|
|
|
struct stat buf;
|
|
|
|
if (stat(path, &buf)) {
|
|
|
|
return false; // stat() returns zero on success
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-22 04:28:45 +00:00
|
|
|
int FixInfoPlist_Strings(char* myPath, char* name) {
|
2005-05-17 11:27:08 +00:00
|
|
|
int retval = 0;
|
|
|
|
FILE *f;
|
2014-06-16 10:02:04 +00:00
|
|
|
time_t cur_time;
|
|
|
|
struct tm *time_data;
|
|
|
|
|
|
|
|
cur_time = time(NULL);
|
|
|
|
time_data = localtime( &cur_time );
|
2005-03-30 09:56:55 +00:00
|
|
|
|
2005-05-17 11:27:08 +00:00
|
|
|
f = fopen(myPath, "w");
|
2005-03-30 09:56:55 +00:00
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fprintf(f, "/* Localized versions of Info.plist keys */\n\n");
|
2012-06-22 04:28:45 +00:00
|
|
|
fprintf(f, "CFBundleName = \"%s\";\n", name);
|
|
|
|
fprintf(f, "CFBundleShortVersionString = \"%s version %s\";\n", name, BOINC_VERSION_STRING);
|
2014-06-16 10:02:04 +00:00
|
|
|
fprintf(f, "CFBundleGetInfoString = \"%s version %s, Copyright %d University of California.\";\n", name, BOINC_VERSION_STRING, time_data->tm_year+1900);
|
2006-04-28 12:26:19 +00:00
|
|
|
fflush(f);
|
2005-03-30 09:56:55 +00:00
|
|
|
retval = fclose(f);
|
|
|
|
}
|
2005-05-17 11:27:08 +00:00
|
|
|
else {
|
2013-07-16 09:29:35 +00:00
|
|
|
printf("Error creating file %s\n", myPath);
|
2005-03-30 09:56:55 +00:00
|
|
|
retval = -1;
|
2005-05-17 11:27:08 +00:00
|
|
|
}
|
2005-03-30 09:56:55 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-05-08 10:11:57 +00:00
|
|
|
int FixInfoPlistFile(char* name) {
|
2005-05-17 11:27:08 +00:00
|
|
|
int retval = 0;
|
|
|
|
FILE *fin = NULL, *fout = NULL;
|
|
|
|
char *c, a, buf[1024];
|
2013-05-08 10:11:57 +00:00
|
|
|
char srcPath[MAXPATHLEN], dstPath[MAXPATHLEN];
|
|
|
|
|
|
|
|
strcpy(dstPath, "./");
|
|
|
|
strcat(dstPath, name);
|
2005-05-17 11:27:08 +00:00
|
|
|
|
2013-05-08 10:11:57 +00:00
|
|
|
strcpy(srcPath, "../clientgui/mac/templates/");
|
|
|
|
strcat(srcPath, name);
|
|
|
|
|
|
|
|
// Save the old file in case there is an error updating it
|
|
|
|
if (file_exists(dstPath)) {
|
|
|
|
rename(dstPath, "./temp");
|
|
|
|
}
|
2006-04-28 12:26:19 +00:00
|
|
|
|
2013-05-08 10:11:57 +00:00
|
|
|
fin = fopen(srcPath, "r");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (fin == NULL)
|
|
|
|
goto bail;
|
|
|
|
|
2013-05-08 10:11:57 +00:00
|
|
|
fout = fopen(dstPath, "w");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (fout == NULL) {
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy everything up to version number
|
|
|
|
for (;;) {
|
|
|
|
c = fgets(buf, sizeof(buf), fin);
|
|
|
|
if (c == NULL)
|
|
|
|
goto bail; // EOF
|
|
|
|
c = strstr(buf, "CFBundleVersion</key>");
|
|
|
|
if (c)
|
|
|
|
break; // Found "CFBundleVersion</key>"
|
|
|
|
fputs(buf, fout);
|
|
|
|
}
|
|
|
|
|
|
|
|
c = strstr(buf, "<string>");
|
|
|
|
if (c == NULL) {
|
|
|
|
fputs(buf, fout);
|
|
|
|
c = fgets(buf, sizeof(buf), fin);
|
|
|
|
if (c == NULL)
|
|
|
|
goto bail; // EOF
|
|
|
|
c = strstr(buf, "<string>");
|
|
|
|
if (c == NULL)
|
|
|
|
goto bail; // "CFBundleVersion</key>" not followed by "<string>"
|
|
|
|
}
|
|
|
|
|
|
|
|
a = *(c+8);
|
|
|
|
*(c+8) = '\0'; // Put terminator after "<string>"
|
|
|
|
fputs(buf, fout); // Copy up to end of "<string>"
|
|
|
|
fputs(BOINC_VERSION_STRING, fout); // Write the current version number
|
|
|
|
*(c+8) = a; // Undo terminator we inserted
|
|
|
|
c = strstr(buf, "</string>"); // Skip over old version number in input
|
|
|
|
fputs(c, fout); // Copy rest of input line
|
|
|
|
|
|
|
|
// Copy rest of file
|
|
|
|
for (;;) {
|
|
|
|
c = fgets(buf, sizeof(buf), fin);
|
|
|
|
if (c == NULL)
|
|
|
|
break; // EOF
|
|
|
|
fputs(buf, fout);
|
|
|
|
}
|
2005-03-30 09:56:55 +00:00
|
|
|
|
2005-05-17 11:27:08 +00:00
|
|
|
fclose(fin);
|
2006-04-28 12:26:19 +00:00
|
|
|
fflush(fout);
|
2005-05-17 11:27:08 +00:00
|
|
|
fclose(fout);
|
2013-05-08 10:11:57 +00:00
|
|
|
|
2006-04-28 12:26:19 +00:00
|
|
|
unlink("temp");
|
2005-05-17 11:27:08 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
bail:
|
|
|
|
if (fin)
|
|
|
|
fclose(fin);
|
|
|
|
if (fout)
|
|
|
|
fclose(fout);
|
|
|
|
|
2013-05-08 10:11:57 +00:00
|
|
|
if (file_exists("./temp")) {
|
|
|
|
rename("./temp", dstPath);
|
2006-04-28 12:26:19 +00:00
|
|
|
// sprintf(buf, "mv -f temp %s", myPath);
|
2017-03-01 12:59:17 +00:00
|
|
|
// retval = callPosixSpawn(buf);
|
2013-05-08 10:11:57 +00:00
|
|
|
} else {
|
|
|
|
sprintf(buf, "cp -f %s %s", srcPath, dstPath);
|
2017-03-01 12:59:17 +00:00
|
|
|
retval = callPosixSpawn(buf);
|
2013-05-08 10:11:57 +00:00
|
|
|
}
|
2006-04-28 12:26:19 +00:00
|
|
|
|
2013-05-08 10:11:57 +00:00
|
|
|
printf("Error updating version number in file %s\n", dstPath);
|
2005-05-17 11:27:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2005-09-02 04:16:20 +00:00
|
|
|
|
|
|
|
|
2012-01-06 10:44:53 +00:00
|
|
|
int MakeBOINCPackageInfoPlistFile(char* myPath, char* brand) {
|
2005-09-02 04:16:20 +00:00
|
|
|
int retval = 0;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
f = fopen(myPath, "w");
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
2012-01-06 10:44:53 +00:00
|
|
|
fprintf(f, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
|
2005-09-02 04:16:20 +00:00
|
|
|
fprintf(f, "<plist version=\"1.0\">\n<dict>\n");
|
|
|
|
fprintf(f, "\t<key>CFBundleGetInfoString</key>\n");
|
2006-01-21 12:42:04 +00:00
|
|
|
fprintf(f, "\t<string>%s %s</string>\n", brand, BOINC_VERSION_STRING);
|
2005-09-02 04:16:20 +00:00
|
|
|
fprintf(f, "\t<key>CFBundleIdentifier</key>\n\t<string>edu.berkeley.boinc</string>\n");
|
|
|
|
fprintf(f, "\t<key>CFBundleShortVersionString</key>\n");
|
|
|
|
fprintf(f, "\t<string>%s</string>\n", BOINC_VERSION_STRING);
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagAllowBackRev</key>\n\t<integer>1</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagAuthorizationAction</key>\n\t<string>AdminAuthorization</string>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagDefaultLocation</key>\n\t<string>/</string>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagFollowLinks</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagInstallFat</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagInstalledSize</key>\n\t<integer>6680</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagIsRequired</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagOverwritePermissions</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagRelocatable</key>\n\t<integer>0</integer>\n");
|
2010-11-19 11:23:28 +00:00
|
|
|
fprintf(f, "\t<key>IFPkgFlagRestartAction</key>\n\t<string>NoRestart</string>\n");
|
2005-09-02 04:16:20 +00:00
|
|
|
fprintf(f, "\t<key>IFPkgFlagRootVolumeOnly</key>\n\t<integer>1</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagUpdateInstalledLanguages</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFormatVersion</key>\n\t<real>0.10000000149011612</real>\n");
|
|
|
|
fprintf(f, "</dict>\n</plist>\n");
|
|
|
|
|
2006-04-28 12:26:19 +00:00
|
|
|
fflush(f);
|
2005-09-02 04:16:20 +00:00
|
|
|
retval = fclose(f);
|
|
|
|
}
|
|
|
|
else {
|
2013-06-11 12:22:12 +00:00
|
|
|
printf("Error creating file %s\n", myPath);
|
2005-09-02 04:16:20 +00:00
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-01 06:32:40 +00:00
|
|
|
// Create a MetaPackage which runs only BOINC,pkg but specifies Restart Required
|
2013-06-11 12:22:12 +00:00
|
|
|
int MakeBOINCRestartPackageInfoPlistFile(char* myPath, char* brand) {
|
|
|
|
int retval = 0;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
f = fopen(myPath, "w");
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
|
|
|
fprintf(f, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
|
|
|
|
fprintf(f, "<plist version=\"1.0\">\n<dict>\n");
|
|
|
|
fprintf(f, "\t<key>CFBundleGetInfoString</key>\n");
|
|
|
|
fprintf(f, "\t<string>%s %s</string>\n", brand, BOINC_VERSION_STRING);
|
|
|
|
fprintf(f, "\t<key>CFBundleIdentifier</key>\n\t<string>edu.berkeley.boinc_r</string>\n");
|
|
|
|
fprintf(f, "\t<key>CFBundleShortVersionString</key>\n");
|
|
|
|
fprintf(f, "\t<string>%s</string>\n", BOINC_VERSION_STRING);
|
|
|
|
fprintf(f, "\t<key>IFMajorVersion</key>\n\t<integer>%d</integer>\n", BOINC_MAJOR_VERSION);
|
|
|
|
fprintf(f, "\t<key>IFMinorVersion</key>\n\t<integer>%d</integer>\n", BOINC_MINOR_VERSION);
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagAllowBackRev</key>\n\t<integer>1</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagAuthorizationAction</key>\n\t<string>AdminAuthorization</string>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagRestartAction</key>\n\t<string>RequiredRestart</string>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagRootVolumeOnly</key>\n\t<integer>1</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagComponentDirectory</key>\n\t<string>../</string>\n");
|
|
|
|
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagPackageList</key>\n");
|
|
|
|
|
|
|
|
fprintf(f, "\t<array>\n");
|
|
|
|
fprintf(f, "\t\t<dict>\n");
|
|
|
|
fprintf(f, "\t\t\t<key>IFPkgFlagPackageLocation</key>\n\t\t\t<string>BOINC.pkg</string>\n");
|
|
|
|
fprintf(f, "\t\t\t<key>IFPkgFlagPackageSelection</key>\n\t\t\t<string>required</string>\n");
|
|
|
|
fprintf(f, "\t\t</dict>\n");
|
|
|
|
fprintf(f, "\t</array>\n");
|
|
|
|
|
|
|
|
fprintf(f, "\t<key>IFPkgFormatVersion</key>\n\t<real>0.10000000149011612</real>\n");
|
|
|
|
fprintf(f, "</dict>\n</plist>\n");
|
|
|
|
|
|
|
|
fflush(f);
|
|
|
|
retval = fclose(f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("Error creating file %s\n", myPath);
|
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Make a MetaPackage to install both BOINC and VirtualBox
|
2012-01-06 10:44:53 +00:00
|
|
|
int MakeMetaPackageInfoPlistFile(char* myPath, char* brand) {
|
|
|
|
int retval = 0;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
f = fopen(myPath, "w");
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
|
|
|
fprintf(f, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
|
|
|
|
fprintf(f, "<plist version=\"1.0\">\n<dict>\n");
|
|
|
|
fprintf(f, "\t<key>CFBundleGetInfoString</key>\n");
|
|
|
|
fprintf(f, "\t<string>%s %s + VirtualBox</string>\n", brand, BOINC_VERSION_STRING);
|
|
|
|
fprintf(f, "\t<key>CFBundleIdentifier</key>\n\t<string>edu.berkeley.boinc+vbox</string>\n");
|
|
|
|
fprintf(f, "\t<key>CFBundleShortVersionString</key>\n");
|
|
|
|
fprintf(f, "\t<string>%s</string>\n", BOINC_VERSION_STRING);
|
|
|
|
fprintf(f, "\t<key>IFMajorVersion</key>\n\t<integer>%d</integer>\n", BOINC_MAJOR_VERSION);
|
|
|
|
fprintf(f, "\t<key>IFMinorVersion</key>\n\t<integer>%d</integer>\n", BOINC_MINOR_VERSION);
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagAllowBackRev</key>\n\t<integer>1</integer>\n");
|
2013-06-11 12:22:12 +00:00
|
|
|
fprintf(f, "\t<key>IFPkgFlagAuthorizationAction</key>\n\t<string>AdminAuthorization</string>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagRestartAction</key>\n\t<string>NoRestart</string>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagRootVolumeOnly</key>\n\t<integer>1</integer>\n");
|
2012-01-06 10:44:53 +00:00
|
|
|
fprintf(f, "\t<key>IFPkgFlagComponentDirectory</key>\n\t<string>../</string>\n");
|
|
|
|
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagPackageList</key>\n");
|
|
|
|
|
|
|
|
fprintf(f, "\t<array>\n");
|
|
|
|
fprintf(f, "\t\t<dict>\n");
|
|
|
|
fprintf(f, "\t\t\t<key>IFPkgFlagPackageLocation</key>\n\t\t\t<string>BOINC.pkg</string>\n");
|
|
|
|
fprintf(f, "\t\t\t<key>IFPkgFlagPackageSelection</key>\n\t\t\t<string>required</string>\n");
|
|
|
|
fprintf(f, "\t\t</dict>\n");
|
|
|
|
|
|
|
|
fprintf(f, "\t\t<dict>\n");
|
|
|
|
fprintf(f, "\t\t\t<key>IFPkgFlagPackageLocation</key>\n\t\t\t<string>VirtualBox.pkg</string>\n");
|
|
|
|
fprintf(f, "\t\t\t<key>IFPkgFlagPackageSelection</key>\n\t\t\t<string>selected</string>\n");
|
|
|
|
fprintf(f, "\t\t</dict>\n");
|
|
|
|
fprintf(f, "\t</array>\n");
|
|
|
|
|
|
|
|
fprintf(f, "\t<key>IFPkgFormatVersion</key>\n\t<real>0.10000000149011612</real>\n");
|
|
|
|
fprintf(f, "</dict>\n</plist>\n");
|
|
|
|
|
|
|
|
fflush(f);
|
|
|
|
retval = fclose(f);
|
|
|
|
}
|
|
|
|
else {
|
2013-06-11 12:22:12 +00:00
|
|
|
printf("Error creating file %s\n", myPath);
|
2012-01-06 10:44:53 +00:00
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-01 12:59:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define NOT_IN_TOKEN 0
|
|
|
|
#define IN_SINGLE_QUOTED_TOKEN 1
|
|
|
|
#define IN_DOUBLE_QUOTED_TOKEN 2
|
|
|
|
#define IN_UNQUOTED_TOKEN 3
|
|
|
|
|
2022-04-06 08:26:49 +00:00
|
|
|
static int parse_posix_spawn_command_line(char* p, char** argv) {
|
2017-03-01 12:59:17 +00:00
|
|
|
int state = NOT_IN_TOKEN;
|
|
|
|
int argc=0;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
switch(state) {
|
|
|
|
case NOT_IN_TOKEN:
|
|
|
|
if (isspace(*p)) {
|
|
|
|
} else if (*p == '\'') {
|
|
|
|
p++;
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_SINGLE_QUOTED_TOKEN;
|
|
|
|
break;
|
|
|
|
} else if (*p == '\"') {
|
|
|
|
p++;
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_DOUBLE_QUOTED_TOKEN;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_UNQUOTED_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_SINGLE_QUOTED_TOKEN:
|
|
|
|
if (*p == '\'') {
|
|
|
|
if (*(p-1) == '\\') break;
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_DOUBLE_QUOTED_TOKEN:
|
|
|
|
if (*p == '\"') {
|
|
|
|
if (*(p-1) == '\\') break;
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_UNQUOTED_TOKEN:
|
|
|
|
if (isspace(*p)) {
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
argv[argc] = 0;
|
|
|
|
return argc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <spawn.h>
|
|
|
|
|
|
|
|
int callPosixSpawn(const char *cmdline) {
|
|
|
|
char command[1024];
|
|
|
|
char progName[1024];
|
|
|
|
char progPath[MAXPATHLEN];
|
|
|
|
char* argv[100];
|
2022-04-06 08:26:49 +00:00
|
|
|
int argc __attribute__((unused)) = 0;
|
2017-03-01 12:59:17 +00:00
|
|
|
char *p;
|
|
|
|
pid_t thePid = 0;
|
|
|
|
int result = 0;
|
|
|
|
int status = 0;
|
|
|
|
extern char **environ;
|
|
|
|
|
2022-04-06 08:26:49 +00:00
|
|
|
// Make a copy of cmdline because parse_posix_spawn_command_line modifies it
|
2017-03-01 12:59:17 +00:00
|
|
|
strlcpy(command, cmdline, sizeof(command));
|
2022-04-06 08:26:49 +00:00
|
|
|
argc = parse_posix_spawn_command_line(const_cast<char*>(command), argv);
|
2017-03-01 12:59:17 +00:00
|
|
|
strlcpy(progPath, argv[0], sizeof(progPath));
|
|
|
|
strlcpy(progName, argv[0], sizeof(progName));
|
|
|
|
p = strrchr(progName, '/');
|
|
|
|
if (p) {
|
|
|
|
argv[0] = p+1;
|
|
|
|
} else {
|
|
|
|
argv[0] = progName;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if VERBOSE_SPAWN
|
|
|
|
printf("***********");
|
|
|
|
for (int i=0; i<argc; ++i) {
|
|
|
|
printf("argv[%d]=%s", i, argv[i]);
|
|
|
|
}
|
|
|
|
printf("***********\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
result = posix_spawnp(&thePid, progPath, NULL, NULL, argv, environ);
|
|
|
|
#if VERBOSE_SPAWN
|
|
|
|
printf("callPosixSpawn command: %s", cmdline);
|
|
|
|
printf("callPosixSpawn: posix_spawnp returned %d: %s", result, strerror(result));
|
|
|
|
#endif
|
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
// CAF int val =
|
|
|
|
waitpid(thePid, &status, WUNTRACED);
|
|
|
|
// CAF if (val < 0) printf("first waitpid returned %d\n", val);
|
|
|
|
if (status != 0) {
|
|
|
|
#if VERBOSE_SPAWN
|
|
|
|
printf("waitpid() returned status=%d", status);
|
|
|
|
#endif
|
|
|
|
result = status;
|
|
|
|
} else {
|
|
|
|
if (WIFEXITED(status)) {
|
|
|
|
result = WEXITSTATUS(status);
|
|
|
|
if (result == 1) {
|
|
|
|
#if VERBOSE_SPAWN
|
|
|
|
printf("WEXITSTATUS(status) returned 1, errno=%d: %s", errno, strerror(errno));
|
|
|
|
#endif
|
|
|
|
result = errno;
|
|
|
|
}
|
|
|
|
#if VERBOSE_SPAWN
|
|
|
|
else if (result) {
|
|
|
|
printf("WEXITSTATUS(status) returned %d", result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} // end if (WIFEXITED(status)) else
|
|
|
|
} // end if waitpid returned 0 sstaus else
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|