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 |
return 0; |
134 |
} |
135 |
|
136 |
string platform() |
137 |
{ |
138 |
utsname* computer = new utsname; |
139 |
uname(computer); |
140 |
|
141 |
string os = computer->sysname; |
142 |
string version = computer->release; |
143 |
string architecture = computer->machine; |
144 |
|
145 |
delete computer; |
146 |
|
147 |
string platform = "(" + os + " " + version + " " + architecture + ")"; |
148 |
|
149 |
return platform; |
150 |
} |
151 |
|
152 |
void usage() |
153 |
{ |
154 |
cout << "Usage: " << program << " [-make host ...] [-mount host ...] [-D] " |
155 |
<< "[-version] [-help]\n" |
156 |
<< "Options:\n" |
157 |
<< " -make host Make the mount tree for host\n" |
158 |
<< " -mount host Mount the shares on host to its tree\n" |
159 |
<< " -D Display debug information\n" |
160 |
<< " -version Display version information and exit\n" |
161 |
<< " -help Display this message and exit\n"; |
162 |
} |
163 |
|
164 |
void version() |
165 |
{ |
166 |
cout << programName << " " << programVersion << " "<< platform() << "\n\n" |
167 |
<< " Copyright (C) 2003, Douglas Thrift. All Rights Reserved.\n\n" |
168 |
<< " This product includes software developed by Douglas Thrift\n" |
169 |
<< " (http://computers.douglasthrift.net/).\n"; |
170 |
} |
171 |
|
172 |
void configure() |
173 |
{ |
174 |
string conf = config.install + "/conf/spectre.conf"; |
175 |
|
176 |
ifstream fin(conf.c_str()); |
177 |
|
178 |
if (!fin.is_open()) |
179 |
{ |
180 |
cerr << program << ": Could not open " << conf << "\n"; |
181 |
exit(1); |
182 |
} |
183 |
|
184 |
do |
185 |
{ |
186 |
// |
187 |
} |
188 |
while (fin.good()); |
189 |
|
190 |
fin.close(); |
191 |
} |