From 619df5364f1a3c35538d4b81e12e78f4fd3d9bce Mon Sep 17 00:00:00 2001 From: jean-christophe81 <98889244+jean-christophe81@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:31:12 +0200 Subject: [PATCH 01/14] silent mode for installer and modifier (#1737) add installer tests silent uninstaller --- .github/scripts/agent_installer_test.ps1 | 267 ++++++++++ .github/workflows/windows-agent.yml | 4 + .../centreon-monitoring-agent-modify.nsi | 64 ++- agent/installer/centreon-monitoring-agent.nsi | 124 ++++- agent/installer/dlg_helper.nsi | 4 +- agent/installer/resources/log_dlg.nsddef | 4 +- agent/installer/resources/log_dlg.nsdinc | 2 +- agent/installer/resources/setup_dlg.nsddef | 2 +- agent/installer/resources/setup_dlg.nsdinc | 2 +- agent/installer/silent.nsi | 477 ++++++++++++++++++ 10 files changed, 906 insertions(+), 44 deletions(-) create mode 100644 .github/scripts/agent_installer_test.ps1 create mode 100644 agent/installer/silent.nsi diff --git a/.github/scripts/agent_installer_test.ps1 b/.github/scripts/agent_installer_test.ps1 new file mode 100644 index 00000000000..8de2f10c333 --- /dev/null +++ b/.github/scripts/agent_installer_test.ps1 @@ -0,0 +1,267 @@ +# +# Copyright 2024 Centreon +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# For more information : contact@centreon.com +# + +# This script test CMA installer in silent mode + + +function test_args_to_registry { +<# +.SYNOPSIS + start a program and check values in registry + +.PARAMETER exe_path + path of the installer to execute + +.PARAMETER exe_args + installer arguments + +.PARAMETER expected_registry_values + hash_table as @{'host'='host_1';'endpoint'='127.0.0.1'} +#> + param ( + [string] $exe_path, + [string[]] $exe_args, + $expected_registry_values + ) + + Write-Host "arguments: $exe_args" + + $process_info= Start-Process -PassThru $exe_path $exe_args + Wait-Process -Id $process_info.Id + if ($process_info.ExitCode -ne 0) { + Write-Host "fail to execute $exe_path with arguments $exe_args" + Write-Host "exit status = " $process_info.ExitCode + exit 1 + } + + foreach ($value_name in $expected_registry_values.Keys) { + $expected_value = $($expected_registry_values[$value_name]) + $real_value = (Get-ItemProperty -Path HKLM:\Software\Centreon\CentreonMonitoringAgent -Name $value_name).$value_name + if ($expected_value -ne $real_value) { + Write-Host "unexpected value for $value_name, expected: $expected_value, read: $real_value" + exit 1 + } + } +} + +Write-Host "############################ all install uninstall ############################" + +$args = '/S','--install_cma', '--install_plugins', '--hostname', "my_host_name_1", "--endpoint","127.0.0.1:4317" +$expected = @{ 'endpoint'='127.0.0.1:4317';'host'='my_host_name_1';'log_type'='EventLog'; 'log_level' = 'error'; 'encryption' = 0;'reversed_grpc_streaming'= 0 } +test_args_to_registry "agent/installer/centreon-monitoring-agent.exe" $args $expected + +if (!(Get-ItemProperty -Path HKLM:\Software\Centreon\CentreonMonitoringAgent)) { + Write-Host "no registry entry created" + exit 1 +} + +Get-Process | Select-Object -Property ProcessName | Select-String centagent + +$info = Get-Process | Select-Object -Property ProcessName | Select-String centagent + +#$info = Get-Process centagent 2>$null +if (!$info) { + Write-Host "centagent.exe not started" + exit 1 +} + +if (![System.Io.File]::Exists("C:\Program Files\Centreon\Plugins\centreon_plugins.exe")) { + Write-Host "centreon_plugins.exe not installed" + exit 1 +} + +$process_info= Start-Process -PassThru "C:\Program Files\Centreon\CentreonMonitoringAgent\uninstall.exe" "/S", "--uninstall_cma","--uninstall_plugins" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 0) { + Write-Host "bad uninstaller exit code" + exit 1 +} + +Start-Sleep -Seconds 5 + +Get-Process | Select-Object -Property ProcessName | Select-String centagent + +$info = Get-Process | Select-Object -Property ProcessName | Select-String centagent +#$info = Get-Process centagent 2>$null +if ($info) { + Write-Host "centagent.exe running" + exit 1 +} + +if ([System.Io.File]::Exists("C:\Program Files\Centreon\Plugins\centreon_plugins.exe")) { + Write-Host "centreon_plugins.exe not removed" + exit 1 +} + +Write-Host "The followind command will output errors, don't take it into account" +#the only mean I have found to test key erasure under CI +#Test-Path doesn't work +$key_found = true +try { + Get-ChildItem -Path HKLM:\Software\Centreon\CentreonMonitoringAgent +} +catch { + $key_found = false +} + +if ($key_found) { + Write-Host "registry entry not removed" + exit 1 +} + + +Write-Host "############################ installer test ############################" + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--help" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 2) { + Write-Host "bad --help exit code" + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--version" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 2) { + Write-Host "bad --version exit code" + exit 1 +} + +#missing mandatory parameters +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "bad no parameter exit code " $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "bad no endpoint exit code " $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto","--endpoint","turlututu" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "bad wrong endpoint exit code " $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto","--endpoint","127.0.0.1:4317","--log_type","file" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "bad no log file path " $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto","--endpoint","127.0.0.1:4317","--log_type","file","--log_file","C:" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "bad log file path " $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto","--endpoint","127.0.0.1:4317","--log_level","dsfsfd" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "bad log level " $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto","--endpoint","127.0.0.1:4317","--reverse","--log_type","file","--log_file","C:\Users\Public\cma.log","--encryption" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "reverse mode, encryption and no private_key " $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto","--endpoint","127.0.0.1:4317","--reverse","--log_type","file","--log_file","C:\Users\Public\cma.log","--encryption","--private_key","C:" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "reverse mode, encryption and bad private_key path" $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto","--endpoint","127.0.0.1:4317","--reverse","--log_type","file","--log_file","C:\Users\Public\cma.log","--encryption","--private_key","C:\Users\Public\private_key.key" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "reverse mode, encryption and no certificate" $process_info.ExitCode + exit 1 +} + +$process_info= Start-Process -PassThru "agent/installer/centreon-monitoring-agent.exe" "/S", "--install_cma","--hostname","toto","--endpoint","127.0.0.1:4317","--reverse","--log_type","file","--log_file","C:\Users\Public\cma.log","--encryption","--private_key","C:\Users\Public\private_key.key", "--public_cert", "C:" +Wait-Process -Id $process_info.Id +if ($process_info.ExitCode -ne 1) { + Write-Host "reverse mode, encryption and bad certificate path" $process_info.ExitCode + exit 1 +} + + +$args = '/S','--install_cma','--hostname', "my_host_name_1", "--endpoint","127.0.0.1:4317" +$expected = @{ 'endpoint'='127.0.0.1:4317';'host'='my_host_name_1';'log_type'='EventLog'; 'log_level' = 'error'; 'encryption' = 0;'reversed_grpc_streaming'= 0 } +test_args_to_registry "agent/installer/centreon-monitoring-agent.exe" $args $expected + +$args = '/S','--install_cma','--hostname', "my_host_name_2", "--endpoint","127.0.0.2:4317", "--log_type", "file", "--log_file", "C:\Users\Public\cma.log", "--log_level", "trace", "--log_max_file_size", "15", "--log_max_files", "10" +$expected = @{ 'endpoint'='127.0.0.2:4317';'host'='my_host_name_2';'log_type'='File'; 'log_level' = 'trace'; 'log_file'='C:\Users\Public\cma.log'; 'encryption' = 0;'reversed_grpc_streaming'= 0; 'log_max_file_size' = 15; 'log_max_files' = 10; } +test_args_to_registry "agent/installer/centreon-monitoring-agent.exe" $args $expected + +$args = '/S','--install_cma','--hostname', "my_host_name_2", "--endpoint","127.0.0.3:4317", "--log_type", "file", "--log_file", "C:\Users\Public\cma.log", "--log_level", "trace", "--encryption" +$expected = @{ 'endpoint'='127.0.0.3:4317';'host'='my_host_name_2';'log_type'='File'; 'log_level' = 'trace'; 'log_file'='C:\Users\Public\cma.log'; 'encryption' = 1;'reversed_grpc_streaming'= 0 } +test_args_to_registry "agent/installer/centreon-monitoring-agent.exe" $args $expected + +$args = '/S','--install_cma','--hostname', "my_host_name_2", "--endpoint","127.0.0.4:4317", "--log_type", "file", "--log_file", "C:\Users\Public\cma.log", "--log_level", "trace", "--encryption", "--private_key", "C:\Users crypto\private.key", "--public_cert", "D:\tutu\titi.crt", "--ca", "C:\Users\Public\ca.crt", "--ca_name", "tls_ca_name" +$expected = @{ 'endpoint'='127.0.0.4:4317';'host'='my_host_name_2';'log_type'='File'; 'log_level' = 'trace'; 'log_file'='C:\Users\Public\cma.log'; 'encryption' = 1;'reversed_grpc_streaming'= 0; 'certificate'='D:\tutu\titi.crt'; 'private_key'='C:\Users crypto\private.key'; 'ca_certificate' = 'C:\Users\Public\ca.crt'; 'ca_name' = 'tls_ca_name' } +test_args_to_registry "agent/installer/centreon-monitoring-agent.exe" $args $expected + +$args = '/S','--install_cma','--hostname', "my_host_name_2", "--endpoint","127.0.0.5:4317", "--log_type", "file", "--log_file", "C:\Users\Public\cma_rev.log", "--log_level", "trace", "--encryption", "--reverse", "--private_key", "C:\Users crypto\private_rev.key", "--public_cert", "D:\tutu\titi_rev.crt", "--ca", "C:\Users\Public\ca_rev.crt", "--ca_name", "tls_ca_name_rev" +$expected = @{ 'endpoint'='127.0.0.5:4317';'host'='my_host_name_2';'log_type'='File'; 'log_level' = 'trace'; 'log_file'='C:\Users\Public\cma_rev.log'; 'encryption' = 1;'reversed_grpc_streaming'= 1; 'certificate'='D:\tutu\titi_rev.crt'; 'private_key'='C:\Users crypto\private_rev.key'; 'ca_certificate' = 'C:\Users\Public\ca_rev.crt'; 'ca_name' = 'tls_ca_name_rev' } +test_args_to_registry "agent/installer/centreon-monitoring-agent.exe" $args $expected + + +Write-Host "############################ modifier test ############################" + +$args = '/S','--hostname', "my_host_name_10", "--endpoint","127.0.0.10:4317", "--no_reverse" +$expected = @{ 'endpoint'='127.0.0.10:4317';'host'='my_host_name_10';'log_type'='File'; 'log_level' = 'trace'; 'log_file'='C:\Users\Public\cma_rev.log'; 'encryption' = 1;'reversed_grpc_streaming'= 0; 'certificate'='D:\tutu\titi_rev.crt'; 'private_key'='C:\Users crypto\private_rev.key'; 'ca_certificate' = 'C:\Users\Public\ca_rev.crt'; 'ca_name' = 'tls_ca_name_rev' } +test_args_to_registry "agent/installer/centreon-monitoring-agent-modify.exe" $args $expected + +$args = '/S',"--log_type", "file", "--log_file", "C:\Users\Public\cma_rev2.log", "--log_level", "debug", "--log_max_file_size", "50", "--log_max_files", "20" +$expected = @{ 'endpoint'='127.0.0.10:4317';'host'='my_host_name_10';'log_type'='File'; 'log_level' = 'debug'; 'log_file'='C:\Users\Public\cma_rev2.log'; 'encryption' = 1;'reversed_grpc_streaming'= 0; 'certificate'='D:\tutu\titi_rev.crt'; 'log_max_file_size' = 50; 'log_max_files' = 20;'private_key'='C:\Users crypto\private_rev.key'; 'ca_certificate' = 'C:\Users\Public\ca_rev.crt'; 'ca_name' = 'tls_ca_name_rev' } +test_args_to_registry "agent/installer/centreon-monitoring-agent-modify.exe" $args $expected + +$args = '/S',"--log_type", "EventLog", "--log_level", "error" +$expected = @{ 'endpoint'='127.0.0.10:4317';'host'='my_host_name_10';'log_type'='event-log'; 'log_level' = 'error'; 'encryption' = 1;'reversed_grpc_streaming'= 0; 'certificate'='D:\tutu\titi_rev.crt'; 'private_key'='C:\Users crypto\private_rev.key'; 'ca_certificate' = 'C:\Users\Public\ca_rev.crt'; 'ca_name' = 'tls_ca_name_rev' } +test_args_to_registry "agent/installer/centreon-monitoring-agent-modify.exe" $args $expected + +$args = '/S',"--private_key", "C:\Users crypto\private_rev2.key", "--public_cert", "D:\tutu\titi_rev2.crt" +$expected = @{ 'endpoint'='127.0.0.10:4317';'host'='my_host_name_10';'log_type'='event-log'; 'log_level' = 'error'; 'encryption' = 1;'reversed_grpc_streaming'= 0; 'certificate'='D:\tutu\titi_rev2.crt'; 'private_key'='C:\Users crypto\private_rev2.key'; 'ca_certificate' = 'C:\Users\Public\ca_rev.crt'; 'ca_name' = 'tls_ca_name_rev' } +test_args_to_registry "agent/installer/centreon-monitoring-agent-modify.exe" $args $expected + +$args = '/S',"--ca", "C:\Users\Public\ca_rev2.crt", "--ca_name", "tls_ca_name_rev2" +$expected = @{ 'endpoint'='127.0.0.10:4317';'host'='my_host_name_10';'log_type'='event-log'; 'log_level' = 'error'; 'encryption' = 1;'reversed_grpc_streaming'= 0; 'certificate'='D:\tutu\titi_rev2.crt'; 'private_key'='C:\Users crypto\private_rev2.key'; 'ca_certificate' = 'C:\Users\Public\ca_rev2.crt'; 'ca_name' = 'tls_ca_name_rev2' } +test_args_to_registry "agent/installer/centreon-monitoring-agent-modify.exe" $args $expected + +$args = '/S',"--no_encryption" +$expected = @{ 'endpoint'='127.0.0.10:4317';'host'='my_host_name_10';'log_type'='event-log'; 'log_level' = 'error'; 'encryption' = 0;'reversed_grpc_streaming'= 0; 'certificate'='D:\tutu\titi_rev2.crt'; 'private_key'='C:\Users crypto\private_rev2.key'; 'ca_certificate' = 'C:\Users\Public\ca_rev2.crt'; 'ca_name' = 'tls_ca_name_rev2' } +test_args_to_registry "agent/installer/centreon-monitoring-agent-modify.exe" $args $expected + + + +Write-Host "############################ end test ############################" + +exit 0 diff --git a/.github/workflows/windows-agent.yml b/.github/workflows/windows-agent.yml index 0ef4b5ba8b9..ffd3033a623 100644 --- a/.github/workflows/windows-agent.yml +++ b/.github/workflows/windows-agent.yml @@ -73,6 +73,10 @@ jobs: cd build_windows tests/ut_agent + - name: Installer test + run: .github/scripts/agent_installer_test.ps1 + shell: powershell + - name: Upload package artifacts if: | inputs.installer_in_artifact == true diff --git a/agent/installer/centreon-monitoring-agent-modify.nsi b/agent/installer/centreon-monitoring-agent-modify.nsi index b5197820b80..4f15ee8d9d5 100644 --- a/agent/installer/centreon-monitoring-agent-modify.nsi +++ b/agent/installer/centreon-monitoring-agent-modify.nsi @@ -28,6 +28,10 @@ Unicode false !define CMA_REG_KEY "SOFTWARE\${COMPANYNAME}\${APPNAME}" +#Match to windows file path C:\tutu yoyo1234 titi\fgdfgdg.rt +!define FILE_PATH_REGEXP '^[a-zA-Z]:([\\|\/](([\w\.]+\s+)*[\w\.]+)+)+$$' + + !include "LogicLib.nsh" !include "nsDialogs.nsh" !include "mui.nsh" @@ -52,35 +56,34 @@ ${NSISCONF_3}!addplugindir /x86-ansi "nsis_pcre" !include "resources\log_dlg.nsdinc" #let it after dialog boxes !include "dlg_helper.nsi" +!include "silent.nsi" Name "Centreon Monitoring Agent ${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}" Icon "resources/logo_centreon.ico" RequestExecutionLevel admin -AllowRootDirInstall true +VIProductVersion "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0" +VIFileVersion "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0" +VIAddVersionKey "FileVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}" +VIAddVersionKey "LegalCopyright" "2024 Centreon" +VIAddVersionKey "FileDescription" "Centreon Monitoring Agent Config modifier" +VIAddVersionKey "ProductName" "Centreon Monitoring Agent" +VIAddVersionKey "CompanyName" "Centreon" +VIAddVersionKey "ProductVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0" !macro VerifyUserIsAdmin UserInfo::GetAccountType pop $0 ${If} $0 != "admin" ;Require admin rights - messageBox mb_iconstop "Administrator rights required!" - setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED - quit + messageBox mb_iconstop "Administrator rights required!" + setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED + quit ${EndIf} !macroend -function .onInit - setShellVarContext all - !insertmacro VerifyUserIsAdmin -functionEnd - -/** - * @brief at the end of the installer, we stop and start cma -*/ -Function encryption_next_and_restart_centagent - Call encryption_dlg_onNext +Function restart_cma !insertmacro SERVICE "stop" "${SERVICE_NAME}" "" ;wait for service stop @@ -97,9 +100,40 @@ Function encryption_next_and_restart_centagent Sleep 500 ${Loop} ; even if service is stopped, process can be stopping so we wait a little more - Sleep 500 + Sleep 1000 !insertmacro SERVICE "start" "${SERVICE_NAME}" "" +FunctionEnd + + +Function .onInit + setShellVarContext all + ${If} ${Silent} + SetErrorLevel 0 + ${GetParameters} $cmdline_parameters + StrCpy $1 "--no_reverse Set this flag if you want to disable Poller-initiated connection$\n\ +--no_encryption Set this flag if you want to disable encryption $\n" + Call show_help + call show_version + Call silent_verify_admin + Call silent_update_conf + + Call restart_cma + System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console + System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout + FileWrite $0 "Centreon monitoring agent configured and restarted$\n" + Quit + ${Else} + !insertmacro VerifyUserIsAdmin + ${EndIf} +FunctionEnd + +/** + * @brief at the end of the installer, we stop and start cma +*/ +Function encryption_next_and_restart_centagent + Call encryption_dlg_onNext + Call restart_cma MessageBox MB_OK "The Centreon Monitoring Agent has now restarted" Quit FunctionEnd diff --git a/agent/installer/centreon-monitoring-agent.nsi b/agent/installer/centreon-monitoring-agent.nsi index dadc0823c94..163d57a1ee0 100644 --- a/agent/installer/centreon-monitoring-agent.nsi +++ b/agent/installer/centreon-monitoring-agent.nsi @@ -27,6 +27,10 @@ Unicode false !define SERVICE_NAME ${APPNAME} !define CMA_REG_KEY "SOFTWARE\${COMPANYNAME}\${APPNAME}" + +#Match to windows file path C:\tutu yoyo1234 titi\fgdfgdg.rt +!define FILE_PATH_REGEXP '^[a-zA-Z]:([\\|\/](([\w\.]+\s+)*[\w\.]+)+)+$$' + !define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" !define NSCLIENT_URL "https://api.github.com/repos/centreon/centreon-nsclient-build/releases/latest" @@ -58,11 +62,24 @@ ${Using:StrFunc} StrCase #let it after dialog boxes !include "dlg_helper.nsi" +!include "silent.nsi" + +OutFile "centreon-monitoring-agent.exe" Name "Centreon Monitoring Agent ${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}" Icon "resources/logo_centreon.ico" LicenseData "resources/license.txt" RequestExecutionLevel admin -AllowRootDirInstall true +;AllowRootDirInstall true + +VIProductVersion "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0" +VIFileVersion "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0" +VIAddVersionKey "FileVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}" +VIAddVersionKey "LegalCopyright" "2024 Centreon" +VIAddVersionKey "FileDescription" "Centreon Monitoring Agent Installer" +VIAddVersionKey "ProductName" "Centreon Monitoring Agent" +VIAddVersionKey "CompanyName" "Centreon" +VIAddVersionKey "ProductVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0" + InstallDir "$PROGRAMFILES64\${COMPANYNAME}\${APPNAME}" !define PLUGINS_DIR "$PROGRAMFILES64\${COMPANYNAME}\Plugins" @@ -73,7 +90,7 @@ Var plugins_url -!macro VerifyUserIsAdmin +!macro verify_user_is_admin UserInfo::GetAccountType pop $0 ${If} $0 != "admin" ;Require admin rights @@ -83,10 +100,6 @@ ${If} $0 != "admin" ;Require admin rights ${EndIf} !macroend -function .onInit - setShellVarContext all - !insertmacro VerifyUserIsAdmin -functionEnd /** @@ -153,11 +166,16 @@ FunctionEnd /** * @brief this section download plugings from the asset of the last centreon-nsclient-build release */ -Section "Plugins" - Call get_plugins_url - CreateDirectory ${PLUGINS_DIR} - DetailPrint "download plugins from $plugins_url" - inetc::get /caption "plugins" /banner "Downloading plugins..." "$plugins_url" "${PLUGINS_DIR}/centreon_plugins.exe" +Section "Plugins" PluginsInstSection + Call get_plugins_url + CreateDirectory ${PLUGINS_DIR} + DetailPrint "download plugins from $plugins_url" + inetc::get /caption "plugins" /banner "Downloading plugins..." "$plugins_url" "${PLUGINS_DIR}/centreon_plugins.exe" + ${If} ${Silent} + System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console + System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout + FileWrite $0 "Centreon plugins installed$\n" + ${EndIf} SectionEnd @@ -207,8 +225,50 @@ Section "Centreon Monitoring Agent" CMAInstSection IntFmt $0 "0x%08X" $0 WriteRegDWORD HKLM "${UNINSTALL_KEY}" "EstimatedSize" "$0" + ${If} ${Silent} + System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console + System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout + FileWrite $0 "Centreon monitoring agent installed and started$\n" + ${EndIf} SectionEnd + +/** + * @brief function called on install +*/ +function .onInit + setShellVarContext all + + ${If} ${Silent} + SetErrorLevel 0 + ${GetParameters} $cmdline_parameters + Strcpy $1 "--install_cma Set this flag if you want to install centreon monitoring agent$\n\ +--install_plugins Set this flag if you want to install centreon plugins$\n" + Call show_help + Call show_version + Call silent_verify_admin + + Call installer_parse_cmd_line + + ${If} $silent_install_cma == 1 + Call cmd_line_to_registry + SectionSetFlags ${CMAInstSection} ${SF_SELECTED} + ${Else} + SectionSetFlags ${CMAInstSection} 0 + ${EndIf} + + ${If} $silent_install_plugins == 1 + SectionSetFlags ${PluginsInstSection} ${SF_SELECTED} + ${Else} + SectionSetFlags ${PluginsInstSection} 0 + ${EndIf} + + ${Else} + !insertmacro verify_user_is_admin + ${EndIf} + +functionEnd + /** * @brief show cma setup dialogbox ig user has choosen to install cma */ @@ -240,7 +300,7 @@ FunctionEnd /** * @brief uninstall section */ -Section "uninstall" +Section "uninstall" UninstallSection SetRegView 64 # the only way to delete a service without reboot ExecWait 'net stop ${SERVICE_NAME}' @@ -272,14 +332,36 @@ SectionEnd function un.onInit SetShellVarContext all - !insertmacro VerifyUserIsAdmin - - MessageBox MB_YESNO "Do you want to remove the Centreon plugins for the agents?" IDNO no_plugins_remove - rmDir ${PLUGINS_DIR} - no_plugins_remove: + ${If} ${Silent} + SetErrorLevel 0 + Call un.show_uninstaller_help + Call un.show_version + Call un.silent_verify_admin - MessageBox MB_YESNO "Do you want to remove the Centreon Monitoring Agent?" IDYES no_cma_remove - Abort - no_cma_remove: + ClearErrors + ${GetOptions} $cmdline_parameters "--uninstall_plugins" $0 + ${IfNot} ${Errors} + rmDir /r ${PLUGINS_DIR} + ${EndIf} -functionEnd \ No newline at end of file + ClearErrors + ${GetOptions} $cmdline_parameters "--uninstall_cma" $0 + ${IfNot} ${Errors} + SectionSetFlags ${UninstallSection} ${SF_SELECTED} + ${Else} + SectionSetFlags ${UninstallSection} 0 + ${EndIf} + + ${Else} + !insertmacro verify_user_is_admin + + MessageBox MB_YESNO "Do you want to remove the Centreon plugins for the agents?" IDNO no_plugins_remove + rmDir /r ${PLUGINS_DIR} + no_plugins_remove: + + MessageBox MB_YESNO "Do you want to remove the Centreon Monitoring Agent?" IDYES no_cma_remove + Abort + no_cma_remove: + + ${EndIf} +functionEnd diff --git a/agent/installer/dlg_helper.nsi b/agent/installer/dlg_helper.nsi index c3953ab4240..c6a864426a9 100644 --- a/agent/installer/dlg_helper.nsi +++ b/agent/installer/dlg_helper.nsi @@ -20,8 +20,6 @@ !insertmacro REMatches -#Match to windows file path C:\tutu yoyo1234 titi\fgdfgdg.rt -!define FILE_PATH_REGEXP '^[a-zA-Z]:([\\|\/](([\w\.]+\s+)*[\w\.]+)+)+$' /*************************************************************************************** setup dialogbox @@ -214,7 +212,7 @@ Function log_dlg_onNext WriteRegDWORD HKLM ${CMA_REG_KEY} "log_max_files" $0 ${Else} ${StrCase} $0 $0 "L" - WriteRegStr HKLM ${CMA_REG_KEY} "log_type" $0 + WriteRegStr HKLM ${CMA_REG_KEY} "log_type" "event-log" ${EndIf} Pop $0 diff --git a/agent/installer/resources/log_dlg.nsddef b/agent/installer/resources/log_dlg.nsddef index 164ab301ed7..e6d112a1f12 100644 --- a/agent/installer/resources/log_dlg.nsddef +++ b/agent/installer/resources/log_dlg.nsddef @@ -19,8 +19,8 @@ Call on_log_type_changed - EventLog - File + event-log + file diff --git a/agent/installer/resources/log_dlg.nsdinc b/agent/installer/resources/log_dlg.nsdinc index 30ede3e8d28..9d67db14bd7 100644 --- a/agent/installer/resources/log_dlg.nsdinc +++ b/agent/installer/resources/log_dlg.nsdinc @@ -87,7 +87,7 @@ Function fnc_log_dlg_Create ${NSD_CreateDropList} 111u 2u 80u 13u "" Pop $hCtl_log_dlg_log_type ${NSD_OnChange} $hCtl_log_dlg_log_type on_log_type_changed - ${NSD_CB_AddString} $hCtl_log_dlg_log_type "EventLog" + ${NSD_CB_AddString} $hCtl_log_dlg_log_type "Event-log" ${NSD_CB_AddString} $hCtl_log_dlg_log_type "File" ; === log_level (type: DropList) === diff --git a/agent/installer/resources/setup_dlg.nsddef b/agent/installer/resources/setup_dlg.nsddef index e64ac5cb85e..263c0872502 100644 --- a/agent/installer/resources/setup_dlg.nsddef +++ b/agent/installer/resources/setup_dlg.nsddef @@ -13,5 +13,5 @@ Do not edit manually! -