66 ============================================================================================== |
66 ============================================================================================== |
67 Convenience script for creating signed packages you can install on your phone. |
67 Convenience script for creating signed packages you can install on your phone. |
68 |
68 |
69 Usage: createpackage.pl [options] templatepkg [target]-[platform] [certificate key [passphrase]] |
69 Usage: createpackage.pl [options] templatepkg [target]-[platform] [certificate key [passphrase]] |
70 |
70 |
71 Where supported optiobns are as follows: |
71 Where supported options are as follows: |
72 [-i|install] = Install the package right away using PC suite |
72 [-i|install] = Install the package right away using PC suite. |
73 [-p|preprocess] = Only preprocess the template .pkg file. |
73 [-p|preprocess] = Only preprocess the template .pkg file. |
74 [-c|certfile=<file>] = The file containing certificate information for signing. |
74 [-c|certfile <file>] = The file containing certificate information for signing. |
75 The file can have several certificates, each specified in |
75 The file can have several certificates, each specified in |
76 separate line. The certificate, key and passphrase in line |
76 separate line. The certificate, key and passphrase in line |
77 must be ';' separated. Lines starting with '#' are treated |
77 must be ';' separated. Lines starting with '#' are treated |
78 as a comments. Also empty lines are ignored. The paths in |
78 as a comments. Also empty lines are ignored. The paths in |
79 <file> can be absolute or relative to <file>. |
79 <file> can be absolute or relative to <file>. |
80 [-u|unsigned] = Preserves the unsigned package |
80 [-u|unsigned] = Preserves the unsigned package. |
|
81 [-s|stub] = Generates stub sis for ROM. |
|
82 [-n|sisname <name>] = Specifies the final sis name. |
81 Where parameters are as follows: |
83 Where parameters are as follows: |
82 templatepkg = Name of .pkg file template |
84 templatepkg = Name of .pkg file template |
83 target = Either debug or release |
85 target = Either debug or release |
84 platform = One of the supported platform |
86 platform = One of the supported platform |
85 winscw | gcce | armv5 | armv6 | armv7 |
87 winscw | gcce | armv5 | armv6 | armv7 |
86 certificate = The certificate file used for signing |
88 certificate = The certificate file used for signing |
87 key = The certificate's private key file |
89 key = The certificate's private key file |
88 passphrase = The certificate's private key file's passphrase |
90 passphrase = The passphrase of the certificate's private key file |
89 |
91 |
90 Example: |
92 Example: |
91 createpackage.pl fluidlauncher_template.pkg release-armv5 |
93 createpackage.pl fluidlauncher_template.pkg release-armv5 |
92 |
94 |
93 Example with certfile: |
95 Example with certfile: |
112 my $install = ""; |
118 my $install = ""; |
113 my $preprocessonly = ""; |
119 my $preprocessonly = ""; |
114 my $certfile = ""; |
120 my $certfile = ""; |
115 my $preserveUnsigned = ""; |
121 my $preserveUnsigned = ""; |
116 my $stub = ""; |
122 my $stub = ""; |
|
123 my $signed_sis_name = ""; |
117 |
124 |
118 unless (GetOptions('i|install' => \$install, |
125 unless (GetOptions('i|install' => \$install, |
119 'p|preprocess' => \$preprocessonly, |
126 'p|preprocess' => \$preprocessonly, |
120 'c|certfile=s' => \$certfile, |
127 'c|certfile=s' => \$certfile, |
121 'u|unsigned' => \$preserveUnsigned, |
128 'u|unsigned' => \$preserveUnsigned, |
122 's|stub' => \$stub,)){ |
129 's|stub' => \$stub, |
|
130 'n|sisname=s' => \$signed_sis_name,)) { |
123 Usage(); |
131 Usage(); |
124 } |
132 } |
125 |
133 |
126 my $certfilepath = abs_path(dirname($certfile)); |
134 my $certfilepath = abs_path(dirname($certfile)); |
127 |
135 |
128 # Read params to variables |
136 # Read params to variables |
129 my $templatepkg = $ARGV[0]; |
137 my $templatepkg = $ARGV[0]; |
130 my $targetplatform = lc $ARGV[1]; |
138 my $targetplatform = lc $ARGV[1]; |
131 |
139 |
132 my @tmpvalues = split('-', $targetplatform); |
140 my @tmpvalues = split('-', $targetplatform); |
133 my $target = $tmpvalues[0]; |
141 my $target; |
134 my $platform = $tmpvalues[1];; |
142 $target = $tmpvalues[0] or $target = ""; |
|
143 my $platform; |
|
144 $platform = $tmpvalues[1] or $platform = ""; |
135 |
145 |
136 # Convert visual target to real target (debug->udeb and release->urel) |
146 # Convert visual target to real target (debug->udeb and release->urel) |
137 $target =~ s/debug/udeb/i; |
147 $target =~ s/debug/udeb/i; |
138 $target =~ s/release/urel/i; |
148 $target =~ s/release/urel/i; |
139 |
149 |
140 my $certificate = $ARGV[2]; |
150 my $certificate; |
141 my $key = $ARGV[3]; |
151 $certificate = $ARGV[2] or $certificate = ""; |
142 my $passphrase = $ARGV[4]; |
152 my $key; |
|
153 $key = $ARGV[3] or $key = ""; |
|
154 my $passphrase; |
|
155 $passphrase = $ARGV[4] or $passphrase = ""; |
143 |
156 |
144 # Generate output pkg basename (i.e. file name without extension) |
157 # Generate output pkg basename (i.e. file name without extension) |
145 my $pkgoutputbasename = $templatepkg; |
158 my $pkgoutputbasename = $templatepkg; |
146 my $preservePkgOutput = ""; |
159 my $preservePkgOutput = ""; |
147 $pkgoutputbasename =~ s/_template/_$targetplatform/g; |
160 $pkgoutputbasename =~ s/_template/_$targetplatform/g; |
148 if ($pkgoutputbasename eq $templatepkg) { |
161 if ($pkgoutputbasename eq $templatepkg) { |
149 $preservePkgOutput = "1"; |
162 $preservePkgOutput = "1"; |
150 } |
163 } |
151 $pkgoutputbasename =~ s/\.pkg//g; |
164 $pkgoutputbasename =~ s/\.pkg//g; |
152 $pkgoutputbasename = lc($pkgoutputbasename); |
165 $pkgoutputbasename = $pkgoutputbasename; |
153 |
166 |
154 # Store output file names to variables |
167 # Store output file names to variables |
155 my $pkgoutput = lc($pkgoutputbasename.".pkg"); |
168 my $pkgoutput = $pkgoutputbasename.".pkg"; |
156 my $sisoutputbasename = lc($pkgoutputbasename); |
169 my $sisoutputbasename; |
157 $sisoutputbasename =~ s/_$targetplatform//g; |
170 if ($signed_sis_name eq "") { |
|
171 $sisoutputbasename = $pkgoutputbasename; |
|
172 $sisoutputbasename =~ s/_$targetplatform//g; |
|
173 $signed_sis_name = $sisoutputbasename.".sis"; |
|
174 } else { |
|
175 $sisoutputbasename = $signed_sis_name; |
|
176 if ($sisoutputbasename =~ m/(\.sis$|\.sisx$)/i) { |
|
177 $sisoutputbasename =~ s/$1//i; |
|
178 } else { |
|
179 $signed_sis_name = $signed_sis_name.".sis"; |
|
180 } |
|
181 } |
|
182 |
158 my $unsigned_sis_name = $sisoutputbasename."_unsigned.sis"; |
183 my $unsigned_sis_name = $sisoutputbasename."_unsigned.sis"; |
159 my $signed_sis_name = $sisoutputbasename.".sis"; |
184 my $stub_sis_name = $sisoutputbasename.".sis"; |
160 my $stub_sis_name = $sisoutputbasename."_stub.sis"; |
|
161 |
185 |
162 # Store some utility variables |
186 # Store some utility variables |
163 my $scriptpath = dirname(__FILE__); |
187 my $scriptpath = dirname(__FILE__); |
164 my $certtext = $certificate; |
188 my $certtext = $certificate; |
165 my $certpath = $scriptpath; |
189 # certificates are one step up in hierarchy |
166 $certpath =~ s-^(.*[^\\])$-$1\\-o; # ensure path ends with a backslash |
190 my $certpath = File::Spec->catdir($scriptpath, File::Spec->updir(), "src/s60installs/"); |
167 $certpath =~ s-/-\\-go; # for those working with UNIX shells |
|
168 $certpath =~ s-bin\\$-src\\s60installs\\-; # certificates are one step up in hierarcy |
|
169 |
191 |
170 # Check some pre-conditions and print error messages if needed. |
192 # Check some pre-conditions and print error messages if needed. |
171 unless (length($templatepkg)) { |
193 unless (length($templatepkg)) { |
172 print "\nError: Template PKG filename is not defined!\n"; |
194 print "\nError: Template PKG filename is not defined!\n"; |
173 Usage(); |
195 Usage(); |
174 } |
|
175 |
|
176 # If the pkg file is not actually a template, there is no need for plaform or target. |
|
177 if ($templatepkg =~ m/_template\.pkg/i) { |
|
178 unless (length($platform) && length($target)) { |
|
179 print "\nError: Platform or target is not defined!\n"; |
|
180 Usage(); |
|
181 } |
|
182 } |
196 } |
183 |
197 |
184 # Check template exist |
198 # Check template exist |
185 stat($templatepkg); |
199 stat($templatepkg); |
186 unless( -e _ ) { |
200 unless( -e _ ) { |
267 mkpath($systeminstall); |
290 mkpath($systeminstall); |
268 my $stub_sis_name = $systeminstall."/".$stub_sis_name; |
291 my $stub_sis_name = $systeminstall."/".$stub_sis_name; |
269 # Create stub SIS. |
292 # Create stub SIS. |
270 system ("makesis -s $pkgoutput $stub_sis_name"); |
293 system ("makesis -s $pkgoutput $stub_sis_name"); |
271 } else { |
294 } else { |
|
295 if ($certtext eq "Self Signed" && !@certificates && $templatepkg !~ m/_installer\.pkg$/i) { |
|
296 print("Auto-patching capabilities for self signed package.\n"); |
|
297 system ("patch_capabilities $pkgoutput"); |
|
298 } |
|
299 |
272 # Create SIS. |
300 # Create SIS. |
273 system ("makesis $pkgoutput $unsigned_sis_name"); |
301 # The 'and' is because system uses 0 to indicate success. |
|
302 system ("makesis $pkgoutput $unsigned_sis_name") and die ("makesis failed"); |
274 print("\n"); |
303 print("\n"); |
275 |
304 |
276 # Sign SIS with certificate info given as an argument. |
305 # Sign SIS with certificate info given as an argument. |
277 system ("signsis $unsigned_sis_name $signed_sis_name $certificate $key $passphrase"); |
306 my $relcert = File::Spec->abs2rel($certificate); |
|
307 my $relkey = File::Spec->abs2rel($key); |
|
308 # The 'and' is because system uses 0 to indicate success. |
|
309 system ("signsis $unsigned_sis_name $signed_sis_name $relcert $relkey $passphrase") and die ("signsis failed"); |
278 |
310 |
279 # Check if creating signed SIS Succeeded |
311 # Check if creating signed SIS Succeeded |
280 stat($signed_sis_name); |
312 stat($signed_sis_name); |
281 if( -e _ ) { |
313 if( -e _ ) { |
282 my $targetInsert = ""; |
314 my $targetInsert = ""; |
286 print ("Successfully created $signed_sis_name ${targetInsert}using certificate: $certtext!\n"); |
318 print ("Successfully created $signed_sis_name ${targetInsert}using certificate: $certtext!\n"); |
287 |
319 |
288 # Sign with additional certificates & keys |
320 # Sign with additional certificates & keys |
289 for my $row ( @certificates ) { |
321 for my $row ( @certificates ) { |
290 # Get certificate absolute file names, relative paths are relative to certfilepath |
322 # Get certificate absolute file names, relative paths are relative to certfilepath |
291 my $abscert = File::Spec->rel2abs( $row->[0], $certfilepath); |
323 my $relcert = File::Spec->abs2rel(File::Spec->rel2abs( $row->[0], $certfilepath)); |
292 my $abskey = File::Spec->rel2abs( $row->[1], $certfilepath); |
324 my $relkey = File::Spec->abs2rel(File::Spec->rel2abs( $row->[1], $certfilepath)); |
293 |
325 |
294 system ("signsis $signed_sis_name $signed_sis_name $abscert $abskey $row->[2]"); |
326 system ("signsis $signed_sis_name $signed_sis_name $relcert $relkey $row->[2]"); |
295 print ("\tAdditionally signed the SIS with certificate: $row->[0]!\n"); |
327 print ("\tAdditionally signed the SIS with certificate: $row->[0]!\n"); |
296 } |
328 } |
297 |
329 |
298 # remove temporary pkg and unsigned sis |
330 # remove temporary pkg and unsigned sis |
299 if (!$preservePkgOutput) { |
331 if (!$preservePkgOutput) { |