diff options
Diffstat (limited to 'packaging/windows/installer.nsi')
-rw-r--r-- | packaging/windows/installer.nsi | 317 |
1 files changed, 275 insertions, 42 deletions
diff --git a/packaging/windows/installer.nsi b/packaging/windows/installer.nsi index 88d160a1d..a462d4997 100644 --- a/packaging/windows/installer.nsi +++ b/packaging/windows/installer.nsi @@ -3,7 +3,7 @@ !include "FileFunc.nsh" Name "Netdata" -Outfile "netdata-installer.exe" +Outfile "netdata-installer-x64.exe" InstallDir "$PROGRAMFILES\Netdata" RequestExecutionLevel admin @@ -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 @@ -29,15 +29,60 @@ Page Custom NetdataConfigPage NetdataConfigLeave !insertmacro MUI_LANGUAGE "English" +!define INSTALLERLOCKFILEGUID "f787d5ef-5c41-4dc0-a115-a1fb654fad1c" + +# https://nsis.sourceforge.io/Allow_only_one_installer_instance +!macro SingleInstanceFile + !if "${NSIS_PTR_SIZE}" > 4 + !include "Util.nsh" + !else ifndef IntPtrCmp + !define IntPtrCmp IntCmp + !endif + + !ifndef NSIS_PTR_SIZE & SYSTYPE_PTR + !define SYSTYPE_PTR i ; NSIS v2.x + !else + !define /ifndef SYSTYPE_PTR p ; NSIS v3.0+ + !endif + + !if "${NSIS_CHAR_SIZE}" < 2 + Push "$TEMP\${INSTALLERLOCKFILEGUID}.lock" + !else + Push "$APPDATA\${INSTALLERLOCKFILEGUID}.lock" + !endif + + System::Call 'KERNEL32::CreateFile(ts,i0x40000000,i0,${SYSTYPE_PTR}0,i4,i0x04000000,${SYSTYPE_PTR}0)${SYSTYPE_PTR}.r0' + ${IntPtrCmp} $0 -1 "" launch launch + System::Call 'kernel32::AttachConsole(i -1)i.r0' + ${If} $0 != 0 + System::Call 'kernel32::GetStdHandle(i -11)i.r0' + FileWrite $0 "The installer is already running.$\r$\n" + ${EndIf} + Quit + launch: +!macroend + +var hCtrlButton var hStartMsys var startMsys +var hCloudURL +var cloudURL var hCloudToken var cloudToken -var hCloudRoom -var cloudRoom +var hCloudRooms +var cloudRooms +var hProxy +var proxy +var hInsecure +var insecure +var accepted + +var avoidClaim Function .onInit + !insertmacro SingleInstanceFile + nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata' pop $0 ${If} $0 == 0 @@ -46,10 +91,71 @@ Function .onInit ${EndIf} StrCpy $startMsys ${BST_UNCHECKED} + StrCpy $insecure ${BST_UNCHECKED} + StrCpy $avoidClaim ${BST_UNCHECKED} + StrCpy $accepted ${BST_UNCHECKED} + + ${GetParameters} $R0 + ${GetOptions} $R0 "/s" $0 + IfErrors +2 0 + SetSilent silent + ClearErrors + + ${GetOptions} $R0 "/t" $0 + IfErrors +2 0 + StrCpy $startMsys ${BST_CHECKED} + ClearErrors + + ${GetOptions} $R0 "/i" $0 + IfErrors +2 0 + StrCpy $insecure ${BST_CHECKED} + ClearErrors + + ${GetOptions} $R0 "/a" $0 + IfErrors +2 0 + StrCpy $accepted ${BST_CHECKED} + ClearErrors + + ${GetOptions} $R0 "/token=" $0 + IfErrors +2 0 + StrCpy $cloudToken $0 + ClearErrors + + ${GetOptions} $R0 "/rooms=" $0 + IfErrors +2 0 + StrCpy $cloudRooms $0 + ClearErrors + + ${GetOptions} $R0 "/proxy=" $0 + IfErrors +2 0 + StrCpy $proxy $0 + ClearErrors + + IfSilent checklicense goahead + checklicense: + ${If} $accepted == ${BST_UNCHECKED} + System::Call 'kernel32::AttachConsole(i -1)i.r0' + ${If} $0 != 0 + System::Call 'kernel32::GetStdHandle(i -11)i.r0' + FileWrite $0 "You must accept the licenses (/A) to continue.$\r$\n" + ${EndIf} + Quit + ${EndIf} + goahead: +FunctionEnd + +Function un.onInit +!insertmacro SingleInstanceFile +FunctionEnd + +Function ShowHelp +Pop $0 + 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 Function NetdataConfigPage - !insertmacro MUI_HEADER_TEXT "Netdata configuration" "Claim your agent on Netdata Cloud" + !insertmacro MUI_HEADER_TEXT "Netdata configuration" "Connect your Agent to your Netdata Cloud Space" nsDialogs::Create 1018 Pop $0 @@ -57,40 +163,59 @@ Function NetdataConfigPage Abort ${EndIf} - ${NSD_CreateLabel} 0 0 100% 12u "Enter your Token and Cloud Room." - ${NSD_CreateLabel} 0 15% 100% 12u "Optionally, you can open a terminal to execute additional commands." + IfFileExists "$INSTDIR\etc\netdata\claim.conf" NotNeeded - ${NSD_CreateLabel} 0 35% 20% 10% "Token" + ${NSD_CreateLabel} 0 0 100% 12u "Enter your Space's Claim Token and the Room IDs where you want to add the Agent." + ${NSD_CreateLabel} 0 12% 100% 12u "If no Room IDs are specified, the Agent will be added to the $\"All nodes$\" Room." + + ${NSD_CreateLabel} 0 30% 20% 10% "Claim Token" Pop $0 - ${NSD_CreateText} 21% 35% 79% 10% "" + ${NSD_CreateText} 21% 30% 79% 10% "" Pop $hCloudToken - ${NSD_CreateLabel} 0 55% 20% 10% "Room" + ${NSD_CreateLabel} 0 45% 20% 10% "Room ID(s)" + Pop $0 + ${NSD_CreateText} 21% 45% 79% 10% "" + Pop $hCloudRooms + + ${NSD_CreateLabel} 0 60% 20% 10% "Proxy URL" Pop $0 - ${NSD_CreateText} 21% 55% 79% 10% "" - Pop $hCloudRoom + ${NSD_CreateText} 21% 60% 79% 10% "" + Pop $hProxy - ${NSD_CreateCheckbox} 0 70% 100% 10u "Open terminal" + ${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} 50% 92% 25% 10u "Open terminal" Pop $hStartMsys + + ${NSD_CreateButton} 90% 90% 30u 15u "&Help" + Pop $hCtrlButton + ${NSD_OnClick} $hCtrlButton ShowHelp + + Goto EndDialogDraw + + NotNeeded: + StrCpy $avoidClaim ${BST_CHECKED} + ${NSD_CreateLabel} 0 0 100% 12u "Your host has already been claimed. You can proceed with the update." + + EndDialogDraw: nsDialogs::Show FunctionEnd Function NetdataConfigLeave - ${NSD_GetText} $hCloudToken $cloudToken - ${NSD_GetText} $hCloudRoom $cloudRoom - ${NSD_GetState} $hStartMsys $startMsys - - StrLen $0 $cloudToken - StrLen $1 $cloudRoom - ${If} $0 == 125 - ${AndIf} $0 == 36 - # We should start our new claiming software here - MessageBox MB_OK "$cloudToken | $cloudRoom | $startMsys" - ${EndIf} - - ${If} $startMsys == 1 - nsExec::ExecToLog '$INSTDIR\msys2.exe' - pop $0 + ${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 ${EndIf} FunctionEnd @@ -132,36 +257,125 @@ Function NetdataUninstallRegistry end: FunctionEnd +Function InstallDLL + ; Check if certutil is available + nsExec::ExecToStack 'where certutil' + Pop $R0 + StrCmp $R0 "" NoCertUtil FoundCertUtil + + NoCertUtil: + DetailPrint "certutil not found, assuming files are different." + Goto CopyDLL + + FoundCertUtil: + ; Calculate hash of the existing DLL + nsExec::ExecToStack 'certutil -hashfile "$SYSDIR\wevt_netdata.dll" MD5' + Pop $R0 + + ; Calculate hash of the new DLL + nsExec::ExecToStack 'certutil -hashfile "$INSTDIR\usr\bin\wevt_netdata.dll" MD5' + Pop $R1 + + StrCmp $R0 $R1 SetPermissions + + CopyDLL: + ClearErrors + CopyFiles /SILENT "$INSTDIR\usr\bin\wevt_netdata.dll" "$SYSDIR" + IfErrors RetryPrompt SetPermissions + + RetryPrompt: + MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Failed to copy wevt_netdata.dll probably because it is in use. Please close the Event Viewer (or other Event Log applications) and press Retry." + StrCmp $R0 IDRETRY CopyDLL + StrCmp $R0 IDCANCEL ExitInstall + + Goto End + + SetPermissions: + nsExec::ExecToLog 'icacls "$SYSDIR\wevt_netdata.dll" /grant "NT SERVICE\EventLog":R' + Goto End + + ExitInstall: + Abort + + End: +FunctionEnd + +Function InstallManifest + IfFileExists "$INSTDIR\usr\bin\wevt_netdata_manifest.xml" CopyManifest End + + CopyManifest: + ClearErrors + CopyFiles /SILENT "$INSTDIR\usr\bin\wevt_netdata_manifest.xml" "$SYSDIR" + IfErrors RetryPrompt InstallManifest + + RetryPrompt: + MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Failed to copy wevt_netdata_manifest.xml." + StrCmp $R0 IDRETRY CopyManifest + StrCmp $R0 IDCANCEL ExitInstall + + InstallManifest: + nsExec::ExecToLog 'wevtutil im "$SYSDIR\wevt_netdata_manifest.xml" "/mf:$SYSDIR\wevt_netdata.dll" "/rf:$SYSDIR\wevt_netdata.dll"' + Goto End + + ExitInstall: + Abort + + End: +FunctionEnd + Section "Install Netdata" - SetOutPath $INSTDIR - SetCompress off + SetOutPath $INSTDIR + SetCompress off - File /r "C:\msys64\opt\netdata\*.*" + File /r "C:\msys64\opt\netdata\*.*" - ClearErrors + ClearErrors nsExec::ExecToLog '$SYSDIR\sc.exe create Netdata binPath= "$INSTDIR\usr\bin\netdata.exe" start= delayed-auto' pop $0 ${If} $0 != 0 - DetailPrint "Warning: Failed to create Netdata service." + DetailPrint "Warning: Failed to create Netdata service." ${EndIf} - ClearErrors + ClearErrors nsExec::ExecToLog '$SYSDIR\sc.exe description Netdata "Real-time system monitoring service"' pop $0 ${If} $0 != 0 - DetailPrint "Warning: Failed to add Netdata service description." + DetailPrint "Warning: Failed to add Netdata service description." ${EndIf} - ClearErrors + WriteUninstaller "$INSTDIR\Uninstall.exe" + + Call NetdataUninstallRegistry + Call InstallDLL + Call InstallManifest + + 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 - DetailPrint "Warning: Failed to start Netdata service." + MessageBox MB_OK "Warning: Failed to start Netdata service." ${EndIf} - WriteUninstaller "$INSTDIR\Uninstall.exe" - - Call NetdataUninstallRegistry + ${If} $startMsys == ${BST_CHECKED} + nsExec::ExecToLog '$INSTDIR\msys2.exe' + pop $0 + ${EndIf} SectionEnd Section "Uninstall" @@ -179,8 +393,27 @@ Section "Uninstall" DetailPrint "Warning: Failed to delete Netdata service." ${EndIf} - RMDir /r "$INSTDIR" + ; Check if the manifest exists before uninstalling it + IfFileExists "$SYSDIR\wevt_netdata_manifest.xml" ManifestExistsForUninstall ManifestNotExistsForUninstall + +ManifestExistsForUninstall: + nsExec::ExecToLog 'wevtutil um "$SYSDIR\wevt_netdata_manifest.xml"' + pop $0 + ${If} $0 != 0 + DetailPrint "Warning: Failed to uninstall the event manifest." + ${EndIf} + Delete "$SYSDIR\wevt_netdata_manifest.xml" + Delete "$SYSDIR\wevt_netdata.dll" + Goto DoneUninstall + +ManifestNotExistsForUninstall: + DetailPrint "Manifest not found, skipping manifest uninstall." + +DoneUninstall: + + ; Remove files + SetOutPath "$PROGRAMFILES" + RMDir /r /REBOOTOK "$INSTDIR" DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata" SectionEnd - |