From 4c3a7ce03cd9870bfb85ea8d6f799587f03fc93c Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 17 Aug 2011 00:17:09 -0400 Subject: [PATCH] fixed the symlink install tool --- build/SConscript.install | 2 +- data/darwin/install-symlinks.sh | 31 -------- src/mtsgui/SConscript | 1 + src/mtsgui/mainwindow.ui | 2 +- .../{symlinks.cpp => symlinks_auth.cpp} | 13 ++-- src/mtsgui/symlinks_install.c | 72 +++++++++++++++++++ 6 files changed, 81 insertions(+), 40 deletions(-) delete mode 100755 data/darwin/install-symlinks.sh rename src/mtsgui/{symlinks.cpp => symlinks_auth.cpp} (78%) create mode 100644 src/mtsgui/symlinks_install.c diff --git a/build/SConscript.install b/build/SConscript.install index b16f67d7..ba23a67c 100644 --- a/build/SConscript.install +++ b/build/SConscript.install @@ -119,7 +119,6 @@ elif sys.platform == 'darwin': if hasPython: fixOSXPluginPath('libpython/mitsuba.dylib') installAs(os.path.join(distDir, 'python/mitsuba.so'), 'libpython/mitsuba.dylib') - env.Install(os.path.join(distDir, 'data'), ['#data/darwin/install-symlinks.sh']) install(frameworkDir, [ 'GLEW.framework/Resources/libs/libGLEW.dylib', 'OpenEXR.framework/Resources/lib/libHalf.6.dylib', 'OpenEXR.framework/Resources/lib/libIex.6.dylib', 'OpenEXR.framework/Resources/lib/libImath.6.dylib', @@ -133,6 +132,7 @@ elif sys.platform == 'darwin': 'Collada14Dom.framework/Resources/lib/libCollada14Dom.dylib'], '#dependencies/darwin') if hasQt: install(os.path.join(distDir, 'Contents/MacOS'), ['mtsgui/mtsgui']) + install(os.path.join(distDir, 'Contents/MacOS'), ['mtsgui/symlinks_install']) installTargets += env.OSXLibInst(frameworkDir, '/Library/Frameworks/QtCore.framework/Versions/4/QtCore') opengl = env.OSXLibInst(frameworkDir, '/Library/Frameworks/QtOpenGL.framework/Versions/4/QtOpenGL') xml = env.OSXLibInst(frameworkDir, '/Library/Frameworks/QtXml.framework/Versions/4/QtXml') diff --git a/data/darwin/install-symlinks.sh b/data/darwin/install-symlinks.sh deleted file mode 100755 index ba4faac8..00000000 --- a/data/darwin/install-symlinks.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -APP=`pwd` -PY_DSO=/Library/Python/2.6/site-packages/mitsuba.so - -install() { - echo $APP/Contents/MacOS/$1 \$@ > /usr/bin/$1 - chmod +x /usr/bin/$1 -} -fix_import() { - install_name_tool -change @loader_path/../Contents/Frameworks/$1.dylib $APP/Contents/Frameworks/$1.dylib $PY_DSO -} - -install mitsuba -install mtsgui -install mtssrv -install mtsimport -install mtsutil - -if [ -e $APP/python/mitsuba.so ] -then - cp $APP/python/mitsuba.so $PY_DSO - fix_import libboost_python - fix_import libboost_system - fix_import libboost_filesystem - fix_import libmitsuba-core - fix_import libmitsuba-render - fix_import libmitsuba-hw - fix_import libmitsuba-bidir - fix_import libiomp5 -fi - diff --git a/src/mtsgui/SConscript b/src/mtsgui/SConscript index aa9cf762..402574c5 100644 --- a/src/mtsgui/SConscript +++ b/src/mtsgui/SConscript @@ -54,6 +54,7 @@ if hasQt: qtEnv_osx.ConfigureForObjectiveCPP() qtEnv_osx['CXXFLAGS'].append(['-Fdependencies/darwin', '-framework', 'BWToolkitFramework']) qtSources += qtEnv_osx.StaticObject('previewsettingsdlg_cocoa_impl.mm') + env.Program('symlinks_install', ['symlinks_install.c']) else: qtSources = [x for x in qtSources if (not isinstance(x, str) or 'cocoa' not in x)] mtsgui = qtEnv.Program('mtsgui', qtSources) diff --git a/src/mtsgui/mainwindow.ui b/src/mtsgui/mainwindow.ui index 55d08f36..bb21d4a2 100644 --- a/src/mtsgui/mainwindow.ui +++ b/src/mtsgui/mainwindow.ui @@ -466,7 +466,7 @@ - Enable command line access + Command-line Access diff --git a/src/mtsgui/symlinks.cpp b/src/mtsgui/symlinks_auth.cpp similarity index 78% rename from src/mtsgui/symlinks.cpp rename to src/mtsgui/symlinks_auth.cpp index 076dd903..8f2193c5 100644 --- a/src/mtsgui/symlinks.cpp +++ b/src/mtsgui/symlinks_auth.cpp @@ -13,9 +13,8 @@ bool create_symlinks() { AuthorizationRef ref; OSStatus status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, flags, &ref); - if (status != errAuthorizationSuccess) { + if (status != errAuthorizationSuccess) return false; - } AuthorizationItem items = {kAuthorizationRightExecute, 0, NULL, 0}; AuthorizationRights rights = { 1, &items }; @@ -28,12 +27,12 @@ bool create_symlinks() { AuthorizationFree(ref, kAuthorizationFlagDefaults); return false; } - char *path = "/usr/bin/sudo"; - std::string scriptPath = mitsuba::__ubi_bundlepath() + "/data/install-symlinks.sh"; - char *args[] = { "bash", const_cast(scriptPath.c_str()), NULL }; - FILE *pipe = pipe = NULL; + std::string bundlePath = mitsuba::__ubi_bundlepath(); + std::string path = bundlePath + "/Contents/MacOS/symlinks_install"; + char *args[] = { const_cast(bundlePath.c_str()), NULL }; + FILE *pipe = NULL; flags = kAuthorizationFlagDefaults; - status = AuthorizationExecuteWithPrivileges(ref, path, flags, args, &pipe); + status = AuthorizationExecuteWithPrivileges(ref, const_cast(path.c_str()), flags, args, &pipe); if (status != errAuthorizationSuccess) { AuthorizationFree(ref, kAuthorizationFlagDefaults); return false; diff --git a/src/mtsgui/symlinks_install.c b/src/mtsgui/symlinks_install.c new file mode 100644 index 00000000..5ec396f9 --- /dev/null +++ b/src/mtsgui/symlinks_install.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include + +void installPython(const char *basedir) { + const char *fname = "/Library/Python/2.6/site-packages/mitsuba.pth"; + + FILE *f = fopen(fname, "w"); + if (!f) { + fprintf(stderr, "Unable to write to file \"%s\"!\n", fname); + exit(-1); + } + + if (fprintf(f, "import sys; sys.path.append(\"%s/python\")\n", basedir) < 1) { + fprintf(stderr, "Unexpected I/O error while " + "writing to \"%s\"!\n", fname); + exit(-1); + } + + fclose(f); +} + +void install(const char *basedir, const char *name) { + char fname[MAXPATHLEN]; + FILE *f; + + snprintf(fname, sizeof(fname), "/usr/bin/%s", name); + + f = fopen(fname, "w"); + if (!f) { + fprintf(stderr, "Unable to write to file \"%s\"!\n", fname); + exit(-1); + } + + if (fprintf(f, "%s/Contents/MacOS/%s $@\n", basedir, name) < 1) { + fprintf(stderr, "Unexpected I/O error while " + "writing to \"%s\"!\n", fname); + exit(-1); + } + + fclose(f); + + if (chmod(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) { + fprintf(stderr, "Unexpected I/O error while setting " + "the permssions of \"%s\"!\n", fname); + exit(-1); + } +} + +int main(int argc, char **argv) { + if (argc != 2) { + fprintf(stderr, "Incorrect number of arguments!\n"); + return -1; + } + + if (setuid(0) != 0) { + fprintf(stderr, "setuid(): failed!\n"); + return -1; + } + + install(argv[1], "mitsuba"); + install(argv[1], "mtsgui"); + install(argv[1], "mtssrv"); + install(argv[1], "mtsutil"); + install(argv[1], "mtsimport"); + installPython(argv[1]); + + return 0; +} +