Repository Public License
1#!/bin/bash2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : ORIX Convert8# File : EmbeddedEngines/libreoffice/fetch.sh9# Module : EmbeddedEngines10# Repository : https://git.spboucher.ai/orix-convert11# Created : 2026-11-2112# Last Modified : 2026-11-2113#14# Author : Simon-Pierre Boucher15# Position : Professor of Finance16# Institution : Université du Québec en Outaouais (UQO)17# Organization : SP Boucher18# Website : https://spboucher.ai19# Git : https://git.spboucher.ai20#21# Preferred Contact: support@spboucher.ai22# Technical Contact: dev@spboucher.ai23# Security/Admin : admin@spboucher.ai24#25# Copyright (c) 202626# Simon-Pierre Boucher27# All rights reserved where applicable. This file is governed by the28# applicable project license, copyright notices and relevant law.29# Existing third-party rights and notices remain unaffected.30#31# License : Proprietary, all rights reserved (see license file)32# License File : LICENSE33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# ORIX Convert — EmbeddedEngines/libreoffice/fetch.sh42# Description: Downloads the official LibreOffice arm64 macOS release DMG from The Document Foundation (pinned43# version + SHA-256), copies LibreOffice.app to EmbeddedEngines/tools/LibreOffice.app and slims it for44# headless conversion (no help, galleries, templates, Python, Java, scripting providers, database45# engines, update checker, Quick Look / Spotlight plug-ins). No LibreOffice code is modified.46# Author: Simon-Pierre Boucher — contact@spboucher.ai47#48# Environment (all optional):49# ORIX_LO_SLIM_STAGES space-separated slim stages to apply (default: all, in the order of ALL_STAGES);50# "none" keeps the official bundle untouched.51# ORIX_LO_DEST destination bundle path (default: EmbeddedEngines/tools/LibreOffice.app).52set -euo pipefail5354VERSION="26.8.3"55DMG="LibreOffice_${VERSION}_MacOS_aarch64.dmg"56URL="https://download.documentfoundation.org/libreoffice/stable/${VERSION}/mac/aarch64/${DMG}"57DMG_SHA256="de943203795e5057785f65515063e2db5eb60b0bb6d8e2534fec59e5cc5fb988"5859ALL_STAGES="integration help content uithemes extensions python java scripting vba database update tools"6061HERE="$(cd "$(dirname "$0")" && pwd)"62WORK="$HERE/work"63DEST="${ORIX_LO_DEST:-$HERE/../tools/LibreOffice.app}"64STAGES="${ORIX_LO_SLIM_STAGES:-$ALL_STAGES}"65mkdir -p "$WORK" "$(dirname "$DEST")"6667size_kb() { LC_ALL=C /usr/bin/du -sk "$1" | /usr/bin/awk '{print $1}'; }68macho_count() {69 /usr/bin/find "$1" -type f -print0 | /usr/bin/xargs -0 /usr/bin/file --no-pad -h | /usr/bin/grep -c 'Mach-O' || true70}7172# --- download + verify -------------------------------------------------------------------------------------------73if [ ! -f "$WORK/$DMG" ]; then74 echo "Downloading $URL"75 /usr/bin/curl --fail --location --silent --show-error -o "$WORK/$DMG.part" "$URL"76 mv "$WORK/$DMG.part" "$WORK/$DMG"77fi78echo "$DMG_SHA256 $WORK/$DMG" | /usr/bin/shasum -a 256 -c -7980# --- copy the official bundle out of the disk image ----------------------------------------------------------------81ORIG="$WORK/LibreOffice.orig.app"82if [ ! -d "$ORIG" ]; then83 MNT="$WORK/mnt"84 mkdir -p "$MNT"85 /usr/bin/hdiutil attach -nobrowse -readonly -mountpoint "$MNT" "$WORK/$DMG" >/dev/null 2>&186 trap '/usr/bin/hdiutil detach "$MNT" >/dev/null 2>&1 || true' EXIT87 /usr/bin/ditto "$MNT/LibreOffice.app" "$ORIG.part"88 /usr/bin/hdiutil detach "$MNT" >/dev/null 2>&189 trap - EXIT90 rmdir "$MNT" 2>/dev/null || true91 mv "$ORIG.part" "$ORIG"92fi93/usr/bin/codesign --verify --deep --strict "$ORIG"94echo "Official bundle: $(size_kb "$ORIG") KiB, $(macho_count "$ORIG") Mach-O files, signature valid"9596rm -rf "$DEST"97/bin/cp -c -R "$ORIG" "$DEST" 2>/dev/null || /usr/bin/ditto "$ORIG" "$DEST"98C="$DEST/Contents"99R="$C/Resources"100F="$C/Frameworks"101102# --- slim stages ---------------------------------------------------------------------------------------------------103# Each stage removes one class of files that the headless conversion tests of Packages/EngineDocuments do not need.104# License texts (LICENSE, LICENSE.html, NOTICE, CREDITS.fodt) and the bundled fonts are never removed.105106stage_integration() {107 # Finder / Spotlight / Quick Look integration of the office suite: a nested helper must not register plug-ins,108 # document types or URL schemes with the system. Info.plist is rewritten (LSUIElement, no document types).109 rm -rf "$C/PlugIns" "$C/Library"110 local P="$C/Info.plist" PB=/usr/libexec/PlistBuddy111 for key in CFBundleDocumentTypes UTExportedTypeDeclarations UTImportedTypeDeclarations CFBundleURLTypes NSServices \112 NSAppleScriptEnabled OSAScriptingDefinition NSAppleEventsUsageDescription NSContactsUsageDescription; do113 $PB -c "Delete :$key" "$P" 2>/dev/null || true114 done115 $PB -c "Delete :LSUIElement" "$P" 2>/dev/null || true116 $PB -c "Add :LSUIElement bool true" "$P"117 $PB -c "Set :CFBundleIdentifier ai.spboucher.orix.convert.libreoffice" "$P"118 $PB -c "Set :CFBundleName ORIX Convert Document Engine" "$P" 2>/dev/null || true119}120121stage_help() {122 rm -rf "$R/help" "$R/readmes" "$R/tipoftheday"123}124125stage_content() {126 # Clip-art galleries, document templates, wizards, AutoText: authoring content, never read by a conversion.127 rm -rf "$R/gallery" "$R/template" "$R/wizards" "$R/autotext"128}129130stage_uithemes() {131 # Icon themes: keep one (Colibre bitmap) for the few export paths that embed stock images.132 /usr/bin/find "$R/config" -maxdepth 1 -name 'images_*.zip' ! -name 'images_colibre.zip' -delete133}134135stage_extensions() {136 # Bundled extensions: the NLP solver (Java) and the spelling / thesaurus data of the dictionaries.137 # Hyphenation patterns (hyph_*.dic) are kept because they change line breaks, hence layout.138 rm -rf "$R/extensions/nlpsolver"139 /usr/bin/find "$R/extensions" -type f \( -name 'th_*' -o -name '*.aff' \) -delete140 /usr/bin/find "$R/extensions" -type f -name '*.dic' ! -name 'hyph_*' -delete141}142143stage_python() {144 # Bundled CPython, PyUNO and the Python scripting provider: not needed to convert, and removing them means a145 # document can never reach a Python interpreter.146 rm -rf "$F/LibreOfficePython.framework" "$R/python" "$R/Scripts/python"147 rm -f "$F/libpyuno.dylib" "$F/pyuno.so" "$F/libpythonloaderlo.dylib"148 rm -f "$R"/*.py "$R"/*.pyi "$R/pythonloader.unorc"149 rm -f "$R/services/pyuno.rdb" "$R/services/scriptproviderforpython.rdb"150}151152stage_java() {153 # Everything that needs a JVM (none is bundled): Java UNO bridge, report builder, HSQLDB, Java wizards.154 rm -rf "$R/java" "$R/Scripts/java" "$R/Scripts/beanshell" "$R/Scripts/javascript" "$R/ure/share/misc/javavendors.xml"155 rm -f "$F"/libjava_uno.dylib "$F"/libjava_uno.jnilib "$F"/libjavaloaderlo.dylib "$F"/libjavavmlo.dylib \156 "$F"/libjuh.jnilib "$F"/libjuhx.dylib "$F"/libjpipe.jnilib "$F"/libhsqldb.jnilib "$F"/libjdbclo.dylib157 # libjvmaccesslo / libjvmfwklo stay: libmergedlo.dylib links them at load time (they only locate a JVM on demand).158 rm -f "$R/services/scriptproviderforbeanshell.rdb" "$R/services/scriptproviderforjavascript.rdb"159 rm -f "$R/registry/reportbuilder.xcd"160}161162stage_scripting() {163 # The Basic macro libraries shipped with the suite (Tools, ScriptForge, Access2Base…). Macro execution is disabled164 # in the profile ORIX Convert generates; without these there is nothing to call either.165 rm -rf "$R/basic" "$R/Scripts"166}167168stage_vba() {169 # VBA object model emulation for Writer and Calc (only reachable from macros, which never run here).170 rm -f "$F"/libvbaobjlo.dylib "$F"/libvbaswobjlo.dylib171}172173stage_database() {174 # Embedded Firebird server and the PostgreSQL / LDAP connectors (LibreOffice Base).175 rm -rf "$R/firebird" "$F/intl"176 # libfbclient stays: libmergedlo.dylib links it at load time.177 rm -f "$F"/libEngine12.dylib "$F"/libfirebird_sdbclo.dylib \178 "$F"/libpostgresql-sdbclo.dylib "$F"/libpostgresql-sdbc-impllo.dylib "$F"/libldapbe2lo.dylib179 rm -f "$R/services/postgresql-sdbc.rdb" "$R/registry/postgresql.xcd"180}181182stage_update() {183 # Online update checker.184 rm -f "$F"/libupdchklo.dylib "$F"/libupdatecheckuilo.dylib "$F"/libupdatefeedlo.dylib "$R/registry/onlineupdate.xcd"185}186187stage_tools() {188 # Command-line tools that are not the converter: extension manager, gallery generator, mail helper, registry189 # viewer, UNO launcher, and the external PDF import helper (xpdfimport, used only to open PDFs in Draw).190 rm -f "$C/MacOS/gengal" "$C/MacOS/regview" "$C/MacOS/senddoc" "$C/MacOS/uno" "$C/MacOS/unoinfo" \191 "$C/MacOS/unopkg" "$C/MacOS/uri-encode" "$C/MacOS/xpdfimport" "$R/senddoc" "$R/unoinfo"192 rm -rf "$R/xpdfimport"193}194195echo "stage size after (KiB)"196printf '%-16s %s\n' "official" "$(size_kb "$DEST")"197if [ "$STAGES" != "none" ]; then198 for stage in $STAGES; do199 case " $ALL_STAGES " in *" $stage "*) ;; *) echo "error: unknown stage $stage" >&2; exit 1 ;; esac200 "stage_$stage"201 printf '%-16s %s\n' "$stage" "$(size_kb "$DEST")"202 done203fi204205# Removing files and editing Info.plist invalidates the official bundle signature (and macOS kills a main executable206# whose Info.plist no longer matches its signature). Re-seal the bundle with an ad-hoc signature that carries the207# same entitlements as the official build, so it runs on the build machine. Nested Mach-O files keep their official208# signatures. The release build replaces all of this with Developer ID signatures (see NOTICE.md).209/usr/bin/codesign -d --entitlements - --xml "$ORIG" 2>/dev/null > "$WORK/official-entitlements.plist"210/usr/bin/plutil -lint "$WORK/official-entitlements.plist" >/dev/null211if [ "$STAGES" != "none" ]; then212 /usr/bin/codesign --force --sign - --entitlements "$WORK/official-entitlements.plist" "$DEST" 2>/dev/null213 /usr/bin/codesign --verify --deep --strict "$DEST"214fi215216# Every load-time dependency inside the bundle must still be present.217missing=0218while IFS= read -r macho; do219 dir="$(dirname "$DEST/$macho")"220 for dep in $(/usr/bin/otool -L "$DEST/$macho" 2>/dev/null | /usr/bin/awk 'NR>1 {print $1}' | /usr/bin/grep '^@loader_path/' || true); do221 [ -e "$dir/${dep#@loader_path/}" ] || { echo "error: $macho needs missing $dep" >&2; missing=1; }222 done223done < <(cd "$DEST" && /usr/bin/find . -type f \( -name '*.dylib' -o -name '*.dylib.*' -o -name '*.so' -o -name '*.jnilib' -o -path './Contents/MacOS/*' \))224[ "$missing" = 0 ] || exit 1225226for keep in LICENSE LICENSE.html NOTICE CREDITS.fodt; do227 [ -f "$R/$keep" ] || { echo "error: $keep is missing from the bundle" >&2; exit 1; }228done229230# List of every Mach-O file left in the bundle (what the release build must sign), next to this script.231( cd "$DEST" && /usr/bin/find . -type f -print0 | /usr/bin/xargs -0 /usr/bin/file --no-pad -h \232 | /usr/bin/grep 'Mach-O' | /usr/bin/sed 's/: *Mach-O.*//' | LC_ALL=C /usr/bin/sort -u ) > "$WORK/macho-files.txt"233234echo "Installed LibreOffice $VERSION at $DEST: $(size_kb "$DEST") KiB, $(wc -l < "$WORK/macho-files.txt" | tr -d ' ') Mach-O files"235echo "Mach-O list: $WORK/macho-files.txt"236