diff options
author | Melanie | 2010-02-08 15:21:35 +0000 |
---|---|---|
committer | Melanie | 2010-02-08 15:21:35 +0000 |
commit | 70a0d7aa4677c240ad12527adde6725df946e572 (patch) | |
tree | f5fb26c626a2b13c057fd4a0d902346501e176c0 | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim into mysql-p... (diff) | |
download | opensim-SC-70a0d7aa4677c240ad12527adde6725df946e572.zip opensim-SC-70a0d7aa4677c240ad12527adde6725df946e572.tar.gz opensim-SC-70a0d7aa4677c240ad12527adde6725df946e572.tar.bz2 opensim-SC-70a0d7aa4677c240ad12527adde6725df946e572.tar.xz |
Adding the Careminster "Configger" tool to OpenSim. The tool will, when launched
in place of OpenSim, dump the config to stdout. Use -f xml, -f ini or -f mysql
to get a condensed ini file, an xml file suitable for webloading, or a set
of mysql insert statements.
-rw-r--r-- | OpenSim/Tools/Configger/ConfigurationLoader.cs | 251 | ||||
-rw-r--r-- | OpenSim/Tools/Configger/Main.cs | 108 | ||||
-rw-r--r-- | OpenSim/Tools/Configger/Util.cs | 79 | ||||
-rw-r--r-- | prebuild.xml | 22 |
4 files changed, 460 insertions, 0 deletions
diff --git a/OpenSim/Tools/Configger/ConfigurationLoader.cs b/OpenSim/Tools/Configger/ConfigurationLoader.cs new file mode 100644 index 0000000..49af417 --- /dev/null +++ b/OpenSim/Tools/Configger/ConfigurationLoader.cs | |||
@@ -0,0 +1,251 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.IO; | ||
4 | using System.Reflection; | ||
5 | using System.Threading; | ||
6 | using System.Xml; | ||
7 | using log4net; | ||
8 | using Nini.Config; | ||
9 | |||
10 | namespace Careminster | ||
11 | { | ||
12 | /// <summary> | ||
13 | /// Loads the Configuration files into nIni | ||
14 | /// </summary> | ||
15 | public class ConfigurationLoader | ||
16 | { | ||
17 | /// <summary> | ||
18 | /// A source of Configuration data | ||
19 | /// </summary> | ||
20 | protected IConfigSource m_config; | ||
21 | |||
22 | /// <summary> | ||
23 | /// Console logger | ||
24 | /// </summary> | ||
25 | private static readonly ILog m_log = | ||
26 | LogManager.GetLogger( | ||
27 | MethodBase.GetCurrentMethod().DeclaringType); | ||
28 | |||
29 | public ConfigurationLoader() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | /// <summary> | ||
34 | /// Loads the region configuration | ||
35 | /// </summary> | ||
36 | /// <param name="argvSource">Parameters passed into the process when started</param> | ||
37 | /// <param name="configSettings"></param> | ||
38 | /// <param name="networkInfo"></param> | ||
39 | /// <returns>A configuration that gets passed to modules</returns> | ||
40 | public IConfigSource LoadConfigSettings() | ||
41 | { | ||
42 | bool iniFileExists = false; | ||
43 | |||
44 | List<string> sources = new List<string>(); | ||
45 | |||
46 | string iniFileName = "OpenSim.ini"; | ||
47 | string iniFilePath = Path.Combine(".", iniFileName); | ||
48 | |||
49 | if (IsUri(iniFileName)) | ||
50 | { | ||
51 | if (!sources.Contains(iniFileName)) | ||
52 | sources.Add(iniFileName); | ||
53 | } | ||
54 | else | ||
55 | { | ||
56 | if (File.Exists(iniFilePath)) | ||
57 | { | ||
58 | if (!sources.Contains(iniFilePath)) | ||
59 | sources.Add(iniFilePath); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | m_config = new IniConfigSource(); | ||
64 | m_config.Merge(DefaultConfig()); | ||
65 | |||
66 | m_log.Info("[CONFIG] Reading configuration settings"); | ||
67 | |||
68 | if (sources.Count == 0) | ||
69 | { | ||
70 | m_log.FatalFormat("[CONFIG] Could not load any configuration"); | ||
71 | m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); | ||
72 | Environment.Exit(1); | ||
73 | } | ||
74 | |||
75 | for (int i = 0 ; i < sources.Count ; i++) | ||
76 | { | ||
77 | if (ReadConfig(sources[i])) | ||
78 | iniFileExists = true; | ||
79 | AddIncludes(sources); | ||
80 | } | ||
81 | |||
82 | if (!iniFileExists) | ||
83 | { | ||
84 | m_log.FatalFormat("[CONFIG] Could not load any configuration"); | ||
85 | m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!"); | ||
86 | Environment.Exit(1); | ||
87 | } | ||
88 | |||
89 | return m_config; | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// Adds the included files as ini configuration files | ||
94 | /// </summary> | ||
95 | /// <param name="sources">List of URL strings or filename strings</param> | ||
96 | private void AddIncludes(List<string> sources) | ||
97 | { | ||
98 | //loop over config sources | ||
99 | foreach (IConfig config in m_config.Configs) | ||
100 | { | ||
101 | // Look for Include-* in the key name | ||
102 | string[] keys = config.GetKeys(); | ||
103 | foreach (string k in keys) | ||
104 | { | ||
105 | if (k.StartsWith("Include-")) | ||
106 | { | ||
107 | // read the config file to be included. | ||
108 | string file = config.GetString(k); | ||
109 | if (IsUri(file)) | ||
110 | { | ||
111 | if (!sources.Contains(file)) | ||
112 | sources.Add(file); | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | string basepath = Path.GetFullPath("."); | ||
117 | string path = Path.Combine(basepath, file); | ||
118 | string[] paths = Util.Glob(path); | ||
119 | foreach (string p in paths) | ||
120 | { | ||
121 | if (!sources.Contains(p)) | ||
122 | sources.Add(p); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | /// <summary> | ||
130 | /// Check if we can convert the string to a URI | ||
131 | /// </summary> | ||
132 | /// <param name="file">String uri to the remote resource</param> | ||
133 | /// <returns>true if we can convert the string to a Uri object</returns> | ||
134 | bool IsUri(string file) | ||
135 | { | ||
136 | Uri configUri; | ||
137 | |||
138 | return Uri.TryCreate(file, UriKind.Absolute, | ||
139 | out configUri) && configUri.Scheme == Uri.UriSchemeHttp; | ||
140 | } | ||
141 | |||
142 | /// <summary> | ||
143 | /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http | ||
144 | /// </summary> | ||
145 | /// <param name="iniPath">Full path to the ini</param> | ||
146 | /// <returns></returns> | ||
147 | private bool ReadConfig(string iniPath) | ||
148 | { | ||
149 | bool success = false; | ||
150 | |||
151 | if (!IsUri(iniPath)) | ||
152 | { | ||
153 | m_log.InfoFormat("[CONFIG] Reading configuration file {0}", | ||
154 | Path.GetFullPath(iniPath)); | ||
155 | |||
156 | m_config.Merge(new IniConfigSource(iniPath)); | ||
157 | success = true; | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", | ||
162 | iniPath); | ||
163 | |||
164 | // The ini file path is a http URI | ||
165 | // Try to read it | ||
166 | // | ||
167 | try | ||
168 | { | ||
169 | XmlReader r = XmlReader.Create(iniPath); | ||
170 | XmlConfigSource cs = new XmlConfigSource(r); | ||
171 | m_config.Merge(cs); | ||
172 | |||
173 | success = true; | ||
174 | } | ||
175 | catch (Exception e) | ||
176 | { | ||
177 | m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath); | ||
178 | Environment.Exit(1); | ||
179 | } | ||
180 | } | ||
181 | return success; | ||
182 | } | ||
183 | |||
184 | /// <summary> | ||
185 | /// Setup a default config values in case they aren't present in the ini file | ||
186 | /// </summary> | ||
187 | /// <returns>A Configuration source containing the default configuration</returns> | ||
188 | private static IConfigSource DefaultConfig() | ||
189 | { | ||
190 | IConfigSource defaultConfig = new IniConfigSource(); | ||
191 | |||
192 | { | ||
193 | IConfig config = defaultConfig.Configs["Startup"]; | ||
194 | |||
195 | if (null == config) | ||
196 | config = defaultConfig.AddConfig("Startup"); | ||
197 | |||
198 | config.Set("region_info_source", "filesystem"); | ||
199 | |||
200 | config.Set("gridmode", false); | ||
201 | config.Set("physics", "OpenDynamicsEngine"); | ||
202 | config.Set("meshing", "Meshmerizer"); | ||
203 | config.Set("physical_prim", true); | ||
204 | config.Set("see_into_this_sim_from_neighbor", true); | ||
205 | config.Set("serverside_object_permissions", false); | ||
206 | config.Set("storage_plugin", "OpenSim.Data.SQLite.dll"); | ||
207 | config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3"); | ||
208 | config.Set("storage_prim_inventories", true); | ||
209 | config.Set("startup_console_commands_file", String.Empty); | ||
210 | config.Set("shutdown_console_commands_file", String.Empty); | ||
211 | config.Set("DefaultScriptEngine", "XEngine"); | ||
212 | config.Set("clientstack_plugin", "OpenSim.Region.ClientStack.LindenUDP.dll"); | ||
213 | // life doesn't really work without this | ||
214 | config.Set("EventQueue", true); | ||
215 | } | ||
216 | |||
217 | { | ||
218 | IConfig config = defaultConfig.Configs["StandAlone"]; | ||
219 | |||
220 | if (null == config) | ||
221 | config = defaultConfig.AddConfig("StandAlone"); | ||
222 | |||
223 | config.Set("accounts_authenticate", true); | ||
224 | config.Set("welcome_message", "Welcome to OpenSimulator"); | ||
225 | config.Set("inventory_plugin", "OpenSim.Data.SQLite.dll"); | ||
226 | config.Set("inventory_source", ""); | ||
227 | config.Set("userDatabase_plugin", "OpenSim.Data.SQLite.dll"); | ||
228 | config.Set("user_source", ""); | ||
229 | config.Set("LibrariesXMLFile", string.Format(".{0}inventory{0}Libraries.xml", Path.DirectorySeparatorChar)); | ||
230 | } | ||
231 | |||
232 | { | ||
233 | IConfig config = defaultConfig.Configs["Network"]; | ||
234 | |||
235 | if (null == config) | ||
236 | config = defaultConfig.AddConfig("Network"); | ||
237 | |||
238 | config.Set("default_location_x", 1000); | ||
239 | config.Set("default_location_y", 1000); | ||
240 | config.Set("grid_send_key", "null"); | ||
241 | config.Set("grid_recv_key", "null"); | ||
242 | config.Set("user_send_key", "null"); | ||
243 | config.Set("user_recv_key", "null"); | ||
244 | config.Set("secure_inventory_server", "true"); | ||
245 | } | ||
246 | |||
247 | return defaultConfig; | ||
248 | } | ||
249 | |||
250 | } | ||
251 | } | ||
diff --git a/OpenSim/Tools/Configger/Main.cs b/OpenSim/Tools/Configger/Main.cs new file mode 100644 index 0000000..c85f0d2 --- /dev/null +++ b/OpenSim/Tools/Configger/Main.cs | |||
@@ -0,0 +1,108 @@ | |||
1 | using Nini.Config; | ||
2 | using System; | ||
3 | |||
4 | namespace Careminster | ||
5 | { | ||
6 | public class Configger | ||
7 | { | ||
8 | public static int Main(string[] args) | ||
9 | { | ||
10 | ArgvConfigSource argvConfig = new ArgvConfigSource(args); | ||
11 | argvConfig.AddSwitch("Startup", "format", "f"); | ||
12 | |||
13 | IConfig startupConfig = argvConfig.Configs["Startup"]; | ||
14 | |||
15 | string format = startupConfig.GetString("format", "ini"); | ||
16 | |||
17 | ConfigurationLoader loader = new ConfigurationLoader(); | ||
18 | |||
19 | IConfigSource s = loader.LoadConfigSettings(); | ||
20 | |||
21 | if (format == "mysql") | ||
22 | { | ||
23 | foreach (IConfig c in s.Configs) | ||
24 | { | ||
25 | foreach (string k in c.GetKeys()) | ||
26 | { | ||
27 | string v = c.GetString(k); | ||
28 | |||
29 | if (k.StartsWith("Include-")) | ||
30 | continue; | ||
31 | Console.WriteLine("insert ignore into config (section, name, value) values ('{0}', '{1}', '{2}');", c.Name, k, v); | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | else if (format == "xml") | ||
36 | { | ||
37 | Console.WriteLine("<Nini>"); | ||
38 | |||
39 | foreach (IConfig c in s.Configs) | ||
40 | { | ||
41 | int count = 0; | ||
42 | |||
43 | foreach (string k in c.GetKeys()) | ||
44 | { | ||
45 | if (k.StartsWith("Include-")) | ||
46 | continue; | ||
47 | |||
48 | count++; | ||
49 | } | ||
50 | |||
51 | if (count > 0) | ||
52 | { | ||
53 | Console.WriteLine("<Section Name=\"{0}\">", c.Name); | ||
54 | |||
55 | foreach (string k in c.GetKeys()) | ||
56 | { | ||
57 | string v = c.GetString(k); | ||
58 | |||
59 | if (k.StartsWith("Include-")) | ||
60 | continue; | ||
61 | Console.WriteLine(" <Key Name=\"{0}\" Value=\"{1}\" />", k, v); | ||
62 | |||
63 | Console.WriteLine("</Section>"); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | Console.WriteLine("</Nini>"); | ||
68 | } | ||
69 | else if (format == "ini") | ||
70 | { | ||
71 | foreach (IConfig c in s.Configs) | ||
72 | { | ||
73 | int count = 0; | ||
74 | |||
75 | foreach (string k in c.GetKeys()) | ||
76 | { | ||
77 | if (k.StartsWith("Include-")) | ||
78 | continue; | ||
79 | |||
80 | count++; | ||
81 | } | ||
82 | |||
83 | if (count > 0) | ||
84 | { | ||
85 | Console.WriteLine("[{0}]", c.Name); | ||
86 | |||
87 | foreach (string k in c.GetKeys()) | ||
88 | { | ||
89 | string v = c.GetString(k); | ||
90 | |||
91 | if (k.StartsWith("Include-")) | ||
92 | continue; | ||
93 | Console.WriteLine("{0} = \"{1}\"", k, v); | ||
94 | } | ||
95 | |||
96 | Console.WriteLine(); | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | Console.WriteLine("Error: unknown format: {0}", format); | ||
103 | } | ||
104 | |||
105 | return 0; | ||
106 | } | ||
107 | } | ||
108 | } | ||
diff --git a/OpenSim/Tools/Configger/Util.cs b/OpenSim/Tools/Configger/Util.cs new file mode 100644 index 0000000..6f8aa76 --- /dev/null +++ b/OpenSim/Tools/Configger/Util.cs | |||
@@ -0,0 +1,79 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Globalization; | ||
5 | using System.IO; | ||
6 | using System.IO.Compression; | ||
7 | using System.Net; | ||
8 | using System.Net.Sockets; | ||
9 | using System.Reflection; | ||
10 | using System.Text; | ||
11 | using System.Text.RegularExpressions; | ||
12 | using System.Threading; | ||
13 | using log4net; | ||
14 | using Nini.Config; | ||
15 | |||
16 | namespace Careminster | ||
17 | { | ||
18 | public static class Util | ||
19 | { | ||
20 | public static string[] Glob(string path) | ||
21 | { | ||
22 | string vol=String.Empty; | ||
23 | |||
24 | if (Path.VolumeSeparatorChar != Path.DirectorySeparatorChar) | ||
25 | { | ||
26 | string[] vcomps = path.Split(new char[] {Path.VolumeSeparatorChar}, 2, StringSplitOptions.RemoveEmptyEntries); | ||
27 | |||
28 | if (vcomps.Length > 1) | ||
29 | { | ||
30 | path = vcomps[1]; | ||
31 | vol = vcomps[0]; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | string[] comps = path.Split(new char[] {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries); | ||
36 | |||
37 | // Glob | ||
38 | |||
39 | path = vol; | ||
40 | if (vol != String.Empty) | ||
41 | path += new String(new char[] {Path.VolumeSeparatorChar, Path.DirectorySeparatorChar}); | ||
42 | else | ||
43 | path = new String(new char[] {Path.DirectorySeparatorChar}); | ||
44 | |||
45 | List<string> paths = new List<string>(); | ||
46 | List<string> found = new List<string>(); | ||
47 | paths.Add(path); | ||
48 | |||
49 | int compIndex = -1; | ||
50 | foreach (string c in comps) | ||
51 | { | ||
52 | compIndex++; | ||
53 | |||
54 | List<string> addpaths = new List<string>(); | ||
55 | foreach (string p in paths) | ||
56 | { | ||
57 | string[] dirs = Directory.GetDirectories(p, c); | ||
58 | |||
59 | if (dirs.Length != 0) | ||
60 | { | ||
61 | foreach (string dir in dirs) | ||
62 | addpaths.Add(Path.Combine(path, dir)); | ||
63 | } | ||
64 | |||
65 | // Only add files if that is the last path component | ||
66 | if (compIndex == comps.Length - 1) | ||
67 | { | ||
68 | string[] files = Directory.GetFiles(p, c); | ||
69 | foreach (string f in files) | ||
70 | found.Add(f); | ||
71 | } | ||
72 | } | ||
73 | paths = addpaths; | ||
74 | } | ||
75 | |||
76 | return found.ToArray(); | ||
77 | } | ||
78 | } | ||
79 | } | ||
diff --git a/prebuild.xml b/prebuild.xml index 46a1057..ac4400d 100644 --- a/prebuild.xml +++ b/prebuild.xml | |||
@@ -2886,6 +2886,28 @@ | |||
2886 | </Files> | 2886 | </Files> |
2887 | </Project> | 2887 | </Project> |
2888 | 2888 | ||
2889 | <Project frameworkVersion="v3_5" name="OpenSim.Tools.Configger" path="OpenSim/Tools/Configger" type="Exe"> | ||
2890 | <Configuration name="Debug"> | ||
2891 | <Options> | ||
2892 | <OutputPath>../../../bin/</OutputPath> | ||
2893 | </Options> | ||
2894 | </Configuration> | ||
2895 | <Configuration name="Release"> | ||
2896 | <Options> | ||
2897 | <OutputPath>../../../bin/</OutputPath> | ||
2898 | </Options> | ||
2899 | </Configuration> | ||
2900 | |||
2901 | <ReferencePath>../../../bin/</ReferencePath> | ||
2902 | <Reference name="System"/> | ||
2903 | <Reference name="Nini.dll"/> | ||
2904 | <Reference name="log4net.dll"/> | ||
2905 | |||
2906 | <Files> | ||
2907 | <Match pattern="*.cs" recurse="true"/> | ||
2908 | </Files> | ||
2909 | </Project> | ||
2910 | |||
2889 | <!-- Test Suite --> | 2911 | <!-- Test Suite --> |
2890 | <Project frameworkVersion="v3_5" name="OpenSim.TestSuite" path="OpenSim/TestSuite" type="Exe"> | 2912 | <Project frameworkVersion="v3_5" name="OpenSim.TestSuite" path="OpenSim/TestSuite" type="Exe"> |
2891 | <Configuration name="Debug"> | 2913 | <Configuration name="Debug"> |