diff --git a/.gitignore b/.gitignore index 7762d1cea..536497466 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,7 @@ build/ build-debug/ build-release/ +build32/ +build64/ debug/ release/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b629182c..687a40349 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,6 +281,10 @@ add_subdirectory(doc) add_subdirectory(agent) add_subdirectory(plugins) +if(MSVC) + add_subdirectory(icinga-installer) +endif() + if(ICINGA2_WITH_STUDIO) add_subdirectory(icinga-studio) endif() @@ -323,6 +327,7 @@ set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nnsE set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "nsExec::Exec '\\\"$INSTDIR\\\\sbin\\\\icinga2\\\" --scm-uninstall'") set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico") set(CPACK_WIX_UPGRADE_GUID "52F2BEAA-4DF0-4C3E-ABDC-C0F61DE4DF8A") +set(CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/icinga2.wixpatch") set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) include(InstallRequiredSystemLibraries) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index d67df4690..2f465bd0b 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -40,8 +40,6 @@ # include # include # include -#else /* _WIN32 */ -# include #endif /* _WIN32 */ using namespace icinga; @@ -127,31 +125,9 @@ int Main(void) #ifdef _WIN32 bool builtinPaths = true; - String prefix; + String prefix = Utility::GetIcingaInstallPath(); - char szProduct[39]; - bool foundMsi = false; - - for (int i = 0; MsiEnumProducts(i, szProduct) == ERROR_SUCCESS; i++) { - char szName[128]; - DWORD cbName = sizeof(szName); - if (MsiGetProductInfo(szProduct, INSTALLPROPERTY_INSTALLEDPRODUCTNAME, szName, &cbName) != ERROR_SUCCESS) - continue; - - if (strcmp(szName, "Icinga 2") != 0) - continue; - - char szLocation[1024]; - DWORD cbLocation = sizeof(szLocation); - if (MsiGetProductInfo(szProduct, INSTALLPROPERTY_INSTALLLOCATION, szLocation, &cbLocation) == ERROR_SUCCESS) { - builtinPaths = false; - prefix = szLocation; - foundMsi = true; - break; - } - } - - if (!builtinPaths) { + if (!prefix.IsEmpty()) { Application::DeclarePrefixDir(prefix); Application::DeclareSysconfDir(prefix + "\\etc"); Application::DeclareRunDir(prefix + "\\var\\run"); diff --git a/icinga-installer/CMakeLists.txt b/icinga-installer/CMakeLists.txt new file mode 100644 index 000000000..4aa6c07dc --- /dev/null +++ b/icinga-installer/CMakeLists.txt @@ -0,0 +1,35 @@ +# Icinga 2 +# Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +add_executable(icinga-installer icinga-installer.cpp) + +include_directories(${Boost_INCLUDE_DIRS}) +target_link_libraries(icinga-installer ${Boost_LIBRARIES} base config cli) + +set_target_properties ( + icinga-installer PROPERTIES + FOLDER Bin + OUTPUT_NAME icinga2-installer + LINK_FLAGS "/SUBSYSTEM:WINDOWS" +) + +set(InstallPath "${CMAKE_INSTALL_SBINDIR}") + +install( + TARGETS icinga-installer + RUNTIME DESTINATION ${InstallPath} +) diff --git a/icinga-installer/icinga-installer.cpp b/icinga-installer/icinga-installer.cpp new file mode 100644 index 000000000..3bfbdb9bb --- /dev/null +++ b/icinga-installer/icinga-installer.cpp @@ -0,0 +1,57 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#include "base/utility.hpp" +#include "base/application.hpp" + +using namespace icinga; + +int InstallIcinga(void) +{ + MessageBox(NULL, "Install", "Icinga 2", 0); + return 0; +} + +int UninstallIcinga(void) +{ + MessageBox(NULL, "Uninstall", "Icinga 2", 0); + return 0; +} + +/** +* Entry point for the installer application. +*/ +int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +{ + /* must be called before using any other libbase functions */ + Application::InitializeBase(); + + int rc; + + if (strcmp(lpCmdLine, "install") == 0) { + rc = InstallIcinga(); + } else if (strcmp(lpCmdLine, "uninstall") == 0) { + rc = UninstallIcinga(); + } else { + MessageBox(NULL, "This application should only be run by the MSI installer package.", "Icinga 2 Installer", MB_ICONWARNING); + rc = 1; + } + + Application::Exit(rc); +} diff --git a/icinga2.wixpatch b/icinga2.wixpatch new file mode 100644 index 000000000..38360b534 --- /dev/null +++ b/icinga2.wixpatch @@ -0,0 +1,11 @@ + + + + + + + $CM_CP_sbin.icinga2_installer.exe>2 + $CM_CP_sbin.icinga2_installer.exe=2 + + + \ No newline at end of file diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index dfb0614db..8d6466839 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -55,6 +55,7 @@ # include # include # include +# include #endif /*_WIN32*/ using namespace icinga; @@ -1859,4 +1860,27 @@ int Utility::MksTemp(char *tmpl) errno = EEXIST; return -1; } -#endif /*_WIN32*/ + +String Utility::GetIcingaInstallPath(void) +{ + char szProduct[39]; + + for (int i = 0; MsiEnumProducts(i, szProduct) == ERROR_SUCCESS; i++) { + char szName[128]; + DWORD cbName = sizeof(szName); + if (MsiGetProductInfo(szProduct, INSTALLPROPERTY_INSTALLEDPRODUCTNAME, szName, &cbName) != ERROR_SUCCESS) + continue; + + if (strcmp(szName, "Icinga 2") != 0) + continue; + + char szLocation[1024]; + DWORD cbLocation = sizeof(szLocation); + if (MsiGetProductInfo(szProduct, INSTALLPROPERTY_INSTALLLOCATION, szLocation, &cbLocation) == ERROR_SUCCESS) + return szLocation; + } + + return ""; +} + +#endif /* _WIN32 */ \ No newline at end of file diff --git a/lib/base/utility.hpp b/lib/base/utility.hpp index d244086f3..9af1b8f8a 100644 --- a/lib/base/utility.hpp +++ b/lib/base/utility.hpp @@ -143,6 +143,10 @@ public: static String CreateTempFile(const String& path, int mode, std::fstream& fp); +#ifdef _WIN32 + static String GetIcingaInstallPath(void); +#endif /* _WIN32 */ + private: Utility(void); static void CollectPaths(const String& path, std::vector& paths);