Files
luminary/macos/launcher/main.c
T
bhursey b34d34dacb Package a self-contained macOS app and harden serving
- Add macos/build.mjs: stages a universal .app outside the checkout, bundles
  and checksums Node, installs production deps per architecture, compiles the
  launcher shim, signs ad-hoc or with a Developer ID, and writes a zip and dmg
  with an optional notarization path.
- Serve precompressed brotli/gzip assets and split admin panels and the public
  pages out of the main bundle.
- Support HTTP range requests, and fix upload and quota accounting, gallery
  download counts and unreadable-file handling.
- Add server HTTP integration tests, a Gitea CI workflow, a catalog backup
  script and a crash screen for the UI.
2026-11-29 06:23:58 +00:00

74 lines
2.2 KiB
C

/*
* Luminary.app main executable.
*
* The bundle needs a Mach-O main executable so it can be code signed and, if a
* certificate is ever bought, notarized: Apple's notary service rejects a
* bundle whose CFBundleExecutable is a shell script. This shim resolves its own
* path, finds Contents/Resources/launcher.sh next to it, and execs bash on it,
* passing every argument through. All the actual launcher logic lives in that
* script, where it can be changed without recompiling anything.
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
/** Write this process's executable path into buf, or return -1. */
static int executable_path(char *buf, size_t size) {
#ifdef __APPLE__
uint32_t needed = (uint32_t)size;
if (_NSGetExecutablePath(buf, &needed) != 0) return -1;
return 0;
#else
/* Not used in the bundle; kept so the shim can be built and tested when
* packaging is exercised from a non-Apple host. */
ssize_t length = readlink("/proc/self/exe", buf, size - 1);
if (length < 0) return -1;
buf[length] = '\0';
return 0;
#endif
}
int main(int argc, char **argv) {
char raw[PATH_MAX];
char exe[PATH_MAX];
char script[PATH_MAX];
if (executable_path(raw, sizeof raw) != 0) {
fprintf(stderr, "luminary: cannot resolve the application path\n");
return 1;
}
if (realpath(raw, exe) == NULL) {
fprintf(stderr, "luminary: cannot resolve %s\n", raw);
return 1;
}
/* exe is .../Luminary.app/Contents/MacOS/Luminary */
char *slash = strrchr(exe, '/');
if (slash == NULL) {
fprintf(stderr, "luminary: unexpected executable path %s\n", exe);
return 1;
}
*slash = '\0';
if (snprintf(script, sizeof script, "%s/../Resources/launcher.sh", exe) >= (int)sizeof script) {
fprintf(stderr, "luminary: application path is too long\n");
return 1;
}
char *args[argc + 2];
args[0] = "/bin/bash";
args[1] = script;
for (int i = 1; i < argc; i++) args[i + 1] = argv[i];
args[argc + 1] = NULL;
execv("/bin/bash", args);
perror("luminary: could not start the launcher");
return 1;
}