@cryptotaxi247 / netdata-1 / commits / 59d806e23

Windows Installer (Silent mode) (#18613)

thiagoftsm committed Oct 1, 2024 at 18:24 UTC 59d806e23ba8c0f0f30ced872e3f4c31c0697688
3 files changed +174 -128
packaging/installer/installer.nsi deleted
-128
@@ -1,128 +0,0 @@
1 -!include "MUI2.nsh"
2 -!include "nsDialogs.nsh"
3 -!include "FileFunc.nsh"
4 -
5 -Name "Netdata"
6 -Outfile "netdata-installer.exe"
7 -InstallDir "$PROGRAMFILES\Netdata"
8 -RequestExecutionLevel admin
9 -
10 -!define MUI_ICON "NetdataWhite.ico"
11 -!define MUI_UNICON "NetdataWhite.ico"
12 -
13 -!define ND_UININSTALL_REG "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
14 -
15 -!define MUI_ABORTWARNING
16 -!define MUI_UNABORTWARNING
17 -
18 -!insertmacro MUI_PAGE_WELCOME
19 -!insertmacro MUI_PAGE_LICENSE "C:\msys64\gpl-3.0.txt"
20 -!insertmacro MUI_PAGE_DIRECTORY
21 -!insertmacro MUI_PAGE_INSTFILES
22 -!insertmacro MUI_PAGE_FINISH
23 -
24 -!insertmacro MUI_UNPAGE_CONFIRM
25 -!insertmacro MUI_UNPAGE_INSTFILES
26 -!insertmacro MUI_UNPAGE_FINISH
27 -
28 -!insertmacro MUI_LANGUAGE "English"
29 -
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 -FunctionEnd
38 -
39 -Function NetdataUninstallRegistry
40 - ClearErrors
41 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
42 - "DisplayName" "Netdata - Real-time system monitoring."
43 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
44 - "DisplayIcon" "$INSTDIR\Uninstall.exe,0"
45 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
46 - "UninstallString" "$INSTDIR\Uninstall.exe"
47 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
48 - "RegOwner" "Netdata Inc."
49 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
50 - "RegCompany" "Netdata Inc."
51 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
52 - "Publisher" "Netdata Inc."
53 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
54 - "HelpLink" "https://learn.netdata.cloud/"
55 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
56 - "URLInfoAbout" "https://www.netdata.cloud/"
57 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
58 - "DisplayVersion" "${CURRVERSION}"
59 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
60 - "VersionMajor" "${MAJORVERSION}"
61 - WriteRegStr HKLM "${ND_UININSTALL_REG}" \
62 - "VersionMinor" "${MINORVERSION}"
63 -
64 - IfErrors 0 +2
65 - MessageBox MB_ICONEXCLAMATION|MB_OK "Unable to create an entry in the Control Panel!" IDOK end
66 -
67 - ClearErrors
68 - ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
69 - IntFmt $0 "0x%08X" $0
70 - WriteRegDWORD HKLM "${ND_UININSTALL_REG}" "EstimatedSize" "$0"
71 -
72 - IfErrors 0 +2
73 - MessageBox MB_ICONEXCLAMATION|MB_OK "Cannot estimate the installation size." IDOK end
74 - end:
75 -FunctionEnd
76 -
77 -Section "Install Netdata"
78 - SetOutPath $INSTDIR
79 - SetCompress off
80 -
81 - File /r "C:\msys64\opt\netdata\*.*"
82 -
83 - ClearErrors
84 - nsExec::ExecToLog '$SYSDIR\sc.exe create Netdata binPath= "$INSTDIR\usr\bin\netdata.exe" start= delayed-auto'
85 - pop $0
86 - ${If} $0 != 0
87 - DetailPrint "Warning: Failed to create Netdata service."
88 - ${EndIf}
89 -
90 - ClearErrors
91 - nsExec::ExecToLog '$SYSDIR\sc.exe description Netdata "Real-time system monitoring service"'
92 - pop $0
93 - ${If} $0 != 0
94 - DetailPrint "Warning: Failed to add Netdata service description."
95 - ${EndIf}
96 -
97 - ClearErrors
98 - nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
99 - pop $0
100 - ${If} $0 != 0
101 - DetailPrint "Warning: Failed to start Netdata service."
102 - ${EndIf}
103 -
104 - WriteUninstaller "$INSTDIR\Uninstall.exe"
105 -
106 - Call NetdataUninstallRegistry
107 -SectionEnd
108 -
109 -Section "Uninstall"
110 - ClearErrors
111 - nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata'
112 - pop $0
113 - ${If} $0 != 0
114 - DetailPrint "Warning: Failed to stop Netdata service."
115 - ${EndIf}
116 -
117 - ClearErrors
118 - nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata'
119 - pop $0
120 - ${If} $0 != 0
121 - DetailPrint "Warning: Failed to delete Netdata service."
122 - ${EndIf}
123 -
124 - RMDir /r "$INSTDIR"
125 -
126 - DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
127 -SectionEnd
128 -
packaging/windows/WINDOWS_INSTALLER.md new
+50
@@ -0,0 +1,50 @@
1 +# Netdata Windows Installer
2 +
3 +Netdata offers a convenient Windows installer for easy setup. This executable provides two distinct installation modes, outlined below.
4 +
5 +## Graphical User Interface (GUI)
6 +
7 +Double-clicking the installer initiates the setup process. Since Netdata adds a service to your system, you'll need to provide administrator privileges.
8 +The installer will then guide you through these steps:
9 +
10 +1. **Welcome**: This screen provides a summary of the actions the installer will perform.
11 +2. **License Agreements**:
12 + - [Netdata Cloud UI License](/src/web/gui/v2/LICENSE.md): Review and accept the license terms to proceed.
13 + - [GPLv3 License](/LICENSE): Read the GNU General Public License v3, which governs the Netdata software.
14 +3. **Destination**: Choose the installation directory. By default, Netdata installs in `C:\Program Files\Netdata`.
15 +4. **Installation**: The installer will copy the necessary files to the chosen directory.
16 +5. **Claiming**: [Connecting](/src/claim/README.md) your Netdata Agent to your Netdata Cloud Space. Here's what you can configure:
17 + - **Token**: The claiming token for your Netdata Cloud Space.
18 + - **Rooms**: Specify the Room IDs where you want your node to appear (comma-separated list).
19 + - **Proxy**: Enter the address of a proxy server if required for communication with Netdata Cloud.
20 + - **Insecure connection**: By default, Netdata verifies the server's certificate. Enabling this option bypasses verification (use only if necessary).
21 + - **Open Terminal**: Select this option to launch the `MSYS2` terminal after installation completes.
22 +6. **Finish**: The installation process is complete!
23 +
24 +## Silent Mode
25 +
26 +This section provides instructions for installing Netdata in silent mode, which is ideal for automated deployments.
27 +Silent mode skips displaying license agreements, but requires explicitly accepting them using the `/A` option.
28 +
29 +**Available Options**:
30 +
31 +| Option | Description |
32 +|-----------|--------------------------------------------------------------------------------------------------|
33 +| `/S` | Enables silent mode installation. |
34 +| `/A` | Accepts all Netdata licenses. This option is mandatory for silent installations. |
35 +| `/D` | Specifies the desired installation directory (defaults to `C:\Program Files\Netdata`). |
36 +| `/T` | Opens the `MSYS2` terminal after installation. |
37 +| `/I` | Forces insecure connections, bypassing hostname verification (use only if absolutely necessary). |
38 +| `/TOKEN=` | Sets the claiming token for your Netdata Cloud Space. |
39 +| `/ROOMS=` | Comma-separated list of Room IDs where you want your node to appear. |
40 +| `/PROXY=` | Sets the proxy server address if your network requires one. |
41 +
42 +**Example Usage**
43 +
44 +Connect your Agent to your Netdata Cloud Space with token `<YOUR_TOKEN>` and room `<YOUR_ROOM>`:
45 +
46 +```bash
47 +netdata-installer.exe /S /A /TOKEN=<YOUR_TOKEN> /ROOMS=<YOUR_ROOM>
48 +```
49 +
50 +Replace `<YOUR_TOKEN>` and `<YOUR_ROOM>` with your actual Netdata Cloud Space claim token and room ID, respectively.
packaging/windows/installer.nsi
+124
@@ -29,6 +29,39 @@ Page Custom NetdataConfigPage NetdataConfigLeave
29
30 !insertmacro MUI_LANGUAGE "English"
31
32 +!define INSTALLERLOCKFILEGUID "f787d5ef-5c41-4dc0-a115-a1fb654fad1c"
33 +
34 +# https://nsis.sourceforge.io/Allow_only_one_installer_instance
35 +!macro SingleInstanceFile
36 + !if "${NSIS_PTR_SIZE}" > 4
37 + !include "Util.nsh"
38 + !else ifndef IntPtrCmp
39 + !define IntPtrCmp IntCmp
40 + !endif
41 +
42 + !ifndef NSIS_PTR_SIZE & SYSTYPE_PTR
43 + !define SYSTYPE_PTR i ; NSIS v2.x
44 + !else
45 + !define /ifndef SYSTYPE_PTR p ; NSIS v3.0+
46 + !endif
47 +
48 + !if "${NSIS_CHAR_SIZE}" < 2
49 + Push "$TEMP\${INSTALLERLOCKFILEGUID}.lock"
50 + !else
51 + Push "$APPDATA\${INSTALLERLOCKFILEGUID}.lock"
52 + !endif
53 +
54 + System::Call 'KERNEL32::CreateFile(ts,i0x40000000,i0,${SYSTYPE_PTR}0,i4,i0x04000000,${SYSTYPE_PTR}0)${SYSTYPE_PTR}.r0'
55 + ${IntPtrCmp} $0 -1 "" launch launch
56 + System::Call 'kernel32::AttachConsole(i -1)i.r0'
57 + ${If} $0 != 0
58 + System::Call 'kernel32::GetStdHandle(i -11)i.r0'
59 + FileWrite $0 "The installer is already running.$\r$\n"
60 + ${EndIf}
61 + Quit
62 + launch:
63 +!macroend
64 +
65 var hStartMsys
66 var startMsys
67
@@ -40,10 +73,13 @@ var hProxy
73 var proxy
74 var hInsecure
75 var insecure
76 +var accepted
77
78 var avoidClaim
79
80 Function .onInit
81 + !insertmacro SingleInstanceFile
82 +
83 nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata'
84 pop $0
85 ${If} $0 == 0
@@ -54,6 +90,59 @@ Function .onInit
90 StrCpy $startMsys ${BST_UNCHECKED}
91 StrCpy $insecure ${BST_UNCHECKED}
92 StrCpy $avoidClaim ${BST_UNCHECKED}
93 + StrCpy $accepted ${BST_UNCHECKED}
94 +
95 + ${GetParameters} $R0
96 + ${GetOptions} $R0 "/s" $0
97 + IfErrors +2 0
98 + SetSilent silent
99 + ClearErrors
100 +
101 + ${GetOptions} $R0 "/t" $0
102 + IfErrors +2 0
103 + StrCpy $startMsys ${BST_CHECKED}
104 + ClearErrors
105 +
106 + ${GetOptions} $R0 "/i" $0
107 + IfErrors +2 0
108 + StrCpy $insecure ${BST_CHECKED}
109 + ClearErrors
110 +
111 + ${GetOptions} $R0 "/a" $0
112 + IfErrors +2 0
113 + StrCpy $accepted ${BST_CHECKED}
114 + ClearErrors
115 +
116 + ${GetOptions} $R0 "/token=" $0
117 + IfErrors +2 0
118 + StrCpy $cloudToken $0
119 + ClearErrors
120 +
121 + ${GetOptions} $R0 "/rooms=" $0
122 + IfErrors +2 0
123 + StrCpy $cloudRooms $0
124 + ClearErrors
125 +
126 + ${GetOptions} $R0 "/proxy=" $0
127 + IfErrors +2 0
128 + StrCpy $proxy $0
129 + ClearErrors
130 +
131 + IfSilent checklicense goahead
132 + checklicense:
133 + ${If} $accepted == ${BST_UNCHECKED}
134 + System::Call 'kernel32::AttachConsole(i -1)i.r0'
135 + ${If} $0 != 0
136 + System::Call 'kernel32::GetStdHandle(i -11)i.r0'
137 + FileWrite $0 "You must accept the licenses (/A) to continue.$\r$\n"
138 + ${EndIf}
139 + Quit
140 + ${EndIf}
141 + goahead:
142 +FunctionEnd
143 +
144 +Function un.onInit
145 +!insertmacro SingleInstanceFile
146 FunctionEnd
147
148 Function NetdataConfigPage
@@ -199,6 +288,41 @@ Section "Install Netdata"
288 WriteUninstaller "$INSTDIR\Uninstall.exe"
289
290 Call NetdataUninstallRegistry
291 +
292 + IfSilent runcmds goodbye
293 + runcmds:
294 + nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
295 + pop $0
296 +
297 + System::Call 'kernel32::AttachConsole(i -1)i.r0'
298 + ${If} $0 != 0
299 + System::Call 'kernel32::GetStdHandle(i -11)i.r0'
300 + FileWrite $0 "Netdata installed with success.$\r$\n"
301 + ${EndIf}
302 + ${If} $startMsys == ${BST_CHECKED}
303 + nsExec::ExecToLog '$INSTDIR\msys2.exe'
304 + pop $0
305 + ${EndIf}
306 +
307 + StrLen $0 $cloudToken
308 + StrLen $1 $cloudRooms
309 + ${If} $0 == 0
310 + ${OrIf} $1 == 0
311 + Goto goodbye
312 + ${EndIf}
313 +
314 + ${If} $0 == 135
315 + ${AndIf} $1 >= 36
316 + nsExec::ExecToLog '$INSTDIR\usr\bin\NetdataClaim.exe /T $cloudToken /R $cloudRooms /P $proxy /I $insecure'
317 + pop $0
318 + ${Else}
319 + System::Call 'kernel32::AttachConsole(i -1)i.r0'
320 + ${If} $0 != 0
321 + System::Call 'kernel32::GetStdHandle(i -11)i.r0'
322 + FileWrite $0 "Room(s) or Token invalid.$\r$\n"
323 + ${EndIf}
324 + ${EndIf}
325 + goodbye:
326 SectionEnd
327
328 Section "Uninstall"