ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Spectre/Spectre.cpp
Revision: 160
Committed: 2003-06-09T21:03:18-07:00 (22 years ago) by douglas
File size: 4715 byte(s)
Log Message:
Added stuff and finished the starter code.

File Contents

# Content
1 // Spectre Samba Mounter
2 //
3 // Douglas Thrift
4 //
5 // Spectre.cpp
6
7 #include "Spectre.h"
8 #include "Maker.h"
9 #include "Mounter.h"
10
11 string program;
12 string programName = "Spectre Samba Mounter";
13 string programVersion = "1.0alpha";
14 bool debug = false;
15
16 Config config;
17
18 int main(int argc, char* argv[])
19 {
20 program = argv[0];
21
22 #include "configure.h"
23
24 bool make = false;
25 bool mount = false;
26
27 set<string> makes;
28 set<string> mounts;
29
30 for (int index = 1; index < argc; index++)
31 {
32 string arg = argv[index];
33
34 if (arg == "-help")
35 {
36 usage();
37 return 0;
38 }
39 else if (arg == "-version")
40 {
41 version();
42 return 0;
43 }
44 else if (arg == "-make")
45 {
46 if (!make) make = true;
47
48 if (++index < argc)
49 {
50 makes.insert(argv[index]);
51 }
52 else
53 {
54 cerr << program << ": Bad arguments\n";
55 usage();
56 return 1;
57 }
58 }
59 else if (arg == "-mount")
60 {
61 if (!mount) mount = true;
62
63 if (++index < argc)
64 {
65 mounts.insert(argv[index]);
66 }
67 else
68 {
69 cerr << program << ": Bad arguments\n";
70 usage();
71 return 1;
72 }
73 }
74 else if (arg == "-D")
75 {
76 if (!debug)
77 {
78 debug = true;
79 cerr.setf(ios_base::boolalpha);
80 }
81 }
82 }
83
84 if (!make && !mount)
85 {
86 usage();
87 return 0;
88 }
89
90 if (debug)
91 {
92 cerr << "make = " << make << "\n"
93 << (make ? "makes = {\n" : "");
94
95 for (set<string>::iterator itor = makes.begin(); itor != makes.end();
96 itor++)
97 {
98 cerr << " " << *itor << "\n";
99 }
100
101 cerr << (make ? "}\n" : "")
102 << "mount = " << mount << "\n"
103 << (mount ? "mounts = {\n" : "");
104
105 for (set<string>::iterator itor = mounts.begin(); itor != mounts.end();
106 itor++)
107 {
108 cerr << " " << *itor << "\n";
109 }
110
111 cerr << (mount ? "}\n" : "")
112 << "config.install = " << config.install << "\n";
113 }
114
115 configure();
116
117 if (debug)
118 {
119 cerr << "config.smbclient = " << config.smbclient << "\n"
120 << "config.mount = " << config.mount << "\n"
121 << "config.root = " << config.root << "\n"
122 << (!config.hosts.empty() ? "config.hosts = {\n" : "");
123
124 for (multimap<string, string>::iterator itor = config.hosts.begin();
125 itor != config.hosts.end(); itor++)
126 {
127 cerr << " " << itor->first << " = " << itor->second << "\n";
128 }
129
130 cerr << (!config.hosts.empty() ? "}\n" : "");
131 }
132
133 if (make)
134 {
135 for (set<string>::iterator itor = makes.begin(); itor != makes.end();
136 itor++)
137 {
138 Maker maker(*itor);
139
140 maker.make();
141 }
142 }
143
144 if (mount)
145 {
146 for (set<string>::iterator itor = mounts.begin(); itor != mounts.end();
147 itor++)
148 {
149 Mounter mounter(*itor);
150
151 mounter.mount();
152 }
153 }
154
155 return 0;
156 }
157
158 string platform()
159 {
160 utsname* computer = new utsname;
161 uname(computer);
162
163 string os = computer->sysname;
164 string version = computer->release;
165 string architecture = computer->machine;
166
167 delete computer;
168
169 string platform = "(" + os + " " + version + " " + architecture + ")";
170
171 return platform;
172 }
173
174 void usage()
175 {
176 cout << "Usage: " << program << " [-make host ...] [-mount host ...] [-D] "
177 << "[-version] [-help]\n"
178 << "Options:\n"
179 << " -make host Make the mount tree for host\n"
180 << " -mount host Mount the shares on host to its tree\n"
181 << " -D Display debug information\n"
182 << " -version Display version information and exit\n"
183 << " -help Display this message and exit\n";
184 }
185
186 void version()
187 {
188 cout << programName << " " << programVersion << " "<< platform() << "\n\n"
189 << " Copyright (C) 2003, Douglas Thrift. All Rights Reserved.\n\n"
190 << " This product includes software developed by Douglas Thrift\n"
191 << " (http://computers.douglasthrift.net/).\n";
192 }
193
194 void configure()
195 {
196 string conf = config.install + "/conf/spectre.conf";
197
198 ifstream fin(conf.c_str());
199
200 if (!fin.is_open())
201 {
202 cerr << program << ": Could not open " << conf << "\n";
203 exit(1);
204 }
205
206 do
207 {
208 string line;
209
210 getline(fin, line);
211
212 if (line.find('#') == 0 || line == "")
213 {
214 // ignore
215 }
216 else if (line.find("smbclient=") == 0)
217 {
218 config.smbclient = line.substr(10);
219 }
220 else if (line.find("mount=") == 0)
221 {
222 config.mount = line.substr(6);
223 }
224 else if (line.find("root=") == 0)
225 {
226 config.root = line.substr(5);
227 }
228 else if (line.find("host=") == 0)
229 {
230 string host = line.substr(5);
231
232 getline(fin, line);
233
234 if (line != "{")
235 {
236 cerr << program << ": Munged configuration for " << host
237 << "\n";
238 exit(1);
239 }
240
241 do
242 {
243 getline(fin, line);
244
245 if (line.find("\t#") == 0)
246 {
247 // ignore
248 }
249 else if (line.find('\t') == 0)
250 {
251 config.hosts.insert(pair<string, string>(host,
252 line.substr(1)));
253 }
254 else if (line == "}")
255 {
256 break;
257 }
258 }
259 while (fin.good());
260 }
261 }
262 while (fin.good());
263
264 fin.close();
265 }