installer.nsi 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 hCloudRooms
  29. var cloudRooms
  30. var hProxy
  31. var proxy
  32. var hInsecure
  33. var insecure
  34. var avoidClaim
  35. Function .onInit
  36. nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata'
  37. pop $0
  38. ${If} $0 == 0
  39. nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata'
  40. pop $0
  41. ${EndIf}
  42. StrCpy $startMsys ${BST_UNCHECKED}
  43. StrCpy $insecure ${BST_UNCHECKED}
  44. StrCpy $avoidClaim ${BST_UNCHECKED}
  45. FunctionEnd
  46. Function NetdataConfigPage
  47. !insertmacro MUI_HEADER_TEXT "Netdata configuration" "Claim your agent on Netdata Cloud"
  48. nsDialogs::Create 1018
  49. Pop $0
  50. ${If} $0 == error
  51. Abort
  52. ${EndIf}
  53. IfFileExists "$INSTDIR\etc\netdata\claim.conf" NotNeeded
  54. ${NSD_CreateLabel} 0 0 100% 12u "Enter your Token and Cloud Room(s)."
  55. ${NSD_CreateLabel} 0 15% 100% 12u "Optionally, you can open a terminal to execute additional commands."
  56. ${NSD_CreateLabel} 0 30% 20% 10% "Token"
  57. Pop $0
  58. ${NSD_CreateText} 21% 30% 79% 10% ""
  59. Pop $hCloudToken
  60. ${NSD_CreateLabel} 0 45% 20% 10% "Room(s)"
  61. Pop $0
  62. ${NSD_CreateText} 21% 45% 79% 10% ""
  63. Pop $hCloudRooms
  64. ${NSD_CreateLabel} 0 60% 20% 10% "Proxy"
  65. Pop $0
  66. ${NSD_CreateText} 21% 60% 79% 10% ""
  67. Pop $hProxy
  68. ${NSD_CreateCheckbox} 0 75% 100% 10u "Insecure connection"
  69. Pop $hInsecure
  70. ${NSD_CreateCheckbox} 0 90% 100% 10u "Open terminal"
  71. Pop $hStartMsys
  72. Goto EndDialogDraw
  73. NotNeeded:
  74. StrCpy $avoidClaim ${BST_CHECKED}
  75. ${NSD_CreateLabel} 0 0 100% 12u "Your host has already been claimed. You can proceed with the update."
  76. EndDialogDraw:
  77. nsDialogs::Show
  78. FunctionEnd
  79. Function NetdataConfigLeave
  80. ${If} $avoidClaim == ${BST_UNCHECKED}
  81. ${NSD_GetText} $hCloudToken $cloudToken
  82. ${NSD_GetText} $hCloudRooms $cloudRooms
  83. ${NSD_GetText} $hProxy $proxy
  84. ${NSD_GetState} $hStartMsys $startMsys
  85. ${NSD_GetState} $hInsecure $insecure
  86. StrLen $0 $cloudToken
  87. StrLen $1 $cloudRooms
  88. ${If} $0 == 0
  89. ${OrIf} $1 == 0
  90. Goto runMsys
  91. ${EndIf}
  92. ${If} $0 == 135
  93. ${AndIf} $1 >= 36
  94. nsExec::ExecToLog '$INSTDIR\usr\bin\NetdataClaim.exe /T $cloudToken /R $cloudRooms /P $proxy /I $insecure'
  95. pop $0
  96. ${Else}
  97. MessageBox MB_OK "The Cloud information does not have the expected length."
  98. ${EndIf}
  99. runMsys:
  100. ${If} $startMsys == ${BST_CHECKED}
  101. nsExec::ExecToLog '$INSTDIR\msys2.exe'
  102. pop $0
  103. ${EndIf}
  104. ${EndIf}
  105. ClearErrors
  106. nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
  107. pop $0
  108. ${If} $0 != 0
  109. MessageBox MB_OK "Warning: Failed to start Netdata service."
  110. ${EndIf}
  111. FunctionEnd
  112. Function NetdataUninstallRegistry
  113. ClearErrors
  114. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  115. "DisplayName" "Netdata - Real-time system monitoring."
  116. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  117. "DisplayIcon" "$INSTDIR\Uninstall.exe,0"
  118. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  119. "UninstallString" "$INSTDIR\Uninstall.exe"
  120. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  121. "RegOwner" "Netdata Inc."
  122. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  123. "RegCompany" "Netdata Inc."
  124. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  125. "Publisher" "Netdata Inc."
  126. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  127. "HelpLink" "https://learn.netdata.cloud/"
  128. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  129. "URLInfoAbout" "https://www.netdata.cloud/"
  130. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  131. "DisplayVersion" "${CURRVERSION}"
  132. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  133. "VersionMajor" "${MAJORVERSION}"
  134. WriteRegStr HKLM "${ND_UININSTALL_REG}" \
  135. "VersionMinor" "${MINORVERSION}"
  136. IfErrors 0 +2
  137. MessageBox MB_ICONEXCLAMATION|MB_OK "Unable to create an entry in the Control Panel!" IDOK end
  138. ClearErrors
  139. ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
  140. IntFmt $0 "0x%08X" $0
  141. WriteRegDWORD HKLM "${ND_UININSTALL_REG}" "EstimatedSize" "$0"
  142. IfErrors 0 +2
  143. MessageBox MB_ICONEXCLAMATION|MB_OK "Cannot estimate the installation size." IDOK end
  144. end:
  145. FunctionEnd
  146. Section "Install Netdata"
  147. SetOutPath $INSTDIR
  148. SetCompress off
  149. File /r "C:\msys64\opt\netdata\*.*"
  150. ClearErrors
  151. nsExec::ExecToLog '$SYSDIR\sc.exe create Netdata binPath= "$INSTDIR\usr\bin\netdata.exe" start= delayed-auto'
  152. pop $0
  153. ${If} $0 != 0
  154. DetailPrint "Warning: Failed to create Netdata service."
  155. ${EndIf}
  156. ClearErrors
  157. nsExec::ExecToLog '$SYSDIR\sc.exe description Netdata "Real-time system monitoring service"'
  158. pop $0
  159. ${If} $0 != 0
  160. DetailPrint "Warning: Failed to add Netdata service description."
  161. ${EndIf}
  162. WriteUninstaller "$INSTDIR\Uninstall.exe"
  163. Call NetdataUninstallRegistry
  164. SectionEnd
  165. Section "Uninstall"
  166. ClearErrors
  167. nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata'
  168. pop $0
  169. ${If} $0 != 0
  170. DetailPrint "Warning: Failed to stop Netdata service."
  171. ${EndIf}
  172. ClearErrors
  173. nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata'
  174. pop $0
  175. ${If} $0 != 0
  176. DetailPrint "Warning: Failed to delete Netdata service."
  177. ${EndIf}
  178. RMDir /r "$INSTDIR"
  179. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
  180. SectionEnd