Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Sep 27, 2024
1 parent b4af22c commit f8abcee
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
required: true
default: true
type: boolean

pull_request:
paths:
- agent/**
Expand Down
16 changes: 11 additions & 5 deletions agent/installer/centreon-monitoring-agent-modify.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ Unicode false

!define CMA_REG_KEY "SOFTWARE\${COMPANYNAME}\${APPNAME}"




!include "LogicLib.nsh"
!include "nsDialogs.nsh"
!include "mui.nsh"
Expand Down Expand Up @@ -77,7 +74,10 @@ 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

Expand All @@ -104,6 +104,10 @@ Function encryption_next_and_restart_centagent
Quit
FunctionEnd


/**
* @brief this fake page is used to have a close button after restart cma confirmation
*/
Function dummy_page
FunctionEnd

Expand All @@ -112,6 +116,8 @@ Page custom fnc_log_dlg_Show log_dlg_onNext ": logging"
Page custom fnc_encryption_Show encryption_next_and_restart_centagent ": encryption"
Page custom dummy_page

; this installer only update agent config
/**
* @brief this installer only update agent config, no installation
*/
Section "update config"
SectionEnd
61 changes: 46 additions & 15 deletions agent/installer/centreon-monitoring-agent.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ InstallDir "$PROGRAMFILES64\${COMPANYNAME}\${APPNAME}"
Var plugins_url



!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
Expand All @@ -88,19 +89,27 @@ function .onInit
functionEnd


/**
* @brief pages
*/
page license
Page components
Page custom setup_cma_show setup_dlg_onNext
Page custom setup_log_show log_dlg_onNext ": logging"
Page custom setup_cma_encryption_show encryption_dlg_onNext ": encryption"
Page instfiles


/**
* @brief first it uses github API to get information of centreon-nsclient-build last releases.
* Then it gets a json response where one asset is the asset of centreon plugins
*
*/
Function get_plugins_url
;because of several bugs, we have to store github response in a file and then parse it
#because of several bugs, we have to store github response in a file and then parse it
Var /GLOBAL json_content_path
Var /GLOBAL nb_assets
GetTempFileName $json_content_path
#get release information
ClearErrors
inetc::get /header "Accept: application/vnd.github+json" ${NSCLIENT_URL} $json_content_path /End
${If} ${Errors}
Expand All @@ -113,7 +122,7 @@ Function get_plugins_url
Abort
${EndIf}


#parse json response
nsJSON::Set /file $json_content_path
${If} ${Errors}
MessageBox MB_OK|MB_ICONSTOP "bad json received from ${NSCLIENT_URL}"
Expand Down Expand Up @@ -141,6 +150,9 @@ Function get_plugins_url

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}
Expand All @@ -149,6 +161,9 @@ Section "Plugins"
SectionEnd


/**
* @brief this section configure and install centreon monitoring agent
*/
Section "Centreon Monitoring Agent" CMAInstSection
SetRegView 64
#event logger
Expand All @@ -158,7 +173,7 @@ Section "Centreon Monitoring Agent" CMAInstSection

!insertmacro SERVICE "stop" "${SERVICE_NAME}" ""

;wait for service stop
#wait for service stop
StrCpy $0 ""
${Do}
Push "running"
Expand All @@ -171,18 +186,20 @@ Section "Centreon Monitoring Agent" CMAInstSection
${EndIf}
Sleep 500
${Loop}
; even if service is stopped, process can be stopping so we wait a little more
# even if service is stopped, process can be stopping so we wait a little more
Sleep 500

file ${CENTAGENT_PATH}
file "centreon-monitoring-agent-modify.exe"
writeUninstaller "$INSTDIR\uninstall.exe"


#create and start service
!insertmacro SERVICE "create" "${SERVICE_NAME}" \
"path=$INSTDIR\centagent.exe;autostart=1;display=Centreon Monitoring Agent;\
starttype=${SERVICE_AUTO_START};servicetype=${SERVICE_WIN32_OWN_PROCESS}"
!insertmacro SERVICE "start" "${SERVICE_NAME}" ""

#uninstall information
WriteRegStr HKLM "${UNINSTALL_KEY}" "DisplayName" "Centreon Monitoring Agent"
WriteRegStr HKLM "${UNINSTALL_KEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "${UNINSTALL_KEY}" "ModifyPath" "$\"$INSTDIR\centreon-monitoring-agent-modify.exe$\""
Expand All @@ -192,26 +209,37 @@ Section "Centreon Monitoring Agent" CMAInstSection

SectionEnd


/**
* @brief show cma setup dialogbox ig user has choosen to install cma
*/
Function setup_cma_show
${If} ${SectionIsSelected} ${CMAInstSection}
Call fnc_cma_Show
${EndIf}
FunctionEnd

/**
* @brief show cma log dialogbox ig user has choosen to install cma
*/
Function setup_log_show
${If} ${SectionIsSelected} ${CMAInstSection}
Call fnc_log_dlg_Show
${EndIf}
FunctionEnd

/**
* @brief show cma encryption dialogbox ig user has choosen to install cma
*/
Function setup_cma_encryption_show
${If} ${SectionIsSelected} ${CMAInstSection}
Call fnc_encryption_Show
${EndIf}
FunctionEnd


/**
* @brief uninstall section
*/
Section "uninstall"
SetRegView 64
# the only way to delete a service without reboot
Expand All @@ -221,28 +249,31 @@ Section "uninstall"
delete $INSTDIR\centagent.exe
delete $INSTDIR\centreon-monitoring-agent-modify.exe


# Try to remove the install directory - this will only happen if it is empty
rmDir $INSTDIR
rmDir "$PROGRAMFILES64\${COMPANYNAME}"

#cma
DeleteRegKey HKLM "${CMA_REG_KEY}"
DeleteRegKey /ifempty HKLM "Software\Centreon"
DeleteRegKey HKLM "${UNINSTALL_KEY}"

#event logger
DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\EventLog\Application\${SERVICE_NAME}"

# Always delete uninstaller as the last action
delete $INSTDIR\uninstall.exe

# Try to remove the install directory - this will only happen if it is empty
rmDir $INSTDIR
rmDir "$PROGRAMFILES64\${COMPANYNAME}"

DeleteRegKey HKLM "${UNINSTALL_KEY}"
SectionEnd

# Uninstaller
/**
* @brief called on uninstall
*/
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:
Expand Down
Loading

0 comments on commit f8abcee

Please sign in to comment.