Skip to content

Commit

Permalink
Add basis for MSI installer. (netdata#18787)
Browse files Browse the repository at this point in the history
* Import draft Wix template for creating MSI packages.

* msi-wix: Add missing XML entry

* msi-wix: Format lines using wixtoolset and Heatwave, also remove a wrong close

* msi-wix: Reorganize code allowing it to be compiled with command 'wix build netdata.wxs'

* Install event manifest and netdata service.

* msi-wix: Add basis to claim agent

* msi-wix: Add Icon to Control panel

* msi-wix: Add Script to convert txt to rtf to be used with licenses

* msi-wix: Add UI and Cloud license

* msi-wix: Add file to install wix dependencies

* msi-wix: Add message to last screen and a checkbox to launch terminal

* Fix event manifest registration.

* msi-wix: Restore removed options

* msi-wix: Add basis for new windows

* msi-wix: Add new dialog

* msi-wix: Comment UI that was posponed and users/group not found

* msi-wix: Remove UI and keep only inline installer

* msi-wix: Add necessary parameter to WIX

* msi-wix: Adjust code and installer

* msi-wix: Fix MSI installer

* msi-wix: Adjust claiming to work with different installers

* msi-wix: Remove no compression and embed files to run final tests

* msi-wix: Address part of permissions issues

* msi-wix: Address remaining issue

* msi-wix: Cleanup

* msi-wix: Add current version to MSI

* msi-wix: Remove unused file

* msi-wix: Fix missing variable kept only in Windows host

* msi-wix: Set correct permissions

* msi-wix: Set correct permissions

* msi-wix: Call wevtutil

* msi-wix: Fix multiple entries in Control Panel

* msi-wix: Rename installation directory

* msi-wix: Rename name in Control Panel

* msi-wix: Address comment (cleanup)

* msi-wix: Address comments (Part II)

* msi-wix: Address comments (Part III)

* msi-wix: Fix rtf convertion

* msi-wix: Remove left-over from previous installer that could be affecting current

* msi-wix: Add missing directories

---------

Co-authored-by: thiagoftsm <[email protected]>
  • Loading branch information
vkalintiris and thiagoftsm authored Oct 30, 2024
1 parent b4dfc78 commit 46cd039
Show file tree
Hide file tree
Showing 9 changed files with 866 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,8 @@ src/go/plugin/go.d/bin/
src/go/plugin/go.d/vendor

# ignore nsis installer
packaging/utils/netdata-installer.exe
packaging/utils/netdata-installer-x64.exe

# ignore files used with msi installer
packaging/utils/*.msi

2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,8 @@ if(OS_WINDOWS)

set(NETDATA_RES_FILES "packaging/windows/resources/netdata.rc")
configure_file(packaging/windows/resources/netdata.manifest.in ${CMAKE_SOURCE_DIR}/packaging/windows/resources/netdata.manifest @ONLY)

configure_file(packaging/windows/netdata.wxs.in ${CMAKE_SOURCE_DIR}/packaging/windows/netdata.wxs @ONLY)
endif()

add_executable(netdata
Expand Down
33 changes: 33 additions & 0 deletions packaging/windows/get-convert-licenses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later

set -e

function txt_to_rtf() {
INPUT="$1"
OUTPUT="$2"

echo '{\rtf1\ansi\deff0 {\fonttbl {\f0 Times New Roman;}}' > "$OUTPUT"
echo '\paperh15840 \paperw12240' >> "$OUTPUT"
echo '\margl720 \margr720 \margt720 \margb720' >> "$OUTPUT"
echo '\f0\fs24' >> "$OUTPUT"

sed s/\$/'\\line'/ "$INPUT" | sed s/\\f/'\\page'/ >> "$OUTPUT"
echo '}' >> "$OUTPUT"
}

if [ ! -f "gpl-3.0.txt" ]; then
curl -o gpl-3.0.txt "https://www.gnu.org/licenses/gpl-3.0.txt"
fi

if [ ! -f "cloud.txt" ]; then
curl -o cloud.txt "https://raw.githubusercontent.com/netdata/netdata/master/src/web/gui/v2/LICENSE.md"
fi

if [ -f "gpl-3.0.txt" ] ; then
txt_to_rtf "gpl-3.0.txt" "gpl-3.0.rtf"
fi

if [ -f "cloud.txt" ] ; then
txt_to_rtf "cloud.txt" "cloud.rtf"
fi
674 changes: 674 additions & 0 deletions packaging/windows/gpl-3.0.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packaging/windows/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ ManifestExistsForUninstall:
${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:
Expand All @@ -410,6 +412,7 @@ ManifestNotExistsForUninstall:
DoneUninstall:

; Remove files
SetOutPath "$PROGRAMFILES"
RMDir /r /REBOOTOK "$INSTDIR"

DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
Expand Down
2 changes: 2 additions & 0 deletions packaging/windows/msi-extension.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
wix extension -g add WixToolset.Util.wixext/5.0.2
wix extension -g add WixToolset.UI.wixext/5.0.2
115 changes: 115 additions & 0 deletions packaging/windows/netdata.wxs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<!-- xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui" -->
<Package Name="Netdata Agent"
Manufacturer="Netdata Inc."
Version="@CMAKE_PROJECT_VERSION@"
UpgradeCode="0d949b90-a54d-4aae-9616-e15fbc410530">

<UIRef Id="WixUI_ErrorProgressText" />

<MediaTemplate EmbedCab="yes"/>

<WixVariable Id="WixUILicenseRtf" Value="cloud.rtf" />

<MajorUpgrade Schedule="afterInstallInitialize" DowngradeErrorMessage="A newer version of [ProductName] is already installed." AllowSameVersionUpgrades="yes" />
<Icon Id="NetdataIcon.ico" SourceFile="NetdataWhite.ico"/>
<Property Id="ARPPRODUCTICON" Value="NetdataIcon.ico" />

<Property Id="TOKEN" Value=" " />
<Property Id="ROOMS" Value=" " />
<Property Id="INSECURE" Value="0" />
<Property Id="PROXY" Value=" " />
<Property Id="URL" Value="https://app.netdata.cloud" />

<Feature Id="Main">
<ComponentGroupRef Id="NetdataComponents" />
<ComponentRef Id="NetdataVarCache" />
<ComponentRef Id="NetdataVarLib" />
<ComponentGroupRef Id="WevtComponents" />
<ComponentRef Id="NetdataService" />
</Feature>
</Package>

<Fragment>
<Property Id="MsiLogging" Value="voicewarmupx!"/>

<StandardDirectory Id="ProgramFiles64Folder">
<Directory Id="INSTALLFOLDER" Name="Netdata">
<Directory Id="USRDIR" Name="usr">
<Directory Id="USRBINDIR" Name="bin" />
</Directory>
<Directory Id="VARDIR" Name="var">
<Directory Id="VARCACHEDIR" Name="cache" />
<Directory Id="VARLIBDIR" Name="lib" />
</Directory>
</Directory>
</StandardDirectory>

<StandardDirectory Id="System64Folder">
</StandardDirectory>

<!-- All the files except for the ones we need to handle specially -->
<ComponentGroup Id="NetdataComponents" Directory="INSTALLFOLDER">
<Files Include="C:\msys64\opt\netdata\**">
<Exclude Files="C:\msys64\opt\netdata\usr\bin\netdata.exe" />
<Exclude Files="C:\msys64\opt\netdata\usr\bin\wevt_netdata_manifest.xml" />
<Exclude Files="C:\msys64\opt\netdata\usr\bin\wevt_netdata.dll" />
</Files>
</ComponentGroup>

<Component Id="NetdataVarCache" Directory="VARCACHEDIR" Guid="a41bc888-60d4-4d99-bb4f-da92614a8f72">
<CreateFolder />
</Component>

<Component Id="NetdataVarLib" Directory="VARLIBDIR" Guid="c72d7ea8-c848-46c4-a983-589044f2eec9">
<CreateFolder />
</Component>

<!-- Install wevt manifest/dll files -->
<ComponentGroup Id="WevtComponents" Directory="System64Folder">
<File Id="WevtDll" Name="wevt_netdata.dll" Source="C:\msys64\opt\netdata\usr\bin\wevt_netdata.dll">
</File>

<File Id="WevtManifest" Name="wevt_netdata_manifest.xml" Source="C:\msys64\opt\netdata\usr\bin\wevt_netdata_manifest.xml">
</File>
</ComponentGroup>

<CustomAction Id="ClaimAgent" Directory="USRBINDIR" ExeCommand='[USRBINDIR]NetdataClaim.exe /T &quot;[TOKEN]&quot; /R &quot;[ROOMS]&quot; /U &quot;[URL]&quot; /I [INSECURE] /P &quot;[PROXY]&quot; /F &quot;[INSTALLFOLDER]etc\netdata\claim.conf&quot;' Execute="deferred" Return="ignore" Impersonate="no"/>
<InstallExecuteSequence>
<Custom Action="ClaimAgent" Before="InstallFinalize" />
</InstallExecuteSequence>

<CustomAction Id="WevtNetdataDLL" Directory="System64Folder" ExeCommand='[System64Folder]icacls.exe &quot;[System64Folder]wevt_netdata.dll&quot; /GRANT &quot;NT SERVICE\EventLog&quot;:R' Execute="deferred" Return="ignore" Impersonate="no"/>
<InstallExecuteSequence>
<Custom Action="WevtNetdataDLL" Before="InstallFinalize" />
</InstallExecuteSequence>

<CustomAction Id="WevtUtil" Directory="System64Folder" ExeCommand='[System64Folder]wevtutil.exe im &quot;[System64Folder]wevt_netdata_manifest.xml&quot; &quot;/mf:[System64Folder]wevt_netdata.dll&quot; &quot;/rf:[System64Folder]wevt_netdata.dll&quot;' Execute="deferred" Return="ignore" Impersonate="no"/>
<InstallExecuteSequence>
<Custom Action="WevtUtil" Before="InstallFinalize" />
</InstallExecuteSequence>

<Component Id="NetdataService" Directory="USRBINDIR">
<File Id="netdata.exe" Source="C:\msys64\opt\netdata\usr\bin\netdata.exe" KeyPath="yes" />

<ServiceInstall Id="InstallService"
Name="Netdata"
DisplayName="Netdata Agent"
Description="Netdata is distributed, real-time, performance and health monitoring for systems and applications."
Type="ownProcess"
Start="auto"
ErrorControl="normal" />

<ServiceControl Id="ControlService"
Start="install"
Stop="both"
Remove="uninstall"
Name="Netdata"
Wait="yes" />
</Component>
</Fragment>
</Wix>

32 changes: 30 additions & 2 deletions src/claim/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ LPWSTR token = NULL;
LPWSTR room = NULL;
LPWSTR proxy = NULL;
LPWSTR url = NULL;
LPWSTR extPath = NULL;
LPWSTR *argv = NULL;

char *aToken = NULL;
Expand Down Expand Up @@ -91,6 +92,13 @@ int nd_claim_parse_args(int argc, LPWSTR *argv)
}
}

if(wcscasecmp(L"/F", argv[i]) == 0) {
if (argc <= i + 1)
continue;
i++;
extPath = argv[i];
}

if(wcscasecmp(L"/U", argv[i]) == 0) {
if (argc <= i + 1)
continue;
Expand Down Expand Up @@ -180,6 +188,9 @@ static void netdata_claim_exit_callback(int signal)

if (argv)
LocalFree(argv);

if (extPath)
LocalFree(extPath);
}

static inline int netdata_claim_prepare_data(char *out, size_t length)
Expand All @@ -202,6 +213,15 @@ static inline int netdata_claim_prepare_data(char *out, size_t length)

static int netdata_claim_get_path(char *path)
{
if (extPath) {
size_t length = wcslen(extPath) + 1;
if (length >= WINDOWS_MAX_PATH)
return -1;

netdata_claim_convert_str(path, extPath, length - 1);
return 0;
}

char *usrPath = { "\\usr\\bin" };
DWORD length = GetCurrentDirectoryA(WINDOWS_MAX_PATH, path);
if (!length) {
Expand All @@ -220,9 +240,17 @@ static void netdata_claim_write_config(char *path)
{
char configPath[WINDOWS_MAX_PATH + 1];
char data[WINDOWS_MAX_PATH + 1];
snprintf(configPath, WINDOWS_MAX_PATH - 1, "%s\\etc\\netdata\\claim.conf", path);
char *filename;
if (!extPath) {
snprintf(configPath, WINDOWS_MAX_PATH - 1, "%s\\etc\\netdata\\claim.conf", path);
filename = configPath;
} else {
filename = path;
}

// MessageBoxA(NULL, configPath, "PATH", 0);

HANDLE hf = CreateFileA(configPath, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hf = CreateFileA(filename, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hf == INVALID_HANDLE_VALUE)
netdata_claim_error_exit(L"CreateFileA");

Expand Down
3 changes: 2 additions & 1 deletion src/claim/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ LRESULT CALLBACK WndProc(HWND hNetdatawnd, UINT message, WPARAM wParam, LPARAM l
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;"
L"/I : Use insecure connection;",
L"/F File : file to store cloud info;"
};

switch (message)
Expand Down

0 comments on commit 46cd039

Please sign in to comment.