Skip to content

Commit

Permalink
[CMK-2245] [CMK-2230] - version and copyright is fully supported by W…
Browse files Browse the repository at this point in the history
…indows Agent

- wnx/src/common/wnx_version.h keeps raw version information from CI/release management
- wnx/src/common/version.h keeps all versions data together
- scripts updated and corrected
- version of the Windows Agent File is independent from the Version of Product

Change-Id: I8918c0e7a46e235d8435f02315e0a30281a4be02
  • Loading branch information
s-kipnis committed Jun 18, 2019
1 parent d5ebf62 commit 812799a
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 7 deletions.
18 changes: 17 additions & 1 deletion agents/wnx/build_release.cmd
Expand Up @@ -11,6 +11,12 @@ rem LOCAL_IMAGES_EXE - exe
rem LOCAL_IMAGE_PDB - pdb
rem WNX_BUILD - in the future this is name of subfloder to build out
rem creates # artefacts in the output folder
SETLOCAL EnableDelayedExpansion

rem read version from the C++ agent
set /p wnx_version_raw=<src\common\wnx_version.h
rem parse version
set wnx_version=%wnx_version_raw:~30,40%

set cur_dir=%cd%
set arte=%cur_dir%\..\..\artefacts
Expand Down Expand Up @@ -81,6 +87,17 @@ move %REMOTE_MACHINE%\check_mk_service.msi %REMOTE_MACHINE%\check_mk_agent_updat
%msbuild% wamain.sln /t:install /p:Configuration=Release,Platform=x64
if not %errorlevel% == 0 powershell Write-Host "Failed Install build" -Foreground Red && exit 8

rem set version:
rem remove quotes
echo %wnx_version:~1,-1%
rem info
powershell Write-Host "Setting Version in MSI: %wnx_version%" -Foreground Green
rem command
echo cscript.exe //nologo WiRunSQL.vbs %REMOTE_MACHINE%\check_mk_agent.msi "UPDATE `Property` SET `Property`.`Value`='%wnx_version:~1,-1%' WHERE `Property`.`Property`='ProductVersion'"
cscript.exe //nologo WiRunSQL.vbs %REMOTE_MACHINE%\check_mk_service.msi "UPDATE `Property` SET `Property`.`Value`='%wnx_version:~1,-1%' WHERE `Property`.`Property`='ProductVersion'"
rem check result
if not %errorlevel% == 0 powershell Write-Host "Failed version set" -Foreground Red && exit 34

goto end
@rem ignored:
powershell Write-Host "starting unit tests" -Foreground Cyan
Expand All @@ -91,7 +108,6 @@ if not %errorlevel% == 0 goto error
popd
powershell Write-Host "Unit test SUCCESS" -Foreground Green


:error
popd
powershell Write-Host "Unit test failed" -Foreground Red
Expand Down
10 changes: 9 additions & 1 deletion agents/wnx/install/Product.wxs
@@ -1,7 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?ifdef $(env.wnx_version) = Enterprise ?>
<!-- IMPORTANT: Build script must correctly set wnx_version -->
<?define ProductVersion = $(env.wnx_version)?>
<?else?>
<!-- IMPORTANT: Code below is executed ONLY during manual compilation
just to signal that real build script was not called -->
<?define ProductVersion = "2.0.0.0"?>
<?endif ?>

<?define CompanyName = "Mathias Kettner GmbH"?>
<?define ProductName = "Check MK Service"?>
<?define ProductVersion = "2.0.1"?>
<?define ProductId = "{C3BDE55B-4C42-48D0-8792-B1DE5174C202}"?>
<?define ProductUpgradeCode = "83F434E9-EA96-4881-AA93-E21B27285C05"?>
<!-- IMPORTANT NOTE 1: If you change architecture, please change the package code TOO -->
Expand Down
Binary file added agents/wnx/src/check_mk_service.rc
Binary file not shown.
9 changes: 9 additions & 0 deletions agents/wnx/src/check_mk_service.vcxproj
Expand Up @@ -262,6 +262,7 @@ call check_service.cmd
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="main\pch.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<Text Include="engine\readme.txt" />
Expand All @@ -278,6 +279,14 @@ call check_service.cmd
<ItemGroup>
<None Include="..\..\..\buildscripts\Jenkinsfile" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="check_mk_service.rc">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
8 changes: 8 additions & 0 deletions agents/wnx/src/check_mk_service.vcxproj.filters
Expand Up @@ -31,10 +31,18 @@
<ClInclude Include="main\pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\buildscripts\Jenkinsfile">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="check_mk_service.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
45 changes: 42 additions & 3 deletions agents/wnx/src/common/version.h
@@ -1,7 +1,46 @@

// Windows Agent Version Data

#pragma once
#if !defined(version_h__)
#define version_h__
#if !defined(CHECK_MK_VERSION)
#define CHECK_MK_VERSION "2.0.0i1"

#include "wnx_version.h"
#define CHECK_MK_VERSION CMK_WIN_AGENT_VERSION

#define STRINGIZE2(s) #s
#define STRINGIZE(s) STRINGIZE2(s)

// This FILE version, normally no changes
#define VERSION_MAJOR 2
#define VERSION_MINOR 1
#define VERSION_REVISION 0
#define VERSION_BUILD 0

#define VER_FILE_VERSION \
VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD
#define VER_FILE_VERSION_STR \
STRINGIZE(VERSION_MAJOR) \
"." STRINGIZE(VERSION_MINOR) "." STRINGIZE( \
VERSION_REVISION) "." STRINGIZE(VERSION_BUILD)

#define VER_PRODUCT_VERSION_STR CMK_WIN_AGENT_VERSION

//#define VER_FILE_DESCRIPTION_STR "Description"
//#define VER_PRODUCTNAME_STR "c_version_binary"
//#define VER_PRODUCT_VERSION VER_FILE_VERSION
//#define VER_ORIGINAL_FILENAME_STR VER_PRODUCTNAME_STR ".exe"
//#define VER_INTERNAL_NAME_STR VER_ORIGINAL_FILENAME_STR
//#define VER_COPYRIGHT_STR "Copyright (C) 2019"

#ifdef _DEBUG
#define VER_VER_DEBUG VS_FF_DEBUG
#else
#define VER_VER_DEBUG 0
#endif
#endif//version_h__

#define VER_FILEOS VOS_NT_WINDOWS32
#define VER_FILEFLAGS VER_VER_DEBUG
#define VER_FILETYPE VFT_APP

#endif // version_h__
4 changes: 4 additions & 0 deletions agents/wnx/src/common/wnx_version.h
@@ -0,0 +1,4 @@
#define CMK_WIN_AGENT_VERSION "1.7.0i1"

// DO NOT CHANGE the structure of the first line
// First line is part of the build script
1 change: 1 addition & 0 deletions agents/wnx/src/engine/engine.vcxproj
Expand Up @@ -235,6 +235,7 @@
<ClInclude Include="..\common\cfg_info.h" />
<ClInclude Include="..\common\mailslot_transport.h" />
<ClInclude Include="..\common\version.h" />
<ClInclude Include="..\common\wnx_version.h" />
<ClInclude Include="..\common\wtools.h" />
<ClInclude Include="..\lwa\Configurable.h" />
<ClInclude Include="..\lwa\Configuration.h" />
Expand Down
3 changes: 3 additions & 0 deletions agents/wnx/src/engine/engine.vcxproj.filters
Expand Up @@ -198,6 +198,9 @@
<ClInclude Include="cma_core.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\wnx_version.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down
3 changes: 1 addition & 2 deletions agents/wnx/src/main/check_mk_service.cpp
Expand Up @@ -336,8 +336,7 @@ int MainFunction(int argc, wchar_t const *Argv[]) {
return cma::srv::InstallMainService();
}
if (param == wtools::ConvertToUTF16(kRemoveParam)) {
XLOG::l(XLOG::kStdio | XLOG::kInfo)("service to REMOVE");
return cma::srv::RemoveMainService();
return cma::srv::RemoveMainService();
}

if (param == wtools::ConvertToUTF16(kCheckParam)) {
Expand Down
14 changes: 14 additions & 0 deletions agents/wnx/src/resource.h
@@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by check_mk_service.rc

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
3 changes: 3 additions & 0 deletions agents/wnx/update_product_version.cmd
@@ -0,0 +1,3 @@
rem this is working example of version upating in the MSI
rem reference only
cscript.exe //nologo WiRunSQL.vbs file.msi "UPDATE `Property` SET `Property`.`Value`='1.2.3.4' WHERE `Property`.`Property`='ProductVersion'"
95 changes: 95 additions & 0 deletions agents/wnx/wirunsql.vbs
@@ -0,0 +1,95 @@
' This script can be used to update the installer database after it is built - see CustomMessages.wxl for related code.
' Add a Post-build event to the ExcelAddInDeploy project:
' Cscript "{Path to WiRunSQL.vbs}\WiRunSQL.vbs" "$(TargetDir)en-us\$(TargetFileName)" "UPDATE `TextStyle` SET `Color` = 16777215 WHERE `TextStyle` = 'WixUI_Font_Title'"
' This updates the installer database after it is built and changes the colour of the title text. Note the use of ` not ' around field names. Colour value calculated as:

' "65536 * blue + 256 * green + red, where red, green, and blue are each in the range of 0-255. The value must not exceed 16777215, which is the value for white.
' The value is 0 for black, 255 for red, 65280 for green, 16711680 for blue and 8421504 for grey. Leaving the field empty specifies the default color." - copied from
' http://msdn.microsoft.com/en-ca/library/windows/desktop/aa372074%28v=vs.85%29.aspx
' See also, http://stackoverflow.com/questions/17574141/customise-fonts-with-wix-extensions and http://msdn.microsoft.com/en-us/library/windows/desktop/aa368568%28v=vs.85%29.aspx

' Windows Installer utility to execute SQL statements against an installer database
' For use with Windows Scripting Host, CScript.exe or WScript.exe
' Copyright (c) Microsoft Corporation. All rights reserved.
' Demonstrates the script-driven database queries and updates
'
Option Explicit

Const msiOpenDatabaseModeReadOnly = 0
Const msiOpenDatabaseModeTransact = 1

Dim argNum, argCount:argCount = Wscript.Arguments.Count
If (argCount < 2) Then
Wscript.Echo "Windows Installer utility to execute SQL queries against an installer database." &_
vbLf & " The 1st argument specifies the path to the MSI database, relative or full path" &_
vbLf & " Subsequent arguments specify SQL queries to execute - must be in double quotes" &_
vbLf & " SELECT queries will display the rows of the result list specified in the query" &_
vbLf & " Binary data columns selected by a query will not be displayed" &_
vblf &_
vblf & "Copyright (C) Microsoft Corporation. All rights reserved."
Wscript.Quit 1
End If

' Scan arguments for valid SQL keyword and to determine if any update operations
Dim openMode : openMode = msiOpenDatabaseModeReadOnly
For argNum = 1 To argCount - 1
Dim keyword : keyword = Wscript.Arguments(argNum)
Dim keywordLen : keywordLen = InStr(1, keyword, " ", vbTextCompare)
If (keywordLen) Then keyword = UCase(Left(keyword, keywordLen - 1))
If InStr(1, "UPDATE INSERT DELETE CREATE ALTER DROP", keyword, vbTextCompare) Then
openMode = msiOpenDatabaseModeTransact
ElseIf keyword <> "SELECT" Then
Fail "Invalid SQL statement type: " & keyword
End If
Next

' Connect to Windows installer object
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError

' Open database
Dim databasePath:databasePath = Wscript.Arguments(0)
Dim database : Set database = installer.OpenDatabase(databasePath, openMode) : CheckError

' Process SQL statements
Dim query, view, record, message, rowData, columnCount, delim, column
For argNum = 1 To argCount - 1
query = Wscript.Arguments(argNum)
Set view = database.OpenView(query) : CheckError
view.Execute : CheckError
If Ucase(Left(query, 6)) = "SELECT" Then
Do
Set record = view.Fetch
If record Is Nothing Then Exit Do
columnCount = record.FieldCount
rowData = Empty
delim = " "
For column = 1 To columnCount
If column = columnCount Then delim = vbLf
rowData = rowData & record.StringData(column) & delim
Next
message = message & rowData
Loop
End If
Next
If openMode = msiOpenDatabaseModeTransact Then database.Commit
If Not IsEmpty(message) Then Wscript.Echo message
Wscript.Quit 0

Sub CheckError
Dim message, errRec
If Err = 0 Then Exit Sub
message = Err.Source & " " & Hex(Err) & ": " & Err.Description
If Not installer Is Nothing Then
Set errRec = installer.LastErrorRecord
If Not errRec Is Nothing Then message = message & vbLf & errRec.FormatText
End If
Fail message
End Sub

Sub Fail(message)
Wscript.Echo message
Wscript.Quit 2
End Sub

0 comments on commit 812799a

Please sign in to comment.