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 # All data files are in Resources and included in the app bundle signature
34 # through that. I think.
37 # We then want to sign data files, too, hmm.
38 entitlements
="--entitlements $BUILDDIR/hardened_runtime.xcent"
40 -or -name '*.fodt' -or -name 'schema.strings' -or -name 'schema.xml' \
41 -or -name '*.jar' -or -name 'LICENSE' -or -name 'LICENSE.html' \
42 -or -name '*.applescript' -or -name '*.odt'"
45 # Sign jnilibs first as workaround for signing issue on old baseline
46 # order matters/screws things up otherwise
47 find -d "$APP_BUNDLE" \
( -name '*.jnilib' \
) ! -type l |
49 id
=`echo ${file#${APP_BUNDLE}/Contents/} | sed -e 's,/,.,g'`
50 codesign
--verbose --force --identifier=$MACOSX_BUNDLE_IDENTIFIER.
$id --sign "$MACOSX_CODESIGNING_IDENTITY" "$file" > "/tmp/codesign_$(basename "$file").log" 2>&1
51 if [ "$?" != "0" ] ; then
54 rm "/tmp/codesign_$(basename "$file").log"
59 # The dylibs in the Python framework are called *.so. Go figure
61 # On Mavericks also would like to have data files signed...
62 # add some where it makes sense. Make a depth-first search to sign the contents
63 # of e.g. the spotlight plugin before attempting to sign the plugin itself
65 find "$APP_BUNDLE" \
( -name '*.dylib' -or -name '*.dylib.*' -or -name '*.so' \
66 $other_files \
) ! -type l |
68 id
=`echo ${file#${APP_BUNDLE}/Contents/} | sed -e 's,/,.,g'`
69 codesign
--verbose --force --identifier=$MACOSX_BUNDLE_IDENTIFIER.
$id --sign "$MACOSX_CODESIGNING_IDENTITY" "$file" > "/tmp/codesign_$(basename "$file").log" 2>&1
70 if [ "$?" != "0" ] ; then
73 rm "/tmp/codesign_$(basename "$file").log"
76 # Sign included bundles. First .app ones (i.e. the Python.app inside
77 # the LibreOfficePython.framework. Be generic for kicks...)
79 find "$APP_BUNDLE"/Contents
-name '*.app' -type d |
83 # Assume the app has a XML (and not binary) Info.plist
84 id
=`grep -A 1 '<key>CFBundleIdentifier</key>' $app/Contents/Info.plist | tail -1 | sed -e 's,.*<string>,,' -e 's,</string>.*,,'`
85 codesign
--verbose --options=runtime
--force --identifier=$id --sign "$MACOSX_CODESIGNING_IDENTITY" $entitlements "$app" > "/tmp/codesign_${fn}.log" 2>&1
86 if [ "$?" != "0" ] ; then
89 rm "/tmp/codesign_${fn}.log"
92 # Then .framework ones. Again, be generic just for kicks.
94 find "$APP_BUNDLE" -name '*.framework' -type d |
95 while read framework
; do
96 fn
=`basename "$framework"`
98 for version
in "$framework"/Versions
/*; do
99 if test ! -L "$version" -a -d "$version"; then
100 # Assume the framework has a XML (and not binary) Info.plist
101 id
=`grep -A 1 '<key>CFBundleIdentifier</key>' $version/Resources/Info.plist | tail -1 | sed -e 's,.*<string>,,' -e 's,</string>.*,,'`
102 if test -d $version/bin
; then
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
108 codesign
--verbose --force --identifier=$id --sign "$MACOSX_CODESIGNING_IDENTITY" "$version" >> "/tmp/codesign_${fn}.log" 2>&1
109 if [ "$?" != "0" ] ; then
112 rm "/tmp/codesign_${fn}.log"
119 find "$APP_BUNDLE" -name '*.mdimporter' -type d |
120 while read bundle
; do
121 codesign
--verbose --force --prefix=$MACOSX_BUNDLE_IDENTIFIER.
--sign "$MACOSX_CODESIGNING_IDENTITY" "$bundle" > "/tmp/codesign_$(basename "${bundle}").log" 2>&1
122 if [ "$?" != "0" ] ; then
125 rm "/tmp/codesign_$(basename "${bundle}").log"
130 find "$APP_BUNDLE/Contents/MacOS" -type f |
136 id
=`echo ${file#${APP_BUNDLE}/Contents/} | sed -e 's,/,.,g'`
137 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
138 if [ "$?" != "0" ] ; then
141 rm "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.${id}.log"
146 # Sign the app bundle as a whole which means (re-)signing the
147 # CFBundleExecutable from Info.plist, i.e. soffice, plus the contents
148 # of the Resources tree.
150 # At this stage we also attach the entitlements in the sandboxing case
152 # Also omit some files from the Bundle's seal via the resource-rules
153 # (bootstraprc and similar that the user might adjust and image files)
154 # See also https://developer.apple.com/library/mac/technotes/tn2206/
156 id
=`echo ${PRODUCTNAME} | tr ' ' '-'`
158 codesign
--force --verbose --options=runtime
--identifier="${MACOSX_BUNDLE_IDENTIFIER}" --sign "$MACOSX_CODESIGNING_IDENTITY" $entitlements "$APP_BUNDLE" > "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.log" 2>&1
159 if [ "$?" != "0" ] ; then
162 rm "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.log"