2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// Spectre.cpp |
5 |
> |
// $Id: Spectre.cpp,v 1.12 2003/07/31 00:56:29 douglas Exp $ |
6 |
|
|
7 |
|
#include "Spectre.h" |
8 |
|
#include "Maker.h" |
9 |
|
#include "Mounter.h" |
10 |
+ |
#include "Unmounter.h" |
11 |
|
|
12 |
|
string program; |
13 |
|
string programName = "Spectre Samba Mounter"; |
20 |
|
void automake(set<string>& makes); |
21 |
|
void automake(set<string>& makes, ipstream& pin); |
22 |
|
void automount(set<string>& mounts); |
23 |
+ |
void autounmount(set<string>& unmounts); |
24 |
|
void configure(); |
25 |
|
|
26 |
|
int main(int argc, char* argv[]) |
43 |
|
|
44 |
|
bool make = false; |
45 |
|
bool mount = false; |
46 |
+ |
bool unmount = false; |
47 |
|
bool automake = false; |
48 |
|
bool automount = false; |
49 |
+ |
bool autounmount = false; |
50 |
|
|
51 |
|
set<string> makes; |
52 |
|
set<string> mounts; |
53 |
+ |
set<string> unmounts; |
54 |
|
|
55 |
|
for (int index = 1; index < args.size(); index++) |
56 |
|
{ |
94 |
|
return 1; |
95 |
|
} |
96 |
|
} |
97 |
+ |
else if (args[index] == "-unmount") |
98 |
+ |
{ |
99 |
+ |
if (!unmount) unmount = true; |
100 |
+ |
|
101 |
+ |
if (++index < args.size()) |
102 |
+ |
{ |
103 |
+ |
unmounts.insert(args[index]); |
104 |
+ |
} |
105 |
+ |
else |
106 |
+ |
{ |
107 |
+ |
cerr << program << ": Bad arguments\n"; |
108 |
+ |
usage(); |
109 |
+ |
return 1; |
110 |
+ |
} |
111 |
+ |
} |
112 |
|
else if (args[index] == "-automake") |
113 |
|
{ |
114 |
|
if (!automake) automake = true; |
117 |
|
{ |
118 |
|
if (!automount) automount = true; |
119 |
|
} |
120 |
+ |
else if (args[index] == "-autounmount") |
121 |
+ |
{ |
122 |
+ |
if (!autounmount) autounmount = true; |
123 |
+ |
} |
124 |
|
else if (args[index] == "-D") |
125 |
|
{ |
126 |
|
if (!debug) |
131 |
|
} |
132 |
|
} |
133 |
|
|
134 |
< |
if (!make && !mount && !automake && !automount) |
134 |
> |
if (!make && !mount && !unmount && !automake && !automount && !autounmount) |
135 |
|
{ |
136 |
|
usage(); |
137 |
|
return 0; |
159 |
|
} |
160 |
|
|
161 |
|
cerr << (mount ? "}\n" : "") |
162 |
+ |
<< "unmount = " << unmount << "\n" |
163 |
+ |
<< (unmount ? "unmounts = {\n" : ""); |
164 |
+ |
|
165 |
+ |
for (set<string>::iterator itor = unmounts.begin(); itor != |
166 |
+ |
unmounts.end(); itor++) |
167 |
+ |
{ |
168 |
+ |
cerr << " " << *itor << "\n"; |
169 |
+ |
} |
170 |
+ |
|
171 |
+ |
cerr << (unmount ? "}\n" : "") |
172 |
|
<< "automake = " << automake << "\n" |
173 |
|
<< "automount = " << automount << "\n" |
174 |
+ |
<< "autounmount = " << autounmount << "\n" |
175 |
|
<< "config.install = " << config.install << "\n"; |
176 |
|
} |
177 |
|
|
182 |
|
cerr << "config.findsmb = " << config.findsmb << "\n" |
183 |
|
<< "config.smbclient = " << config.smbclient << "\n" |
184 |
|
<< "config.mount = " << config.mount << "\n" |
185 |
+ |
<< "config.umount = " << config.umount << "\n" |
186 |
|
<< "config.root = " << config.root << "\n" |
187 |
|
<< (!config.hosts.empty() ? "config.hosts = {\n" : ""); |
188 |
|
|
221 |
|
} |
222 |
|
} |
223 |
|
|
224 |
+ |
if (autounmount) ::autounmount(unmounts); |
225 |
+ |
|
226 |
+ |
if (unmount || autounmount) |
227 |
+ |
{ |
228 |
+ |
for (set<string>::iterator itor = unmounts.begin(); itor != |
229 |
+ |
unmounts.end(); itor++) |
230 |
+ |
{ |
231 |
+ |
Unmounter unmounter(*itor); |
232 |
+ |
|
233 |
+ |
unmounter.unmount(); |
234 |
+ |
} |
235 |
+ |
} |
236 |
+ |
|
237 |
|
return 0; |
238 |
|
} |
239 |
|
|
257 |
|
{ |
258 |
|
string tab(8 + program.length(), ' '); |
259 |
|
|
260 |
< |
cout << "Usage: " << program << " [-make host ...] [-mount host ...]\n" |
261 |
< |
<< tab << "[-automake] [-automount]\n" |
260 |
> |
cout << "Usage: " << program << " [-make host ...] [-mount host ...] [-unm" |
261 |
> |
<< "ount host ...]\n" |
262 |
> |
<< tab << "[-automake] [-automount] [-autounmount]\n" |
263 |
|
<< tab << "[-D] [-version] [-help]\n" |
264 |
|
<< "Options:\n" |
265 |
|
<< " -make host Make the mount tree for host\n" |
266 |
|
<< " -mount host Mount the shares on host to its tree\n" |
267 |
+ |
<< " -unmount host Unmount the shares on host from its tree\n" |
268 |
|
<< " -automake Automagically make the mount tree\n" |
269 |
|
<< " -automount Automagically mount shares to the tree\n" |
270 |
+ |
<< " -autounmount Automagically unmount dead shares from the tre" |
271 |
+ |
<< "e\n" |
272 |
|
<< " -D Display debug information\n" |
273 |
|
<< " -version Display version information and exit\n" |
274 |
|
<< " -help Display this message and exit\n"; |
431 |
|
} |
432 |
|
} |
433 |
|
|
434 |
+ |
void autounmount(set<string>& unmounts) |
435 |
+ |
{ |
436 |
+ |
// |
437 |
+ |
} |
438 |
+ |
|
439 |
|
void configure() |
440 |
|
{ |
441 |
|
string conf = config.install + "/conf/spectre.conf"; |