]> granicus.if.org Git - icinga2/commitdiff
Make sure config files aren't overwritten during updates
authorGunnar Beutner <gunnar@beutner.name>
Thu, 31 Mar 2016 11:54:10 +0000 (13:54 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 20 Apr 2016 08:07:50 +0000 (10:07 +0200)
refs #11449

cmake/InstallConfig.cmake
icinga-installer/icinga-installer.cpp

index 452abfadf7399bb15c8976f656209a87648059c5..e4af25d5ed62368593ab9dd2f0fddafd457d23d3 100644 (file)
@@ -21,25 +21,20 @@ function(install_if_not_exists src dest)
     set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
   endif()
   get_filename_component(src_name "${src}" NAME)
-  if (NOT IS_ABSOLUTE "${dest}")
-    set(dest "${CMAKE_INSTALL_PREFIX}/${dest}")
-  endif()
   get_filename_component(basename_dest "${src}" NAME)
   string(REPLACE "/" "\\\\" nsis_src "${src}")
   string(REPLACE "/" "\\\\" nsis_dest_dir "${real_dest}")
   string(REPLACE "/" "\\\\" nsis_dest "${real_dest}/${basename_dest}")
-  set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}
-    SetOverwrite off
-    CreateDirectory '$INSTDIR\\\\${nsis_dest_dir}'
-    File '/oname=${nsis_dest}' '${nsis_src}'
-    SetOverwrite on
-  " PARENT_SCOPE)
   install(CODE "
-    if(NOT EXISTS \"\$ENV{DESTDIR}${dest}/${src_name}\")
-      #file(INSTALL \"${src}\" DESTINATION \"${dest}\")
+    if(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.* OR NOT EXISTS \"\$ENV{DESTDIR}${dest}/${src_name}\")
       message(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\")
+      if(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.*)
+        set(skel_prefix \"share/skel/\")
+      else()
+        set(skel_prefix \"\")
+      endif()
       execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\"
-                      \"\$ENV{DESTDIR}${dest}/${src_name}\"
+                      \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\${skel_prefix}${dest}/${src_name}\"
                       RESULT_VARIABLE copy_result
                       ERROR_VARIABLE error_output)
       if(copy_result)
index 022faa726f621b355fda2bf97f8c72e8c28b6413..ea5c5d8e04f4309e975416255f92c22f63fea08c 100644 (file)
@@ -41,10 +41,24 @@ static void ExecuteIcingaCommand(const String& args)
        ExecuteCommand("\"" + GetIcingaInstallDir() + "\\sbin\\icinga2.exe\" " + args);
 }
 
+static void CopyConfigFile(const String& installDir, const String& sourceConfigPath, size_t skelPrefixLength)
+{
+       String relativeConfigPath = sourceConfigPath.SubStr(installDir.GetLength() + skelPrefixLength);
+
+       String targetConfigPath = installDir + relativeConfigPath;
+
+       if (!Utility::PathExists(targetConfigPath)) {
+               Utility::MkDirP(Utility::DirName(targetConfigPath), 0700);
+               Utility::CopyFile(sourceConfigPath, targetConfigPath);
+       }
+}
+
 static int InstallIcinga(void)
 {
        String installDir = GetIcingaInstallDir();
 
+       installDir = "C:\\Program Files\\Icinga2\\";
+
        ExecuteCommand("icacls \"" + installDir + "\" /grant *S-1-5-20:(oi)(ci)m");
        ExecuteCommand("icacls \"" + installDir + "\\etc\" /inheritance:r /grant:r *S-1-5-20:(oi)(ci)m *S-1-5-32-544:(oi)(ci)f");
 
@@ -61,6 +75,9 @@ static int InstallIcinga(void)
        Utility::MkDirP(installDir + "/var/spool/icinga2/perfdata", 0700);
        Utility::MkDirP(installDir + "/var/spool/icinga2/tmp", 0700);
 
+       String skelDir = "/share/skel";
+       Utility::GlobRecursive(installDir + skelDir, "*", boost::bind(&CopyConfigFile, installDir, _1, skelDir.GetLength()), GlobFile);
+
        ExecuteIcingaCommand("--scm-install daemon");
 
        return 0;