@cryptotaxi247 / netdata-1 / commits / ebb3e3643

Improve windows installer (#18649)

thiagoftsm committed Oct 9, 2024 at 07:38 UTC ebb3e3643194c0b52cc08b53477a37a87c333009
5 files changed +73 -72
.github/ISSUE_TEMPLATE/BUG_REPORT.yml
+2
@@ -72,6 +72,8 @@ body:
72 uname -a; uname -K
73 # macOS
74 uname -a; sw_vers
75 + # Windows (prompt)
76 + ver
77 ```
78 > NOTE: This will be automatically formatted into code, so no need for backticks.
79 render: shell
CMakeLists.txt
+1 -1
@@ -2357,7 +2357,7 @@ add_executable(netdata
2357
2358 if(OS_WINDOWS)
2359 add_executable(NetdataClaim ${CLAIM_WINDOWS_FILES} ${NETDATA_CLAIM_RES_FILES})
2360 - target_link_libraries(NetdataClaim shell32;gdi32;msftedit)
2360 + target_link_libraries(NetdataClaim shell32 gdi32 msftedit)
2361 target_compile_options(NetdataClaim PUBLIC -mwindows)
2362 endif()
2363
packaging/windows/installer.nsi
+43 -69
@@ -19,8 +19,8 @@ RequestExecutionLevel admin
19 !insertmacro MUI_PAGE_LICENSE "C:\msys64\cloud.txt"
20 !insertmacro MUI_PAGE_LICENSE "C:\msys64\gpl-3.0.txt"
21 !insertmacro MUI_PAGE_DIRECTORY
22 -!insertmacro MUI_PAGE_INSTFILES
22 Page Custom NetdataConfigPage NetdataConfigLeave
23 +!insertmacro MUI_PAGE_INSTFILES
24 !insertmacro MUI_PAGE_FINISH
25
26 !insertmacro MUI_UNPAGE_CONFIRM
@@ -66,6 +66,8 @@ var hCtrlButton
66 var hStartMsys
67 var startMsys
68
69 +var hCloudURL
70 +var cloudURL
71 var hCloudToken
72 var cloudToken
73 var hCloudRooms
@@ -148,7 +150,7 @@ FunctionEnd
150
151 Function ShowHelp
152 Pop $0
151 - MessageBox MB_ICONQUESTION|MB_OK "$\"Proxy URL$\" set the proxy server address to use if your network requires one.$\n$\n$\"Insecure connection$\" disable verification of the server's certificate chain and host name.$\n$\n$\"Open Terminal$\" open MSYS2 terminal to run additional commands after installation." IDOK endHelp
153 + MessageBox MB_ICONQUESTION|MB_OK "$\"Cloud URL$\" The Netdata Cloud base URL.$\n$\n$\"Proxy URL$\" set the proxy server address to use if your network requires one.$\n$\n$\"Insecure connection$\" disable verification of the server's certificate chain and host name.$\n$\n$\"Open Terminal$\" open MSYS2 terminal to run additional commands after installation." IDOK endHelp
154 endHelp:
155 FunctionEnd
156
@@ -181,13 +183,18 @@ Function NetdataConfigPage
183 ${NSD_CreateText} 21% 60% 79% 10% ""
184 Pop $hProxy
185
184 - ${NSD_CreateCheckbox} 0 75% 50% 10u "Insecure connection"
186 + ${NSD_CreateLabel} 0 75% 20% 10% "Cloud URL"
187 + Pop $0
188 + ${NSD_CreateText} 21% 75% 79% 10% "https://app.netdata.cloud"
189 + Pop $hCloudURL
190 +
191 + ${NSD_CreateCheckbox} 0 92% 25% 10u "Insecure connection"
192 Pop $hInsecure
193
187 - ${NSD_CreateCheckbox} 0 90% 50% 10u "Open terminal"
194 + ${NSD_CreateCheckbox} 50% 92% 25% 10u "Open terminal"
195 Pop $hStartMsys
196
190 - ${NSD_CreateButton} 80% 90% 30u 15u "&Help"
197 + ${NSD_CreateButton} 90% 90% 30u 15u "&Help"
198 Pop $hCtrlButton
199 ${NSD_OnClick} $hCtrlButton ShowHelp
200
@@ -204,38 +211,11 @@ FunctionEnd
211 Function NetdataConfigLeave
212 ${If} $avoidClaim == ${BST_UNCHECKED}
213 ${NSD_GetText} $hCloudToken $cloudToken
214 + ${NSD_GetText} $hCloudURL $cloudURL
215 ${NSD_GetText} $hCloudRooms $cloudRooms
216 ${NSD_GetText} $hProxy $proxy
217 ${NSD_GetState} $hStartMsys $startMsys
218 ${NSD_GetState} $hInsecure $insecure
211 -
212 - StrLen $0 $cloudToken
213 - StrLen $1 $cloudRooms
214 - ${If} $0 == 0
215 - ${OrIf} $1 == 0
216 - Goto runMsys
217 - ${EndIf}
218 -
219 - ${If} $0 == 135
220 - ${AndIf} $1 >= 36
221 - nsExec::ExecToLog '$INSTDIR\usr\bin\NetdataClaim.exe /T $cloudToken /R $cloudRooms /P $proxy /I $insecure'
222 - pop $0
223 - ${Else}
224 - MessageBox MB_OK "The Cloud information does not have the expected length."
225 - ${EndIf}
226 -
227 - runMsys:
228 - ${If} $startMsys == ${BST_CHECKED}
229 - nsExec::ExecToLog '$INSTDIR\msys2.exe'
230 - pop $0
231 - ${EndIf}
232 - ${EndIf}
233 -
234 - ClearErrors
235 - nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
236 - pop $0
237 - ${If} $0 != 0
238 - MessageBox MB_OK "Warning: Failed to start Netdata service."
219 ${EndIf}
220 FunctionEnd
221
@@ -297,44 +277,37 @@ Section "Install Netdata"
277 DetailPrint "Warning: Failed to add Netdata service description."
278 ${EndIf}
279
300 - WriteUninstaller "$INSTDIR\Uninstall.exe"
280 + WriteUninstaller "$INSTDIR\Uninstall.exe"
281
282 Call NetdataUninstallRegistry
283
304 - IfSilent runcmds goodbye
305 - runcmds:
306 - nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
307 - pop $0
308 -
309 - System::Call 'kernel32::AttachConsole(i -1)i.r0'
310 - ${If} $0 != 0
311 - System::Call 'kernel32::GetStdHandle(i -11)i.r0'
312 - FileWrite $0 "Netdata installed with success.$\r$\n"
313 - ${EndIf}
314 - ${If} $startMsys == ${BST_CHECKED}
315 - nsExec::ExecToLog '$INSTDIR\msys2.exe'
316 - pop $0
317 - ${EndIf}
318 -
319 - StrLen $0 $cloudToken
320 - StrLen $1 $cloudRooms
321 - ${If} $0 == 0
322 - ${OrIf} $1 == 0
323 - Goto goodbye
324 - ${EndIf}
325 -
326 - ${If} $0 == 135
327 - ${AndIf} $1 >= 36
328 - nsExec::ExecToLog '$INSTDIR\usr\bin\NetdataClaim.exe /T $cloudToken /R $cloudRooms /P $proxy /I $insecure'
329 - pop $0
330 - ${Else}
331 - System::Call 'kernel32::AttachConsole(i -1)i.r0'
332 - ${If} $0 != 0
333 - System::Call 'kernel32::GetStdHandle(i -11)i.r0'
334 - FileWrite $0 "Room(s) or Token invalid.$\r$\n"
335 - ${EndIf}
336 - ${EndIf}
337 - goodbye:
284 + StrLen $0 $cloudToken
285 + StrLen $1 $cloudRooms
286 + ${If} $0 == 0
287 + ${OrIf} $1 == 0
288 + Goto runCmds
289 + ${EndIf}
290 +
291 + ${If} $0 == 135
292 + ${AndIf} $1 >= 36
293 + nsExec::ExecToLog '$INSTDIR\usr\bin\NetdataClaim.exe /T $cloudToken /R $cloudRooms /P $proxy /I $insecure /U $cloudURL'
294 + pop $0
295 + ${Else}
296 + MessageBox MB_OK "The Cloud information does not have the expected length."
297 + ${EndIf}
298 +
299 + runCmds:
300 + ClearErrors
301 + nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
302 + pop $0
303 + ${If} $0 != 0
304 + MessageBox MB_OK "Warning: Failed to start Netdata service."
305 + ${EndIf}
306 +
307 + ${If} $startMsys == ${BST_CHECKED}
308 + nsExec::ExecToLog '$INSTDIR\msys2.exe'
309 + pop $0
310 + ${EndIf}
311 SectionEnd
312
313 Section "Uninstall"
@@ -352,7 +325,8 @@ Section "Uninstall"
325 DetailPrint "Warning: Failed to delete Netdata service."
326 ${EndIf}
327
355 - RMDir /r "$INSTDIR"
328 + # https://nsis.sourceforge.io/Reference/RMDir
329 + RMDir /r /REBOOTOK "$INSTDIR"
330
331 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
332 SectionEnd
src/claim/main.c
+25 -1
@@ -14,11 +14,13 @@
14 LPWSTR token = NULL;
15 LPWSTR room = NULL;
16 LPWSTR proxy = NULL;
17 +LPWSTR url = NULL;
18 LPWSTR *argv = NULL;
19
20 char *aToken = NULL;
21 char *aRoom = NULL;
22 char *aProxy = NULL;
23 +char *aURL = NULL;
24 int insecure = 0;
25
26 LPWSTR netdata_claim_get_formatted_message(LPWSTR pMessage, ...)
@@ -89,6 +91,13 @@ int nd_claim_parse_args(int argc, LPWSTR *argv)
91 }
92 }
93
94 + if(wcscasecmp(L"/U", argv[i]) == 0) {
95 + if (argc <= i + 1)
96 + continue;
97 + i++;
98 + url = argv[i];
99 + }
100 +
101 if(wcscasecmp(L"/I", argv[i]) == 0) {
102 if (argc <= i + 1)
103 continue;
@@ -142,6 +151,15 @@ static int netdata_claim_prepare_strings()
151
152 netdata_claim_convert_str(aProxy, proxy, length - 1);
153 }
154 +
155 + if (url) {
156 + length = wcslen(url) + 1;
157 + aURL = calloc(sizeof(char), length - 1);
158 + if (!aURL)
159 + return -1;
160 +
161 + netdata_claim_convert_str(aURL, url, length - 1);
162 + }
163 return 0;
164 }
165
@@ -157,6 +175,9 @@ static void netdata_claim_exit_callback(int signal)
175 if (aProxy)
176 free(aProxy);
177
178 + if (aURL)
179 + free(aURL);
180 +
181 if (argv)
182 LocalFree(argv);
183 }
@@ -165,9 +186,12 @@ static inline int netdata_claim_prepare_data(char *out, size_t length)
186 {
187 char *proxyLabel = (aProxy) ? "proxy = " : "# proxy = ";
188 char *proxyValue = (aProxy) ? aProxy : "";
189 +
190 + char *urlValue = (aURL) ? aURL : "https://app.netdata.cloud";
191 return snprintf(out,
192 length,
170 - "[global]\n url = https://app.netdata.cloud\n token = %s\n rooms = %s\n %s%s\n insecure = %s",
193 + "[global]\n url = %s\n token = %s\n rooms = %s\n %s%s\n insecure = %s",
194 + urlValue,
195 aToken,
196 aRoom,
197 proxyLabel,
src/claim/ui.c
+2 -1
@@ -25,6 +25,7 @@ LRESULT CALLBACK WndProc(HWND hNetdatawnd, UINT message, WPARAM wParam, LPARAM l
25 L"/T TOKEN: The cloud token;",
26 L"/R ROOMS: A list of rooms to claim;",
27 L"/P PROXY: The proxy information;",
28 + L"/U URL : The cloud URL;",
29 L"/I : Use insecure connection;"
30 };
31
@@ -83,7 +84,7 @@ int netdata_claim_window_loop(HINSTANCE hInstance, int nCmdShow)
84 L"Netdata Claim",
85 WS_OVERLAPPEDWINDOW,
86 CW_USEDEFAULT, CW_USEDEFAULT,
86 - 460, 220,
87 + 460, 240,
88 NULL,
89 NULL,
90 hInstance,