How can I sign the files using NSIS? - nsis

How can I sign the files using NSIS?
We changed WIX installer to NSIS.
Earlier in the WIX installer it was used like as shown below in the .xml file to sign the files.
<property name="FileSigningDrive" location="${env.FILE_SIGNING}"/>
<!--echo message="Signing Setup.exe ....." />
<exec dir="${FileSigningDrive}\"
executable="${FileSigningDrive}\signcode.exe" failonerror="true">
<arg value='-spc' />
<arg value='mycredentials.spc' />
<arg value='-v' />
<arg value='testkey.pvk' />
<arg value='-t' />
<arg value='http://timestamp.verisign.com/scripts/timpstamp.dll' />
<arg value='"${install}\RootCDDir\setup.exe"' />
</exec-->
Similarly, how to sign the files in NSIS?

You can sign the installer by executing a command of your choice with !finalize:
!finalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the install exe to be signed.
Signing the uninstaller is a bit annoying and requires you to generate the uninstaller and then signing it.

This is an update to #Anders answer.
From v3.08, you can straight away use !uninstfinalize to sign the uninstaller.
So now you can write your code like this.
!finalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the install exe to be signed.
!uninstfinalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the uninstaller exe to be signed.
Keep in mind that you must append = 0 at !finalize and !uninstfinalize. That will stop running both in parallel. Otherwise, the signtool.exe will fail because it can't run in parallel.

Related

Optional spaces between multiple layout renderers?

I think I must be missing something extremely obvious here but furious doc reading and googling has failed me. I have the following layout for a file name:
<target name="asyncLogFile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard" >
<target name="mainLogFile" xsi:type="File" fileName="logs/${mdlc:item=GameServer:whenEmpty=Main} ${mdlc:item=Controller}.log"
layout="${longdate} ${level:uppercase=true} | ${logger} | ${message} ${exception:format=toString,Data:maxInnerExceptionLevel=3}" />
</target>
The MDLC items can both be null, in the games of the GameServer it gets replaced with "Main" and the Controller doesn't matter (If the GameServer is null then the Controller will be null).
However this means that if GameServer is null I end up with
Main .log Because of the space I have between the two mdlc entries. How can I make that space optional as part of the GameServer mldc entry!? I have looked at :pad to add a space after the but that doesn't seem to work. I have tried concatenating the mdlc's but that doesn't work.
I was expecting something simple you could add as an ambient property like :suffix but nothing like that exists.
Again I think I must be missing something basic here but it eludes me.
Same ugly, but faster because of less allocation:
<variable name="GameServerLogFile" value="${when:when='${mdlc:item=GameServer}'=='':inner=Main:else=${mdlc:item=GameServer} ${mdlc:item=Controller}}" />
<targets>
<target name="mainLogFile" xsi:type="File" fileName="logs/${GameServerLogFile}.log" />
</targets>
Better to compare against empty-string '', than to call length()-method.
Ugly but this works
<target name="mainLogFile" xsi:type="File" fileName="logs/${when:when=length('${mdlc:item=GameServer}') > 0:inner=${mdlc:item=GameServer} ${mdlc:item=Controller}:else=Main}.log"

shell script sed replace

I have this file config.xml
<widget id="com.example.hello" version="0.0.1">
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#callback.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<enter>PASSWORD</enter>
<content src="index.html" />
<access origin="*" />
I tried to do it with sed without success.
I need to do this:
$./script.sh config.xml NEWPASSWORD
to get:
<widget id="com.example.hello" version="0.0.1">
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#callback.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<enter>NEWPASSWORD</enter>
<content src="index.html" />
<access origin="*" />
Using backreference:
sed "s/^\( *<enter>\)\([^>]*\)</\1$2</" "$1"
^\( *<enter>\): search for lines starting with any number of spaces followed by <enter>. Matching characters are captured with escaped parentheses.
\([^>]*\)<: following characters up top next < are captured in a second group.
\1$2<: in the substitution string, characters from first group are output(\1) followed by the second parameter value passed to the script, ($2, the new password value)
The command is applied to $1, the file passed as first parameter to the script (the file name).
To edit the file in place, use the -i flag:
sed -i "s/^\( *<enter>\)\([^>]*\)</\1$2</" "$1"
The good result is:
$cat script.sh
#!/bin/sh
file=$1
sed -i "s/^\( *<enter>\)\([^>]*\)</\1$2</" "$1"
Then:
$./script.sh config.xml NEWPASSWORD
Many thanks to everyone, especially to Kenavoz.

Can not run ' Ant exec executable="zip" '

Below is my ant script.
<exec executable="zip" dir="/usr/local/clo/ven/image/manual_bundle/testzip/">
<arg value="-y"/>
<arg value="-r"/>
<arg value="${file.path}"/>
<arg value="*"/>
</exec>
But below error occur.
zip-image_binary:
[exec] zip warning: name not matched: *
[exec]
[exec] zip error: Nothing to do! (try: zip -y -r /usr/local/clo/ven/image/a.zip . -i *)
[exec] Result: 12
My purpose is to zip all the files and directories under /usr/local/clo/ven/image/manual_bundle/testzip/
When you run the command using your shell then the shell expands the * glob pattern. The zip executable doesn't expect any pattern at all but a list of files (usually provided by your shell). If you don't want to use the built-in zip task you can emulate that behaviour by using apply rather than exec. Something like this
<apply executable="zip" parallel="true" relative="true"
dir="/usr/local/clo/ven/image/manual_bundle/testzip/">
<fileset dir="/usr/local/clo/ven/image/manual_bundle/testzip/"/>
<mergemapper to="${file.path}"/>
<arg value="-y"/>
<arg value="-r"/>
<targetfile/>
</apply>
The equivalent zip task is a lot simpler
<zip destfile="${file.path}">
<fileset dir="/usr/local/clo/ven/image/manual_bundle/testzip/"/>
</zip>

Trouble with quotes in ant's <exec>

This is the command that runs just fine on terminal
egrep Version ./path/fileName.java | cut -d"\"" -f4
I've used the following in my code
<exec command="egrep Version ./path/fileName.java | cut -d"\" -f4)" outputproperty="VER"/>
But getting errors
the command attribute is deprecated.
[exec] Please use the executable attribute and nested arg elements.
[exec] Result: 1
[echo] "Version: egrep: invalid argument `\\' for `--directories'
[echo] Valid arguments are:
[echo] - `read'
[echo] - `recurse'
[echo] - `skip'
[echo] Usage: egrep [OPTION]... PATTERN [FILE]...
[echo] Try `egrep --help' for more information."
there is one less quot; in the command because if I write 2 quots, it will give me number of quots unbalanced error.
Ant's <exec> uses Java's rules for execution, in particular it is not a shell and does not understand pipes and redirections on its own. Probably your best bet will be to invoke a shell. You will also need to capture the output in a property if you want to make use of it later in your build:
<exec executable="sh" outputproperty="version.number">
<arg value="-c" />
<arg value="egrep Version ./path/fileName.java | cut -d'"' -f4" />
</exec>
Alternatively, you could forget the exec and implement the required logic directly in Ant using loadfile with a filterchain rather than calling an external process:
<loadfile srcFile="path/fileName.java" property="version.number"
encoding="UTF-8">
<filterchain>
<tokenfilter>
<!-- equivalent of egrep Version -->
<containsregex pattern="Version" />
<!-- equivalent of the cut - extract the bit between the third and
fourth double quote marks -->
<containsregex pattern='^[^"]*"[^"]*"[^"]*"([^"]*)".*$$'
replace="\1" />
</tokenfilter>
<!-- I'm guessing you don't want a trailing newline on your version num -->
<striplinebreaks />
</filterchain>
</loadfile>
Try using ' in your xml
<exec command='egrep Version ./path/fileName.java | cut -d"\"" -f4)' outputproperty="VER"/>

CruiseControl.NET and Mounting a Drive

I am running CruiseControl.NET as a service but some of the projects that I am building reference things using a network drive. As In H:... instead of \machine\dir. I can't change the project references. How can I mount the H: drive before the project builds or maybe when CruiseControl starts running?
From a command line, you can call "net use" to set up a mapped drive. You might be able to run this from an exec task before the code is compiled.
I've tested the following .bat file and it worked fine using:
- CruiseControl.Net version 1.5.7256.1
- a .bat file running from an <exec> task.
.bat file
ECHO OFF
NET USE \\Server\data /USER:domain\user password
ECHO ON
C:\utils\robocopy.exe C:\build\data \\Server\data *.*
ccnet.config
<project name="ProjectName">
<!-- snip -->
<tasks>
<!-- snip -->
<exec>
<executable>deploy.bat</executable>
<baseDirectory>Configuration\</baseDirectory>
<buildArgs></buildArgs>
<buildTimeoutSeconds>60</buildTimeoutSeconds>
<successExitCodes>0,1,2,3,4,5,6,7,8</successExitCodes>
</exec>
Notes:
I installed the Cruise Control service using default settings and accounts.
I turn echo off and then on, to prevent user details from being put into build logs.
I got the hint to not use drive letters from this:
Mapping a network drive without hardcoding a drive letter in a batch file
Update: Included ccnet.config syntax
in my ccnet.config:
<exec>
<executable>setup_build.cmd</executable>
<baseDirectory>&BaseDIR;\CruiseControlNET</baseDirectory>
<buildArgs>&BaseDIR;\AllProjectsTFS</buildArgs>
<buildTimeoutSeconds>&BuildTimeoutInSeconds;</buildTimeoutSeconds>
</exec>
And I checked setup_build.cmd under my CruiseControlNet directory in SVN (setup as described in: http://confluence.public.thoughtworks.org/display/CCNET/Configure+CruiseControl.Net+to+Automatically+Update+its+Config+File)
setup_build.cmd contains:
#ECHO OFF
:CHECK_PARAMETERS
IF "%1"=="" GOTO SYNTAX
:PRINT_PARAMETERS
SET BASE_DIRECTORY=%1
ECHO PARAMETERS:
ECHO BaseDirectory: %BASE_DIRECTORY%
ECHO.
:ARTIFACTS_DIRECTORY
ECHO CREATING ARTIFACTS DIRECTORY:
SET ARTIFACTS_DIR=%BASE_DIRECTORY%\Artifacts
ECHO Creating Artifacts Directory in: %ARTIFACTS_DIR%
IF EXIST %ARTIFACTS_DIR% RMDIR /S /Q %ARTIFACTS_DIR%
MKDIR %ARTIFACTS_DIR%
ECHO SUCCESS
ECHO.
:SETUP_NETWORK_DRIVES
ECHO MAPPING NETWORK DRIVES:
IF NOT EXIST H: NET USE H: \\server\share
NET USE
GOTO END
:SYNTAX
ECHO Wrong Arguments:
ECHO SYNTAX: setup_build.cmd [BASE_DIRECTORY]
EXIT /B -1
:END
EXIT /B 0

Resources