bin/createpackage.pl
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    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:
    99         .\\cert\\mycert.cer;.\\cert\\mykey.key;yourpassword
   101         .\\cert\\mycert.cer;.\\cert\\mykey.key;yourpassword
   100         X:\\QtS60\\s60installs\\selfsigned.cer;X:\\QtS60\\s60installs\\selfsigned.key
   102         X:\\QtS60\\s60installs\\selfsigned.cer;X:\\QtS60\\s60installs\\selfsigned.key
   101 
   103 
   102 If no certificate and key files are provided, either a RnD certificate or
   104 If no certificate and key files are provided, either a RnD certificate or
   103 a self-signed certificate from QtDir\\src\\s60installs directory is used.
   105 a self-signed certificate from QtDir\\src\\s60installs directory is used.
       
   106 In the latter case the resulting package will also be automatically patched
       
   107 using patch_capabilities.pl script, which makes it unsuitable for distribution.
       
   108 Always specify certificates explicitly if you wish to distribute your package.
       
   109 
   104 ==============================================================================================
   110 ==============================================================================================
   105 
   111 
   106 ENDUSAGESTRING
   112 ENDUSAGESTRING
   107 
   113 
   108     exit();
   114     exit();
   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 _ ) {
   195         Usage();
   209         Usage();
   196     }
   210     }
   197 } else {
   211 } else {
   198     #If no certificate is given, check default options
   212     #If no certificate is given, check default options
   199     $certtext = "RnD";
   213     $certtext = "RnD";
   200     $certificate = $certpath."rd.cer";
   214     $certificate = File::Spec->catfile($certpath, "rd.cer");
   201     $key = $certpath."rd-key.pem";
   215     $key = File::Spec->catfile($certpath, "rd-key.pem");
   202 
   216 
   203     stat($certificate);
   217     stat($certificate);
   204     unless( -e _ ) {
   218     unless( -e _ ) {
   205         $certtext = "Self Signed";
   219         $certtext = "Self Signed";
   206         $certificate = $certpath."selfsigned.cer";
   220         $certificate = File::Spec->catfile($certpath, "selfsigned.cer");
   207         $key = $certpath."selfsigned.key";
   221         $key = File::Spec->catfile($certpath, "selfsigned.key");
   208     }
   222     }
   209 }
   223 }
   210 
   224 
   211 # Read the certificates from file to two dimensional array
   225 # Read the certificates from file to two dimensional array
   212 my @certificates;
   226 my @certificates;
   240 if (!$preservePkgOutput) {
   254 if (!$preservePkgOutput) {
   241     unlink $pkgoutput;
   255     unlink $pkgoutput;
   242 }
   256 }
   243 
   257 
   244 # Preprocess PKG
   258 # Preprocess PKG
       
   259 
   245 local $/;
   260 local $/;
   246 # read template file
   261 # read template file
   247 open( TEMPLATE, $templatepkg) or die "Error '$templatepkg': $!\n";
   262 open( TEMPLATE, $templatepkg) or die "Error '$templatepkg': $!\n";
   248 $_=<TEMPLATE>;
   263 $_=<TEMPLATE>;
   249 close (TEMPLATE);
   264 close (TEMPLATE);
       
   265 
       
   266 # If the pkg file does not contain macros, there is no need for platform or target.
       
   267 if (m/\$\(PLATFORM\)/) {
       
   268     unless (length($platform) && length($target)) {
       
   269         print "\nError: Platform or target is not defined!\n";
       
   270         Usage();
       
   271     }
       
   272 }
   250 
   273 
   251 # replace the PKG variables
   274 # replace the PKG variables
   252 s/\$\(PLATFORM\)/$platform/gm;
   275 s/\$\(PLATFORM\)/$platform/gm;
   253 s/\$\(TARGET\)/$target/gm;
   276 s/\$\(TARGET\)/$target/gm;
   254 
   277 
   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) {