Пример #1
0
        static private void insert_value_after_comment_or_end_in_minionconfig_file(Session session, string key, string value)
        {
            string MINION_CONFIGFILE = MinionConfigurationUtilities.getConfigFileLocation_DECAC(session);

            string[] configLines_in        = File.ReadAllLines(MINION_CONFIGFILE);
            string[] configLines_out       = new string[configLines_in.Length + 1];
            int      configLines_out_index = 0;

            session.Log("...insert_value_after_comment_or_end  key  {0}", key);
            session.Log("...insert_value_after_comment_or_end  value  {0}", value);
            bool found = false;

            for (int i = 0; i < configLines_in.Length; i++)
            {
                configLines_out[configLines_out_index++] = configLines_in[i];
                if (!found && configLines_in[i].StartsWith("#" + key + ":"))
                {
                    found = true;
                    session.Log("...insert_value_after_comment_or_end..found the # in       {0}", configLines_in[i]);
                    configLines_out[configLines_out_index++] = key + ": " + value;
                }
            }
            if (!found)
            {
                session.Log("...insert_value_after_comment_or_end..end");
                configLines_out[configLines_out_index++] = key + ": " + value;
            }
            File.WriteAllLines(MINION_CONFIGFILE, configLines_out);
        }
        private static bool replace_pattern_in_config_file_DECAC(Session session, string pattern, string replacement)
        {
            /*
             * config file means: conf/minion
             */
            bool   replaced_in_any_file = false;
            string MINION_CONFIGFILE    = MinionConfigurationUtilities.getConfigFileLocation_DECAC(session);

            replaced_in_any_file |= replace_in_file_DECAC(session, MINION_CONFIGFILE, pattern, replacement);

            return(replaced_in_any_file);
        }
Пример #3
0
        private static bool replace_pattern_in_all_config_files_DECAC(Session session, string pattern, string replacement)
        {
            /*
             * "All config" files means:
             *   conf/minion
             *   conf/minion.d/*.conf           (only for New)
             *
             * MAYBE this function could input a dictionary of key/value pairs, because it reopens all config files over and over.
             *
             */
            bool   replaced_in_any_file = false;
            string MINION_CONFIGFILE    = MinionConfigurationUtilities.getConfigFileLocation_DECAC(session);
            string MINION_CONFIGDIR     = MinionConfigurationUtilities.getConfigdDirectoryLocation_DECAC(session);

            replaced_in_any_file |= replace_in_file_DECAC(session, MINION_CONFIGFILE, pattern, replacement);

            // Shane wants that the installer changes only the MINION_CONFIGFILE, not the minion.d/*.conf files
            if (session.CustomActionData["config_type"] == "New")
            {
                // Go into the minion.d/ folder
                if (Directory.Exists(MINION_CONFIGDIR))
                {
                    var conf_files = System.IO.Directory.GetFiles(MINION_CONFIGDIR, "*.conf");
                    foreach (var conf_file in conf_files)
                    {
                        // skip _schedule.conf
                        if (conf_file.EndsWith("_schedule.conf"))
                        {
                            continue;
                        }
                        replaced_in_any_file |= replace_in_file_DECAC(session, conf_file, pattern, replacement);
                    }
                }
            }
            return(replaced_in_any_file);
        }