Implement support for running custom install/uninstall actions

refs #11449
This commit is contained in:
Gunnar Beutner 2016-03-30 18:59:23 +02:00
parent 027a23f468
commit 6bf3225e84
8 changed files with 141 additions and 27 deletions

2
.gitignore vendored
View File

@ -8,5 +8,7 @@
build/ build/
build-debug/ build-debug/
build-release/ build-release/
build32/
build64/
debug/ debug/
release/ release/

View File

@ -281,6 +281,10 @@ add_subdirectory(doc)
add_subdirectory(agent) add_subdirectory(agent)
add_subdirectory(plugins) add_subdirectory(plugins)
if(MSVC)
add_subdirectory(icinga-installer)
endif()
if(ICINGA2_WITH_STUDIO) if(ICINGA2_WITH_STUDIO)
add_subdirectory(icinga-studio) add_subdirectory(icinga-studio)
endif() 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_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_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
set(CPACK_WIX_UPGRADE_GUID "52F2BEAA-4DF0-4C3E-ABDC-C0F61DE4DF8A") 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) set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
include(InstallRequiredSystemLibraries) include(InstallRequiredSystemLibraries)

View File

@ -40,8 +40,6 @@
# include <sys/types.h> # include <sys/types.h>
# include <pwd.h> # include <pwd.h>
# include <grp.h> # include <grp.h>
#else /* _WIN32 */
# include <msi.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
using namespace icinga; using namespace icinga;
@ -127,31 +125,9 @@ int Main(void)
#ifdef _WIN32 #ifdef _WIN32
bool builtinPaths = true; bool builtinPaths = true;
String prefix; String prefix = Utility::GetIcingaInstallPath();
char szProduct[39]; if (!prefix.IsEmpty()) {
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) {
Application::DeclarePrefixDir(prefix); Application::DeclarePrefixDir(prefix);
Application::DeclareSysconfDir(prefix + "\\etc"); Application::DeclareSysconfDir(prefix + "\\etc");
Application::DeclareRunDir(prefix + "\\var\\run"); Application::DeclareRunDir(prefix + "\\var\\run");

View File

@ -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}
)

View File

@ -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);
}

11
icinga2.wixpatch Normal file
View File

@ -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>

View File

@ -55,6 +55,7 @@
# include <VersionHelpers.h> # include <VersionHelpers.h>
# include <windows.h> # include <windows.h>
# include <io.h> # include <io.h>
# include <msi.h>
#endif /*_WIN32*/ #endif /*_WIN32*/
using namespace icinga; using namespace icinga;
@ -1859,4 +1860,27 @@ int Utility::MksTemp(char *tmpl)
errno = EEXIST; errno = EEXIST;
return -1; 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 */

View File

@ -143,6 +143,10 @@ public:
static String CreateTempFile(const String& path, int mode, std::fstream& fp); static String CreateTempFile(const String& path, int mode, std::fstream& fp);
#ifdef _WIN32
static String GetIcingaInstallPath(void);
#endif /* _WIN32 */
private: private:
Utility(void); Utility(void);
static void CollectPaths(const String& path, std::vector<String>& paths); static void CollectPaths(const String& path, std::vector<String>& paths);