5 # Use of unset variable is an error
7 # If any part of a pipeline of commands fails, the whole pipeline fails
10 # Script to sign executables, dylibs and frameworks in an app bundle plus the bundle itself. Called
11 # from installer::simplepackage::create_package() in solenv/bin/modules/installer/simplepackage.pm
12 # and the test-install target in Makefile.in.
14 test `uname` = Darwin ||
{ echo This is
for macOS only
; exit 1; }
16 test $# = 1 ||
{ echo Usage
: $0 app-bundle
; exit 1; }
20 MACOSX_BUNDLE_IDENTIFIER \
21 MACOSX_CODESIGNING_IDENTITY
; do
22 if test -z "$(eval echo '$'$V)"; then
23 echo No
'$'$V "environment variable! This should be run in a build only"
30 if test -n "$ENABLE_MACOSX_SANDBOX"; then
31 # In a sandboxed build executables need the entitlements
32 entitlements
="--entitlements $BUILDDIR/lo.xcent"
33 # We use --enable-canonical-installation-tree-structure so all
34 # data files in Resources are included in the app bundle signature
35 # through that. I think.
38 # We then want to sign data files, too, hmm.
39 entitlements
="--entitlements $SRCDIR/hardened_runtime.xcent"
41 -or -name '*.fodt' -or -name 'schema.strings' -or -name 'schema.xml' \
42 -or -name '*.jar' -or -name 'LICENSE' -or -name 'LICENSE.html' \
43 -or -name '*.applescript' -or -name '*.odt'"
46 # Sign jnilibs first as workaround for signing issue on old baseline
47 # order matters/screws things up otherwise
48 find -d "$APP_BUNDLE" \
( -name '*.jnilib' \
) ! -type l |
50 id
=`echo ${file#${APP_BUNDLE}/Contents/} | sed -e 's,/,.,g'`
51 codesign
--verbose --force --identifier=$MACOSX_BUNDLE_IDENTIFIER.
$id --sign "$MACOSX_CODESIGNING_IDENTITY" "$file" > "/tmp/codesign_$(basename "$file").log" 2>&1
52 if [ "$?" != "0" ] ; then
55 rm "/tmp/codesign_$(basename "$file").log"
60 # The dylibs in the Python framework are called *.so. Go figure
62 # On Mavericks also would like to have data files signed...
63 # add some where it makes sense. Make a depth-first search to sign the contents
64 # of e.g. the spotlight plugin before attempting to sign the plugin itself
66 find "$APP_BUNDLE" \
( -name '*.dylib' -or -name '*.dylib.*' -or -name '*.so' \
67 $other_files \
) ! -type l |
69 id
=`echo ${file#${APP_BUNDLE}/Contents/} | sed -e 's,/,.,g'`
70 codesign
--verbose --force --identifier=$MACOSX_BUNDLE_IDENTIFIER.
$id --sign "$MACOSX_CODESIGNING_IDENTITY" "$file" > "/tmp/codesign_$(basename "$file").log" 2>&1
71 if [ "$?" != "0" ] ; then
74 rm "/tmp/codesign_$(basename "$file").log"
77 # Sign included bundles. First .app ones (i.e. the Python.app inside
78 # the LibreOfficePython.framework. Be generic for kicks...)
80 find "$APP_BUNDLE"/Contents
-name '*.app' -type d |
84 # Assume the app has a XML (and not binary) Info.plist
85 id
=`grep -A 1 '<key>CFBundleIdentifier</key>' $app/Contents/Info.plist | tail -1 | sed -e 's,.*<string>,,' -e 's,</string>.*,,'`
86 codesign
--verbose --options=runtime
--force --identifier=$id --sign "$MACOSX_CODESIGNING_IDENTITY" $entitlements "$app" > "/tmp/codesign_${fn}.log" 2>&1
87 if [ "$?" != "0" ] ; then
90 rm "/tmp/codesign_${fn}.log"
93 # Then .framework ones. Again, be generic just for kicks.
95 find "$APP_BUNDLE" -name '*.framework' -type d |
96 while read framework
; do
97 fn
=`basename "$framework"`
99 for version
in "$framework"/Versions
/*; do
100 if test ! -L "$version" -a -d "$version"; then
101 # Assume the framework has a XML (and not binary) Info.plist
102 id
=`grep -A 1 '<key>CFBundleIdentifier</key>' $version/Resources/Info.plist | tail -1 | sed -e 's,.*<string>,,' -e 's,</string>.*,,'`
103 # files in bin are not covered by signing the framework...
104 for scriptorexecutable
in $
(find $version/bin
/ -type f
); do
105 codesign
--verbose --options=runtime
--force --identifier=$id --sign "$MACOSX_CODESIGNING_IDENTITY" "$scriptorexecutable" >> "/tmp/codesign_${fn}.log" 2>&1
107 codesign
--verbose --force --identifier=$id --sign "$MACOSX_CODESIGNING_IDENTITY" "$version" >> "/tmp/codesign_${fn}.log" 2>&1
108 if [ "$?" != "0" ] ; then
111 rm "/tmp/codesign_${fn}.log"
118 find "$APP_BUNDLE" -name '*.mdimporter' -type d |
119 while read bundle
; do
120 codesign
--verbose --force --prefix=$MACOSX_BUNDLE_IDENTIFIER.
--sign "$MACOSX_CODESIGNING_IDENTITY" "$bundle" > "/tmp/codesign_$(basename "${bundle}").log" 2>&1
121 if [ "$?" != "0" ] ; then
124 rm "/tmp/codesign_$(basename "${bundle}").log"
129 find "$APP_BUNDLE/Contents/MacOS" -type f |
135 id
=`echo ${file#${APP_BUNDLE}/Contents/} | sed -e 's,/,.,g'`
136 codesign
--force --verbose --options=runtime
--identifier=$MACOSX_BUNDLE_IDENTIFIER.
$id --sign "$MACOSX_CODESIGNING_IDENTITY" $entitlements "$file" > "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.${id}.log" 2>&1
137 if [ "$?" != "0" ] ; then
140 rm "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.${id}.log"
145 # Sign the app bundle as a whole which means (re-)signing the
146 # CFBundleExecutable from Info.plist, i.e. soffice, plus the contents
147 # of the Resources tree (which unless you used
148 # --enable-canonical-installation-tree-structure is not much, far from
149 # all of our non-code "resources").
151 # At this stage we also attach the entitlements in the sandboxing case
153 # Also omit some files from the Bundle's seal via the resource-rules
154 # (bootstraprc and similar that the user might adjust and image files)
155 # See also https://developer.apple.com/library/mac/technotes/tn2206/
157 id
=`echo ${PRODUCTNAME} | tr ' ' '-'`
159 codesign
--force --verbose --options=runtime
--identifier="${MACOSX_BUNDLE_IDENTIFIER}" --sign "$MACOSX_CODESIGNING_IDENTITY" $entitlements "$APP_BUNDLE" > "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.log" 2>&1
160 if [ "$?" != "0" ] ; then
163 rm "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.log"