diff --git a/packaging/installer/installer.nsi b/packaging/installer/installer.nsi new file mode 100644 index 0000000000..c14ccb5993 --- /dev/null +++ b/packaging/installer/installer.nsi @@ -0,0 +1,128 @@ +!include "MUI2.nsh" +!include "nsDialogs.nsh" +!include "FileFunc.nsh" + +Name "Netdata" +Outfile "netdata-installer.exe" +InstallDir "$PROGRAMFILES\Netdata" +RequestExecutionLevel admin + +!define MUI_ICON "NetdataWhite.ico" +!define MUI_UNICON "NetdataWhite.ico" + +!define ND_UININSTALL_REG "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata" + +!define MUI_ABORTWARNING +!define MUI_UNABORTWARNING + +!insertmacro MUI_PAGE_WELCOME +!insertmacro MUI_PAGE_LICENSE "C:\msys64\gpl-3.0.txt" +!insertmacro MUI_PAGE_DIRECTORY +!insertmacro MUI_PAGE_INSTFILES +!insertmacro MUI_PAGE_FINISH + +!insertmacro MUI_UNPAGE_CONFIRM +!insertmacro MUI_UNPAGE_INSTFILES +!insertmacro MUI_UNPAGE_FINISH + +!insertmacro MUI_LANGUAGE "English" + +Function .onInit + nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata' + pop $0 + ${If} $0 == 0 + nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata' + pop $0 + ${EndIf} +FunctionEnd + +Function NetdataUninstallRegistry + ClearErrors + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "DisplayName" "Netdata - Real-time system monitoring." + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "DisplayIcon" "$INSTDIR\Uninstall.exe,0" + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "UninstallString" "$INSTDIR\Uninstall.exe" + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "RegOwner" "Netdata Inc." + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "RegCompany" "Netdata Inc." + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "Publisher" "Netdata Inc." + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "HelpLink" "https://learn.netdata.cloud/" + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "URLInfoAbout" "https://www.netdata.cloud/" + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "DisplayVersion" "${CURRVERSION}" + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "VersionMajor" "${MAJORVERSION}" + WriteRegStr HKLM "${ND_UININSTALL_REG}" \ + "VersionMinor" "${MINORVERSION}" + + IfErrors 0 +2 + MessageBox MB_ICONEXCLAMATION|MB_OK "Unable to create an entry in the Control Panel!" IDOK end + + ClearErrors + ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 + IntFmt $0 "0x%08X" $0 + WriteRegDWORD HKLM "${ND_UININSTALL_REG}" "EstimatedSize" "$0" + + IfErrors 0 +2 + MessageBox MB_ICONEXCLAMATION|MB_OK "Cannot estimate the installation size." IDOK end + end: +FunctionEnd + +Section "Install Netdata" + SetOutPath $INSTDIR + SetCompress off + + File /r "C:\msys64\opt\netdata\*.*" + + 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." + ${EndIf} + + 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." + ${EndIf} + + ClearErrors + nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata' + pop $0 + ${If} $0 != 0 + DetailPrint "Warning: Failed to start Netdata service." + ${EndIf} + + WriteUninstaller "$INSTDIR\Uninstall.exe" + + Call NetdataUninstallRegistry +SectionEnd + +Section "Uninstall" + ClearErrors + nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata' + pop $0 + ${If} $0 != 0 + DetailPrint "Warning: Failed to stop Netdata service." + ${EndIf} + + ClearErrors + nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata' + pop $0 + ${If} $0 != 0 + DetailPrint "Warning: Failed to delete Netdata service." + ${EndIf} + + RMDir /r "$INSTDIR" + + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata" +SectionEnd + diff --git a/packaging/installer/package-windows.sh b/packaging/installer/package-windows.sh new file mode 100755 index 0000000000..7b1c57e461 --- /dev/null +++ b/packaging/installer/package-windows.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +repo_root="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd -P)")")" + +if [ -n "${BUILD_DIR}" ]; then + build="${BUILD_DIR}" +elif [ -n "${OSTYPE}" ]; then + if [ -n "${MSYSTEM}" ]; then + build="${repo_root}/build-${OSTYPE}-${MSYSTEM}" + else + build="${repo_root}/build-${OSTYPE}" + fi +elif [ "$USER" = "vk" ]; then + build="${repo_root}/build" +else + build="${repo_root}/build" +fi + +set -exu -o pipefail + +${GITHUB_ACTIONS+echo "::group::Installing"} +cmake --install "${build}" +${GITHUB_ACTIONS+echo "::endgroup::"} + +if [ ! -f "/msys2-installer.exe" ]; then + ${GITHUB_ACTIONS+echo "::group::Fetching MSYS2 installer"} + "${repo_root}/packaging/windows/fetch-msys2-installer.py" /msys2-installer.exe + ${GITHUB_ACTIONS+echo "::endgroup::"} +fi + +${GITHUB_ACTIONS+echo "::group::Packaging"} +NDVERSION=$"$(grep 'CMAKE_PROJECT_VERSION:STATIC' "${build}/CMakeCache.txt"| cut -d= -f2)" +NDMAJORVERSION=$"$(grep 'CMAKE_PROJECT_VERSION_MAJOR:STATIC' "${build}/CMakeCache.txt"| cut -d= -f2)" +NDMINORVERSION=$"$(grep 'CMAKE_PROJECT_VERSION_MINOR:STATIC' "${build}/CMakeCache.txt"| cut -d= -f2)" + +if [ -f "/gpl-3.0.txt" ]; then + ${GITHUB_ACTIONS+echo "::group::Fetching GPL3 License"} + curl -o /gpl-3.0.txt "https://www.gnu.org/licenses/gpl-3.0.txt" + ${GITHUB_ACTIONS+echo "::endgroup::"} +fi + +/mingw64/bin/makensis.exe -DCURRVERSION="${NDVERSION}" -DMAJORVERSION="${NDMAJORVERSION}" -DMINORVERSION="${NDMINORVERSION}" "${repo_root}/packaging/windows/installer.nsi" +${GITHUB_ACTIONS+echo "::endgroup::"} diff --git a/packaging/windows/fetch-msys2-installer.py b/packaging/windows/fetch-msys2-installer.py index 8210cfee95..e30e7205c8 100755 --- a/packaging/windows/fetch-msys2-installer.py +++ b/packaging/windows/fetch-msys2-installer.py @@ -78,8 +78,8 @@ def main() -> None: with TemporaryDirectory() as tmpdir: tmppath = Path(tmpdir) - installer = fetch_release_asset(tmppath, name, f'msys2-x86_64-{version}.exe') - checksums = fetch_release_asset(tmppath, name, f'msys2-x86_64-{version}.exe.sha256') + installer = fetch_release_asset(tmppath, name, f'msys2-base-x86_64-{version}.tar.zst') + checksums = fetch_release_asset(tmppath, name, f'msys2-base-x86_64-{version}.tar.zst.sha256') print('>>> Verifying SHA256 checksum') expected_checksum = checksums.read_text().partition(' ')[0].casefold() diff --git a/packaging/windows/installer.nsi b/packaging/windows/installer.nsi index dbafb03938..88d160a1d3 100644 --- a/packaging/windows/installer.nsi +++ b/packaging/windows/installer.nsi @@ -16,8 +16,11 @@ RequestExecutionLevel admin !define MUI_UNABORTWARNING !insertmacro MUI_PAGE_WELCOME +!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_FINISH !insertmacro MUI_UNPAGE_CONFIRM @@ -26,9 +29,69 @@ RequestExecutionLevel admin !insertmacro MUI_LANGUAGE "English" +var hStartMsys +var startMsys + +var hCloudToken +var cloudToken +var hCloudRoom +var cloudRoom + Function .onInit nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata' pop $0 + ${If} $0 == 0 + nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata' + pop $0 + ${EndIf} + + StrCpy $startMsys ${BST_UNCHECKED} +FunctionEnd + +Function NetdataConfigPage + !insertmacro MUI_HEADER_TEXT "Netdata configuration" "Claim your agent on Netdata Cloud" + + nsDialogs::Create 1018 + Pop $0 + ${If} $0 == error + 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." + + ${NSD_CreateLabel} 0 35% 20% 10% "Token" + Pop $0 + ${NSD_CreateText} 21% 35% 79% 10% "" + Pop $hCloudToken + + ${NSD_CreateLabel} 0 55% 20% 10% "Room" + Pop $0 + ${NSD_CreateText} 21% 55% 79% 10% "" + Pop $hCloudRoom + + ${NSD_CreateCheckbox} 0 70% 100% 10u "Open terminal" + Pop $hStartMsys + 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 + ${EndIf} FunctionEnd Function NetdataUninstallRegistry diff --git a/packaging/windows/package-windows.sh b/packaging/windows/package-windows.sh index 4c62e0c08f..03f72a692f 100755 --- a/packaging/windows/package-windows.sh +++ b/packaging/windows/package-windows.sh @@ -1,9 +1,20 @@ #!/bin/bash -REPO_ROOT="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd -P)")")" +repo_root="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd -P)")")" -# shellcheck source=./win-build-dir.sh -. "${REPO_ROOT}/packaging/windows/win-build-dir.sh" +if [ -n "${BUILD_DIR}" ]; then + build="${BUILD_DIR}" +elif [ -n "${OSTYPE}" ]; then + if [ -n "${MSYSTEM}" ]; then + build="${repo_root}/build-${OSTYPE}-${MSYSTEM}" + else + build="${repo_root}/build-${OSTYPE}" + fi +elif [ "$USER" = "vk" ]; then + build="${repo_root}/build" +else + build="${repo_root}/build" +fi set -exu -o pipefail @@ -11,16 +22,30 @@ ${GITHUB_ACTIONS+echo "::group::Installing"} cmake --install "${build}" ${GITHUB_ACTIONS+echo "::endgroup::"} -if [ ! -f "/msys2-installer.exe" ]; then - ${GITHUB_ACTIONS+echo "::group::Fetching MSYS2 installer"} - "${REPO_ROOT}/packaging/windows/fetch-msys2-installer.py" /msys2-installer.exe +if [ ! -f "/msys2-latest.tar.zst" ]; then + ${GITHUB_ACTIONS+echo "::group::Fetching MSYS2 files"} + "${repo_root}/packaging/windows/fetch-msys2-installer.py" /msys2-latest.tar.zst ${GITHUB_ACTIONS+echo "::endgroup::"} fi +${GITHUB_ACTIONS+echo "::group::Licenses"} +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 +${GITHUB_ACTIONS+echo "::endgroup::"} + ${GITHUB_ACTIONS+echo "::group::Packaging"} +tar -xf /msys2-latest.tar.zst -C /opt/netdata/ || exit 1 +cp -R /opt/netdata/msys64/* /opt/netdata/ || exit 1 +rm -rf /opt/netdata/msys64/ NDVERSION=$"$(grep 'CMAKE_PROJECT_VERSION:STATIC' "${build}/CMakeCache.txt"| cut -d= -f2)" NDMAJORVERSION=$"$(grep 'CMAKE_PROJECT_VERSION_MAJOR:STATIC' "${build}/CMakeCache.txt"| cut -d= -f2)" NDMINORVERSION=$"$(grep 'CMAKE_PROJECT_VERSION_MINOR:STATIC' "${build}/CMakeCache.txt"| cut -d= -f2)" -/mingw64/bin/makensis.exe -DCURRVERSION="${NDVERSION}" -DMAJORVERSION="${NDMAJORVERSION}" -DMINORVERSION="${NDMINORVERSION}" "${REPO_ROOT}/packaging/windows/installer.nsi" +/mingw64/bin/makensis.exe -DCURRVERSION="${NDVERSION}" -DMAJORVERSION="${NDMAJORVERSION}" -DMINORVERSION="${NDMINORVERSION}" "${repo_root}/packaging/windows/installer.nsi" ${GITHUB_ACTIONS+echo "::endgroup::"} +