Browse Source

Improve windows installer (#18649)

thiagoftsm 5 months ago
parent
commit
ebb3e36431
5 changed files with 73 additions and 72 deletions
  1. 2 0
      .github/ISSUE_TEMPLATE/BUG_REPORT.yml
  2. 1 1
      CMakeLists.txt
  3. 43 69
      packaging/windows/installer.nsi
  4. 25 1
      src/claim/main.c
  5. 2 1
      src/claim/ui.c

+ 2 - 0
.github/ISSUE_TEMPLATE/BUG_REPORT.yml

@@ -72,6 +72,8 @@ body:
         uname -a; uname -K
         # macOS
         uname -a; sw_vers
+        # Windows (prompt)
+        ver
         ```
         > NOTE: This will be automatically formatted into code, so no need for backticks.
       render: shell

+ 1 - 1
CMakeLists.txt

@@ -2357,7 +2357,7 @@ add_executable(netdata
 
 if(OS_WINDOWS)
         add_executable(NetdataClaim ${CLAIM_WINDOWS_FILES} ${NETDATA_CLAIM_RES_FILES})
-        target_link_libraries(NetdataClaim shell32;gdi32;msftedit)
+        target_link_libraries(NetdataClaim shell32 gdi32 msftedit)
         target_compile_options(NetdataClaim PUBLIC -mwindows)
 endif()
 

+ 43 - 69
packaging/windows/installer.nsi

@@ -19,8 +19,8 @@ RequestExecutionLevel admin
 !insertmacro MUI_PAGE_LICENSE "C:\msys64\cloud.txt"
 !insertmacro MUI_PAGE_LICENSE "C:\msys64\gpl-3.0.txt"
 !insertmacro MUI_PAGE_DIRECTORY
-!insertmacro MUI_PAGE_INSTFILES
 Page Custom NetdataConfigPage NetdataConfigLeave
+!insertmacro MUI_PAGE_INSTFILES
 !insertmacro MUI_PAGE_FINISH
 
 !insertmacro MUI_UNPAGE_CONFIRM
@@ -66,6 +66,8 @@ var hCtrlButton
 var hStartMsys
 var startMsys
 
+var hCloudURL
+var cloudURL
 var hCloudToken
 var cloudToken
 var hCloudRooms
@@ -148,7 +150,7 @@ FunctionEnd
 
 Function ShowHelp
 Pop $0
-        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
+        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
         endHelp:
 FunctionEnd
 
@@ -181,13 +183,18 @@ Function NetdataConfigPage
         ${NSD_CreateText} 21% 60% 79% 10% ""
         Pop $hProxy
 
-        ${NSD_CreateCheckbox} 0 75% 50% 10u "Insecure connection"
+        ${NSD_CreateLabel} 0 75% 20% 10% "Cloud URL"
+        Pop $0
+        ${NSD_CreateText} 21% 75% 79% 10% "https://app.netdata.cloud"
+        Pop $hCloudURL
+
+        ${NSD_CreateCheckbox} 0 92% 25% 10u "Insecure connection"
         Pop $hInsecure
 
-        ${NSD_CreateCheckbox} 0 90% 50% 10u "Open terminal"
+        ${NSD_CreateCheckbox} 50% 92% 25% 10u "Open terminal"
         Pop $hStartMsys
 
-        ${NSD_CreateButton} 80% 90% 30u 15u "&Help"
+        ${NSD_CreateButton} 90% 90% 30u 15u "&Help"
         Pop $hCtrlButton
         ${NSD_OnClick} $hCtrlButton ShowHelp
 
@@ -204,38 +211,11 @@ FunctionEnd
 Function NetdataConfigLeave
         ${If} $avoidClaim == ${BST_UNCHECKED}
                 ${NSD_GetText} $hCloudToken $cloudToken
+                ${NSD_GetText} $hCloudURL $cloudURL
                 ${NSD_GetText} $hCloudRooms $cloudRooms
                 ${NSD_GetText} $hProxy $proxy
                 ${NSD_GetState} $hStartMsys $startMsys
                 ${NSD_GetState} $hInsecure $insecure
-
-                StrLen $0 $cloudToken
-                StrLen $1 $cloudRooms
-                ${If} $0 == 0
-                ${OrIf} $1 == 0
-                        Goto runMsys
-                ${EndIf}
-
-                ${If} $0 == 135
-                ${AndIf} $1 >= 36
-                        nsExec::ExecToLog '$INSTDIR\usr\bin\NetdataClaim.exe /T $cloudToken /R $cloudRooms /P $proxy /I $insecure'
-                        pop $0
-                ${Else}
-                        MessageBox MB_OK "The Cloud information does not have the expected length."
-                ${EndIf}
-
-                runMsys:
-                ${If} $startMsys == ${BST_CHECKED}
-                        nsExec::ExecToLog '$INSTDIR\msys2.exe'
-                        pop $0
-                ${EndIf}
-        ${EndIf}
-
-        ClearErrors
-        nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
-        pop $0
-        ${If} $0 != 0
-	        MessageBox MB_OK "Warning: Failed to start Netdata service."
         ${EndIf}
 FunctionEnd
 
@@ -297,44 +277,37 @@ Section "Install Netdata"
 	    DetailPrint "Warning: Failed to add Netdata service description."
         ${EndIf}
 
-	WriteUninstaller "$INSTDIR\Uninstall.exe"
+        WriteUninstaller "$INSTDIR\Uninstall.exe"
 
         Call NetdataUninstallRegistry
 
-        IfSilent runcmds goodbye
-        runcmds:
-           nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
-           pop $0
-
-           System::Call 'kernel32::AttachConsole(i -1)i.r0'
-           ${If} $0 != 0
-                System::Call 'kernel32::GetStdHandle(i -11)i.r0'
-                FileWrite $0 "Netdata installed with success.$\r$\n"
-           ${EndIf}
-           ${If} $startMsys == ${BST_CHECKED}
-                   nsExec::ExecToLog '$INSTDIR\msys2.exe'
-                   pop $0
-           ${EndIf}
-
-           StrLen $0 $cloudToken
-           StrLen $1 $cloudRooms
-           ${If} $0 == 0
-           ${OrIf} $1 == 0
-                   Goto goodbye
-           ${EndIf}
-
-           ${If} $0 == 135
-           ${AndIf} $1 >= 36
-                    nsExec::ExecToLog '$INSTDIR\usr\bin\NetdataClaim.exe /T $cloudToken /R $cloudRooms /P $proxy /I $insecure'
-                    pop $0
-           ${Else}         
-                    System::Call 'kernel32::AttachConsole(i -1)i.r0'
-                    ${If} $0 != 0
-                        System::Call 'kernel32::GetStdHandle(i -11)i.r0'
-                        FileWrite $0 "Room(s) or Token invalid.$\r$\n"
-                    ${EndIf}
-           ${EndIf}
-        goodbye:
+        StrLen $0 $cloudToken
+        StrLen $1 $cloudRooms
+        ${If} $0 == 0
+        ${OrIf} $1 == 0
+                Goto runCmds
+        ${EndIf}
+
+        ${If} $0 == 135
+        ${AndIf} $1 >= 36
+                nsExec::ExecToLog '$INSTDIR\usr\bin\NetdataClaim.exe /T $cloudToken /R $cloudRooms /P $proxy /I $insecure /U $cloudURL'
+                pop $0
+        ${Else}
+                MessageBox MB_OK "The Cloud information does not have the expected length."
+        ${EndIf}
+
+        runCmds:
+        ClearErrors
+        nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
+        pop $0
+        ${If} $0 != 0
+	        MessageBox MB_OK "Warning: Failed to start Netdata service."
+        ${EndIf}
+
+        ${If} $startMsys == ${BST_CHECKED}
+                nsExec::ExecToLog '$INSTDIR\msys2.exe'
+                pop $0
+        ${EndIf}
 SectionEnd
 
 Section "Uninstall"
@@ -352,7 +325,8 @@ Section "Uninstall"
 	    DetailPrint "Warning: Failed to delete Netdata service."
         ${EndIf}
 
-	RMDir /r "$INSTDIR"
+        # https://nsis.sourceforge.io/Reference/RMDir
+	RMDir /r /REBOOTOK "$INSTDIR"
 
         DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
 SectionEnd

+ 25 - 1
src/claim/main.c

@@ -14,11 +14,13 @@
 LPWSTR token = NULL;
 LPWSTR room = NULL;
 LPWSTR proxy = NULL;
+LPWSTR url = NULL;
 LPWSTR *argv = NULL;
 
 char *aToken = NULL;
 char *aRoom = NULL;
 char *aProxy = NULL;
+char *aURL = NULL;
 int insecure = 0;
 
 LPWSTR netdata_claim_get_formatted_message(LPWSTR pMessage, ...)
@@ -89,6 +91,13 @@ int nd_claim_parse_args(int argc, LPWSTR *argv)
             }
         }
 
+        if(wcscasecmp(L"/U", argv[i]) == 0) {
+            if (argc <= i + 1)
+                continue;
+            i++;
+            url = argv[i];
+        }
+
         if(wcscasecmp(L"/I", argv[i]) == 0) {
             if (argc <= i + 1)
                 continue;
@@ -142,6 +151,15 @@ static int netdata_claim_prepare_strings()
 
         netdata_claim_convert_str(aProxy, proxy, length - 1);
     }
+
+    if (url) {
+        length = wcslen(url) + 1;
+        aURL = calloc(sizeof(char), length - 1);
+        if (!aURL)
+            return -1;
+
+        netdata_claim_convert_str(aURL, url, length - 1);
+    }
     return 0;
 }
 
@@ -157,6 +175,9 @@ static void netdata_claim_exit_callback(int signal)
     if (aProxy)
         free(aProxy);
 
+    if (aURL)
+        free(aURL);
+
     if (argv)
         LocalFree(argv);
 }
@@ -165,9 +186,12 @@ static inline int netdata_claim_prepare_data(char *out, size_t length)
 {
     char *proxyLabel = (aProxy) ? "proxy = " : "#    proxy = ";
     char *proxyValue = (aProxy) ? aProxy : "";
+
+    char *urlValue = (aURL) ? aURL : "https://app.netdata.cloud";
     return snprintf(out,
                     length,
-                    "[global]\n    url = https://app.netdata.cloud\n    token = %s\n    rooms = %s\n    %s%s\n    insecure = %s",
+                    "[global]\n    url = %s\n    token = %s\n    rooms = %s\n    %s%s\n    insecure = %s",
+                    urlValue,
                     aToken,
                     aRoom,
                     proxyLabel,

+ 2 - 1
src/claim/ui.c

@@ -25,6 +25,7 @@ LRESULT CALLBACK WndProc(HWND hNetdatawnd, UINT message, WPARAM wParam, LPARAM l
                          L"/T TOKEN: The cloud token;",
                          L"/R ROOMS: A list of rooms to claim;",
                          L"/P PROXY: The proxy information;",
+                         L"/U URL  : The cloud URL;",
                          L"/I      : Use insecure connection;"
     };
 
@@ -83,7 +84,7 @@ int netdata_claim_window_loop(HINSTANCE hInstance, int nCmdShow)
                                       L"Netdata Claim",
                                       WS_OVERLAPPEDWINDOW,
                                       CW_USEDEFAULT, CW_USEDEFAULT,
-                                      460, 220,
+                                      460, 240,
                                       NULL,
                                       NULL,
                                       hInstance,