macOS: Remove BGHUDAppKit in build scripts
[vlc.git] / extras / package / macosx / codesign.sh
1 #!/bin/bash
2 # Copyright (C) 2012-2014 Felix Paul K├╝hne <fkuehne at videolan dot org>
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU Lesser General Public License as published by
6 # the Free Software Foundation; either version 2.1 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17
18 set -e
19
20 info()
21 {
22     green='\x1B[1;32m'
23     normal='\x1B[0m'
24     echo -e "[${green}codesign${normal}] $1"
25 }
26
27 usage()
28 {
29 cat << EOF
30 usage: $0 [options]
31
32 Sign VLC.app in the current directory
33
34 OPTIONS:
35    -h            Show this help
36    -i            Identity to use
37    -t            Entitlements file to use
38    -g            Enable additional magic
39 EOF
40
41 }
42
43 while getopts "hi:t:g" OPTION
44 do
45      case $OPTION in
46          h)
47              usage
48              exit 1
49          ;;
50          i)
51              IDENTITY=$OPTARG
52          ;;
53          t)
54              OPTIONS="--entitlements $OPTARG"
55          ;;
56          g)
57              GK="yes"
58          ;;
59      esac
60 done
61 shift $(($OPTIND - 1))
62
63 if [ "x$1" != "x" ]; then
64     usage
65     exit 1
66 fi
67
68 if test -z "$GK"
69 then
70
71     info "Signing frameworks"
72     find VLC.app/Contents/Frameworks/* -type f -exec codesign --force -s "$IDENTITY" $OPTIONS '{}' \;
73
74     info "Signing the executable"
75     codesign --force -s "$IDENTITY" $OPTIONS VLC.app/Contents/MacOS/VLC
76
77     info "Signing the modules"
78     find VLC.app/Contents/MacOS/plugins/* -type f -exec codesign --force -s "$IDENTITY" $OPTIONS '{}' \;
79
80     info "Signing the libraries"
81     find VLC.app/Contents/MacOS/lib/* -type f -exec codesign --force -s "$IDENTITY" $OPTIONS '{}' \;
82
83     info "Signing the lua stuff"
84     find VLC.app/Contents/MacOS/share/lua/* -name *luac -type f -exec codesign --force -s "$IDENTITY" $OPTIONS '{}' \;
85 else
86     FIRSTPARTOF_REQUIREMENT="=designated => anchor apple generic  and identifier \""
87     SECONDPARTOF_REQUIREMENT="\" and ((cert leaf[field.1.2.840.113635.100.6.1.9] exists) or ( certificate 1[field.1.2.840.113635.100.6.2.6] exists and certificate leaf[field.1.2.840.113635.100.6.1.13] exists  and certificate leaf[subject.OU] = \"75GAHG3SZQ\" ))"
88
89     info "Cleaning frameworks"
90     find VLC.app/Contents/Frameworks -type f -name ".DS_Store" -exec rm '{}' \;
91     find VLC.app/Contents/Frameworks -type f -name "*.textile" -exec rm '{}' \;
92     find VLC.app/Contents/Frameworks -type f -name "*.txt" -exec rm '{}' \;
93
94     info "Signing frameworks"
95     IDENTIFIER="com.growl.growlframework"
96     codesign --force --verbose -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$IDENTIFIER$SECONDPARTOF_REQUIREMENT" --timestamp=none VLC.app/Contents/Frameworks/Growl.framework/Versions/A
97     IDENTIFIER="org.sparkle-project.Sparkle.Autoupdate"
98     codesign --force --verbose -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$IDENTIFIER$SECONDPARTOF_REQUIREMENT" --timestamp=none VLC.app/Contents/Frameworks/Sparkle.framework/Resources/Autoupdate.app
99     IDENTIFIER="org.sparkle-project.Sparkle"
100     codesign --force --verbose -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$IDENTIFIER$SECONDPARTOF_REQUIREMENT" --timestamp=none VLC.app/Contents/Frameworks/Sparkle.framework/Versions/A
101
102     info "Signing the framework headers"
103     for i in `find VLC.app/Contents/Frameworks/* -type f -name "*.h" -exec echo {} \;`
104     do
105         fbname=$(basename "$i")
106         filename="${fbname%.*}"
107
108         codesign --force -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$filename$SECONDPARTOF_REQUIREMENT" --timestamp=none $i
109     done
110
111     info "Signing the framework strings"
112     for i in `find VLC.app/Contents/Frameworks/* -type f -name "*.strings" -exec echo {} \;`
113     do
114         fbname=$(basename "$i")
115         filename="${fbname%.*}"
116
117         codesign --force -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$filename$SECONDPARTOF_REQUIREMENT" --timestamp=none $i
118     done
119
120     info "Signing the framework plist files"
121     for i in `find VLC.app/Contents/Frameworks/* -type f -name "*.plist" -exec echo {} \;`
122     do
123         fbname=$(basename "$i")
124         filename="${fbname%.*}"
125
126         codesign --force -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$filename$SECONDPARTOF_REQUIREMENT" --timestamp=none $i
127     done
128
129     info "Signing the framework nib files"
130     for i in `find VLC.app/Contents/Frameworks/* -type f -name "*.nib" -exec echo {} \;`
131     do
132         fbname=$(basename "$i")
133         filename="${fbname%.*}"
134
135         codesign --force -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$filename$SECONDPARTOF_REQUIREMENT" --timestamp=none $i
136     done
137
138     info "Signing the headers"
139     for i in `find VLC.app/Contents/MacOS/include/* -type f -exec echo {} \;`
140     do
141         fbname=$(basename "$i")
142         filename="${fbname%.*}"
143
144         codesign --force -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$filename$SECONDPARTOF_REQUIREMENT" --timestamp=none $i
145     done
146
147     info "Signing the modules"
148
149     for i in `find VLC.app/Contents/MacOS/plugins/* -type f -exec echo {} \;`
150     do
151         fbname=$(basename "$i")
152         filename="${fbname%.*}"
153
154         codesign --force -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$filename$SECONDPARTOF_REQUIREMENT" --timestamp=none $i
155     done
156
157     info "Signing the libraries"
158
159     for i in `find VLC.app/Contents/MacOS/lib/* -type f -exec echo {} \;`
160     do
161         fbname=$(basename "$i")
162         filename="${fbname%.*}"
163
164         codesign --force -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$filename$SECONDPARTOF_REQUIREMENT" --timestamp=none $i
165     done
166
167     info "Signing share"
168
169     for i in `find VLC.app/Contents/MacOS/share/* -type f -exec echo {} \;`
170     do
171         fbname=$(basename "$i")
172         filename="${fbname%.*}"
173
174         codesign --force -s "$IDENTITY" --preserve-metadata=identifier,entitlements --requirements "$FIRSTPARTOF_REQUIREMENT$filename$SECONDPARTOF_REQUIREMENT" --timestamp=none $i
175     done
176
177     info "Signing the executable"
178     IDENTIFIER="org.videolan.vlc"
179     codesign --force -s "$IDENTITY" --requirements "$FIRSTPARTOF_REQUIREMENT$IDENTIFIER$SECONDPARTOF_REQUIREMENT" --timestamp=none VLC.app/Contents/MacOS/VLC
180 fi
181
182 info "all items signed, validating..."
183
184 info "Validating frameworks"
185 codesign --verify -vv VLC.app/Contents/Frameworks/Growl.framework
186 codesign --verify -vv VLC.app/Contents/Frameworks/Sparkle.framework
187
188 info "Validating autoupdate app"
189 codesign --verify -vv VLC.app/Contents/Frameworks/Sparkle.framework/Versions/Current/Resources/Autoupdate.app
190
191 info "Validating complete bundle"
192 codesign --verify --deep --verbose=4 VLC.app
193
194
195 info "Validation complete"