]> granicus.if.org Git - icinga2/commitdiff
Implement support for running custom install/uninstall actions
authorGunnar Beutner <gunnar@beutner.name>
Wed, 30 Mar 2016 16:59:23 +0000 (18:59 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Thu, 31 Mar 2016 12:53:54 +0000 (14:53 +0200)
refs #11449

.gitignore
CMakeLists.txt
icinga-app/icinga.cpp
icinga-installer/CMakeLists.txt [new file with mode: 0644]
icinga-installer/icinga-installer.cpp [new file with mode: 0644]
icinga2.wixpatch [new file with mode: 0644]
lib/base/utility.cpp
lib/base/utility.hpp

index 7762d1ceab55c85ca6eda937354dbb7e9afbc0df..536497466531d6bccd3c272969ae0b1d20af358d 100644 (file)
@@ -8,5 +8,7 @@
 build/
 build-debug/
 build-release/
+build32/
+build64/
 debug/
 release/
index 7b629182c34edd05031d1e7eb1a1acaf20a633bb..687a403490b084ced1255bb992245cb8c608975b 100644 (file)
@@ -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)
index d67df4690273a658a3602aab67b9f3da1ba76d39..2f465bd0b34a3cf9ff1761f21e0cce756f1db3bc 100644 (file)
@@ -40,8 +40,6 @@
 #      include <sys/types.h>
 #      include <pwd.h>
 #      include <grp.h>
-#else /* _WIN32 */
-#      include <msi.h>
 #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 (file)
index 0000000..4aa6c07
--- /dev/null
@@ -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 (file)
index 0000000..3bfbdb9
--- /dev/null
@@ -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 (file)
index 0000000..38360b5
--- /dev/null
@@ -0,0 +1,11 @@
+<CPackWiXPatch>
+  <CPackWiXFragment Id="#PRODUCT">
+    <CustomAction Id="XtraInstall" FileKey="CM_FP_sbin.icinga2_installer.exe" ExeCommand="install" Execute="deferred" Impersonate="no" />
+    <CustomAction Id="XtraUninstall" FileKey="CM_FP_sbin.icinga2_installer.exe" ExeCommand="uninstall" Execute="deferred" Impersonate="no" />
+
+    <InstallExecuteSequence>
+      <Custom Action="XtraInstall" Before="InstallFinalize">$CM_CP_sbin.icinga2_installer.exe&gt;2</Custom>
+      <Custom Action="XtraUninstall" After="InstallInitialize">$CM_CP_sbin.icinga2_installer.exe=2</Custom>
+    </InstallExecuteSequence>
+  </CPackWiXFragment>
+</CPackWiXPatch>
\ No newline at end of file
index dfb0614db87e1d07d59d4ea52d4f2f4fae6c32bd..8d6466839f31c430d832c50d6e8860208c23e261 100644 (file)
@@ -55,6 +55,7 @@
 #      include <VersionHelpers.h>
 #      include <windows.h>
 #      include <io.h>
+#      include <msi.h>
 #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
index d244086f33304e6d9cbc001d1ec0ea3df599e346..9af1b8f8a09a8d1b02ceda80fdf404dfb8bc8660 100644 (file)
@@ -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<String>& paths);