installer.nsi 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. !include "MUI2.nsh"
  2. !include "nsDialogs.nsh"
  3. !include "FileFunc.nsh"
  4. Name "Netdata"
  5. Outfile "netdata-installer.exe"
  6. InstallDir "$PROGRAMFILES\Netdata"
  7. RequestExecutionLevel admin
  8. !define MUI_ICON "NetdataWhite.ico"
  9. !define MUI_UNICON "NetdataWhite.ico"
  10. !define ND_UININSTALL_REG "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
  11. !define MUI_ABORTWARNING
  12. !define MUI_UNABORTWARNING
  13. !insertmacro MUI_PAGE_WELCOME
  14. !insertmacro MUI_PAGE_LICENSE "C:\msys64\cloud.txt"
  15. !insertmacro MUI_PAGE_LICENSE "C:\msys64\gpl-3.0.txt"
  16. !insertmacro MUI_PAGE_DIRECTORY
  17. !insertmacro MUI_PAGE_INSTFILES
  18. Page Custom NetdataConfigPage NetdataConfigLeave
  19. !insertmacro MUI_PAGE_FINISH
  20. !insertmacro MUI_UNPAGE_CONFIRM
  21. !insertmacro MUI_UNPAGE_INSTFILES
  22. !insertmacro MUI_UNPAGE_FINISH
  23. !insertmacro MUI_LANGUAGE "English"
  24. var hStartMsys
  25. var startMsys
  26. var hCloudToken
  27. var cloudToken
  28. var hCloudRoom
  29. var cloudRoom
  30. Function .onInit
  31. nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata'
  32. pop $0
  33. ${If} $0 == 0
  34. nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata'
  35. pop $0
  36. ${EndIf}
  37. StrCpy $startMsys ${BST_UNCHECKED}
  38. FunctionEnd
  39. Function NetdataConfigPage
  40. !insertmacro MUI_HEADER_TEXT "Netdata configuration" "Claim your agent on Netdata Cloud"
  41. nsDialogs::Create 1018
  42. Pop $0
  43. ${If} $0 == error
  44. Abort
  45. ${EndIf}
  46. ${NSD_CreateLabel} 0 0 100% 12u "Enter your Token and Cloud Room."
  47. ${NSD_CreateLabel} 0 15% 100% 12u "Optionally, you can open a terminal to execute additional commands."
  48. ${NSD_CreateLabel} 0 35% 20% 10% "Token"
  49. Pop $0
  50. ${NSD_CreateText} 21% 35% 79% 10% ""
  51. Pop $hCloudToken
  52. ${NSD_CreateLabel} 0 55% 20% 10% "Room"
  53. Pop $0
  54. ${NSD_CreateText} 21% 55% 79% 10% ""
  55. Pop $hCloudRoom
  56. ${NSD_CreateCheckbox} 0 70% 100% 10u "Open terminal"
  57. Pop $hStartMsys
  58. nsDialogs::Show
  59. FunctionEnd
  60. Function NetdataConfigLeave
  61. ${NSD_GetText} $hCloudToken $cloudToken
  62. ${NSD_GetText} $hCloudRoom $cloudRoom
  63. ${NSD_GetState} $hStartMsys $startMsys
  64. StrLen $0 $cloudToken
  65. StrLen $1 $cloudRoom
  66. ${If} $0 == 125
  67. ${AndIf} $0 == 36
  68. # We should start our new claiming software here
  69. MessageBox MB_OK "$cloudToken | $cloudRoom | $startMsys"
  70. ${EndIf}
  71. ${If} $startMsys == 1
  72. nsExec::ExecToLog '$INSTDIR\msys2.exe'
  73. pop $0
  74. ${EndIf}
  75. FunctionEnd
  76. Function NetdataUninstallRegistry
  77. ClearErrors
  78. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  79. "DisplayName" "Netdata - Real-time system monitoring."
  80. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  81. "DisplayIcon" "$INSTDIR\Uninstall.exe,0"
  82. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  83. "UninstallString" "$INSTDIR\Uninstall.exe"
  84. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  85. "RegOwner" "Netdata Inc."
  86. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  87. "RegCompany" "Netdata Inc."
  88. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  89. "Publisher" "Netdata Inc."
  90. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  91. "HelpLink" "https://learn.netdata.cloud/"
  92. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  93. "URLInfoAbout" "https://www.netdata.cloud/"
  94. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  95. "DisplayVersion" "${CURRVERSION}"
  96. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  97. "VersionMajor" "${MAJORVERSION}"
  98. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  99. "VersionMinor" "${MINORVERSION}"
  100. IfErrors 0 +2
  101. MessageBox MB_ICONEXCLAMATION|MB_OK "Unable to create an entry in the Control Panel!" IDOK end
  102. ClearErrors
  103. ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
  104. IntFmt $0 "0x%08X" $0
  105. WriteRegDWORD HKLM "${ND_UININSTALL_REG}" "EstimatedSize" "$0"
  106. IfErrors 0 +2
  107. MessageBox MB_ICONEXCLAMATION|MB_OK "Cannot estimate the installation size." IDOK end
  108. end:
  109. FunctionEnd
  110. Section "Install Netdata"
  111. SetOutPath $INSTDIR
  112. SetCompress off
  113. File /r "C:\msys64\opt\netdata\*.*"
  114. ClearErrors
  115. nsExec::ExecToLog '$SYSDIR\sc.exe create Netdata binPath= "$INSTDIR\usr\bin\netdata.exe" start= delayed-auto'
  116. pop $0
  117. ${If} $0 != 0
  118. DetailPrint "Warning: Failed to create Netdata service."
  119. ${EndIf}
  120. ClearErrors
  121. nsExec::ExecToLog '$SYSDIR\sc.exe description Netdata "Real-time system monitoring service"'
  122. pop $0
  123. ${If} $0 != 0
  124. DetailPrint "Warning: Failed to add Netdata service description."
  125. ${EndIf}
  126. ClearErrors
  127. nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
  128. pop $0
  129. ${If} $0 != 0
  130. DetailPrint "Warning: Failed to start Netdata service."
  131. ${EndIf}
  132. WriteUninstaller "$INSTDIR\Uninstall.exe"
  133. Call NetdataUninstallRegistry
  134. SectionEnd
  135. Section "Uninstall"
  136. ClearErrors
  137. nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata'
  138. pop $0
  139. ${If} $0 != 0
  140. DetailPrint "Warning: Failed to stop Netdata service."
  141. ${EndIf}
  142. ClearErrors
  143. nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata'
  144. pop $0
  145. ${If} $0 != 0
  146. DetailPrint "Warning: Failed to delete Netdata service."
  147. ${EndIf}
  148. RMDir /r "$INSTDIR"
  149. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
  150. SectionEnd