nss: upgrade to release 3.73
[LibreOffice.git] / solenv / bin / macosx-codesign-app-bundle
blob8aa72574532751fe356879ad15651e72b52081ef
1 #!/bin/bash
3 # Exit on errors
4 set -e
5 # Use of unset variable is an error
6 set -u
7 # If any part of a pipeline of commands fails, the whole pipeline fails
8 set -o pipefail
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; }
18 for V in \
19 BUILDDIR \
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"
24 exit 1
26 done
28 APP_BUNDLE="$1"
29 entitlements=
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.
35 other_files=''
36 else
37 # We then want to sign data files, too, hmm.
38 entitlements="--entitlements $BUILDDIR/hardened_runtime.xcent"
39 other_files="\
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 |
48 while read file; do
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
52 exit 1
54 rm "/tmp/codesign_$(basename "$file").log"
55 done
57 # Sign dylibs
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 |
67 while read file; do
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
71 exit 1
73 rm "/tmp/codesign_$(basename "$file").log"
74 done
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 |
80 while read app; do
81 fn=`basename "$app"`
82 fn=${fn%.*}
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
87 exit 1
89 rm "/tmp/codesign_${fn}.log"
90 done
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"`
97 fn=${fn%.*}
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
106 done
108 codesign --verbose --force --identifier=$id --sign "$MACOSX_CODESIGNING_IDENTITY" "$version" >> "/tmp/codesign_${fn}.log" 2>&1
109 if [ "$?" != "0" ] ; then
110 exit 1
112 rm "/tmp/codesign_${fn}.log"
114 done
115 done
117 # Then mdimporters
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
123 exit 1
125 rm "/tmp/codesign_$(basename "${bundle}").log"
126 done
128 # Sign executables
130 find "$APP_BUNDLE/Contents/MacOS" -type f |
131 while read file; do
132 case "$file" in
133 */soffice)
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
139 exit 1
141 rm "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.${id}.log"
143 esac
144 done
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
160 exit 1
162 rm "/tmp/codesign_${MACOSX_BUNDLE_IDENTIFIER}.log"
163 exit 0