-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
347 lines (271 loc) · 9.83 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#include <iostream>
#include <vector>
#include <string>
#include <unistd.h>
#include "qubespkg.h"
#include "debiancontrolfile.h"
#include "qubesinstallhelper.h"
using namespace std;
std::vector<qubesPkg*> getPackages()
{
std::vector<qubesPkg*> packages{};
qubesPkg* qPack=nullptr;
//load package list
qPack=new qubesPkg("qubes-core-vchan-xen");
qPack->addPackageName("libvchan-xen", PkgInstallFlag::ALL);
qPack->addPackageName("libvchan-xen-dev", PkgInstallFlag::FOR_DEV);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-core-qubesdb");
qPack->addPackageName("libqubesdb", PkgInstallFlag::ALL);
qPack->addPackageName("qubesdb-dev", PkgInstallFlag::FOR_DEV);
qPack->addPackageName("python3-qubesdb", PkgInstallFlag::ALL);
qPack->addPackageName("qubesdb", PkgInstallFlag::ALL);
qPack->addPackageName("qubesdb-dom0", PkgInstallFlag::FOR_PROD);
qPack->addPackageName("qubesdb-vm", PkgInstallFlag::IGNORE);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-core-qrexec");
qPack->addPackageName("libqrexec-utils2", PkgInstallFlag::ALL);
qPack->addPackageName("libqrexec-utils-dev", PkgInstallFlag::FOR_DEV);
qPack->addPackageName("qubes-core-qrexec", PkgInstallFlag::FOR_PROD);
qPack->addPackageName("qubes-core-qrexec-dom0", PkgInstallFlag::FOR_PROD);
qPack->addPackageName("python3-qrexec", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-rpm-oxide");
qPack->addPackageName("qubes-rpm-oxide", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-linux-utils");
qPack->addPackageName("python3-qubesimgconverter", PkgInstallFlag::ALL);
qPack->addPackageName("qubes-utils", PkgInstallFlag::FOR_PROD);
qPack->addPackageName("qubes-kernel-vm-support", PkgInstallFlag::IGNORE);
qPack->addPackageName("libqubes-pure0", PkgInstallFlag::ALL);
qPack->addPackageName("libqubes-rpc-filecopy2", PkgInstallFlag::ALL);
qPack->addPackageName("libqubes-rpc-filecopy-dev", PkgInstallFlag::FOR_DEV);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-linux-kernel");
qPack->addPackageName("kernel-latest-qubes-vm", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-core-agent-linux");
qPack->addPackageName("qubes-core-agent-dom0-updates", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-core-admin"); //no debian files in qubes github repo
qPack->addPackageName("qubes-core-dom0", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-repo-templates");
qPack->addPackageName("qubes-repo-templates", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-gui-common");
qPack->addPackageName("qubes-gui-common", PkgInstallFlag::ALL);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-gui-daemon");
qPack->addPackageName("qubes-gui-daemon", PkgInstallFlag::FOR_PROD);
qPack->addPackageName("qubes-gui-daemon-pulseaudio", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-gui-agent-linux"); //issue with missing Trolltech.conf
qPack->addPackageName("qubes-gui-agent", PkgInstallFlag::IGNORE);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-core-admin-client"); //sphinxdoc throws error
qPack->addPackageName("python3-qubesadmin", PkgInstallFlag::FOR_PROD);
qPack->addPackageName("qubes-core-admin-client", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-app-linux-img-converter");
qPack->addPackageName("qubes-img-converter", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-artwork"); //needs dependency qubesimgconverter
qPack->addPackageName("qubes-artwork", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-python-qasync");
qPack->addPackageName("python3-qasync", PkgInstallFlag::ALL);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-desktop-linux-common");
qPack->addPackageName("qubes-desktop-linux-common", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
qPack=new qubesPkg("qubes-manager"); //has qubes-python-qasync dependency
qPack->addPackageName("qubes-manager", PkgInstallFlag::FOR_PROD);
packages.push_back(qPack);
return packages;
}
int main(int argc, char** argv)
{
std::vector<qubesPkg*> packages{};
qubesInstallHelper* helper=nullptr;
std::string arg{};
std::string folderName{"output"};
std::string dlProject{};
int ret{0};
bool hasError{false};
bool createPackages{false};
bool downloadProject{false};
bool foundProject{false};
bool installQubes{false};
bool installQubesManagerOnly{false};
bool showHelp{true};
bool noRoot{false};
bool debug{false};
cout << "---Qubes debian/ubuntu package creator & installer---" << endl;
if (argc<=1)
showHelp=true;
else
{
for(int i=1; i <argc; ++i)
{
arg=argv[i];
if (arg=="-create")
{
createPackages=true;
showHelp=false;
}
else if (arg.length()>=8 && arg.substr(0,8)=="-install")
{
if (arg.substr(8)=="=qubes-manager")
{
installQubesManagerOnly=true;
}
installQubes=true;
showHelp=downloadProject;
}
else if (arg.length()>=10 && arg.substr(0,10)=="-download=")
{
dlProject=arg.substr(10);
downloadProject=true;
showHelp=installQubes;
}
else if (arg.length()>8 && arg.substr(0,8)=="-folder=")
{
folderName=arg.substr(8);
}
else if (arg=="-noroot")
{
noRoot=true;
}
else if (arg=="-help")
{
showHelp=true;
break;
}
else if (arg=="-debug")
{
debug=true;
}
}
}
if (showHelp)
{
cout << "Possible args:" << endl;
cout << "-create create the debian packages" << endl;
cout << "-install install qubes with the debian packages" << endl;
cout << "-download=[PROJECTNAME] download project" << endl;
cout << "-folder=[NAME] set the folder name, default is output" << endl;
cout << "-noroot ignore missing root privileges" << endl;
return 0;
}
if (!noRoot && getuid()!=0)
{
cout << "This app needs to run as root." << endl;
return -2;
}
packages=getPackages();
if (createPackages)
{
cout << "deb files will be created in the output folder" << endl;
cout << "starting with downloading and creating deb packages..." << endl;
qubesPkg::outputFolder=folderName;
qubesPkg::initForCreate();
for(auto p :packages)
{
ret=p->download();
if (ret!=0)
{
cout << "Error while downloading project " << p->projectName << endl;
hasError=true;
break;
}
ret=p->readVersion();
if (ret!=0)
{
cout << "Error while reading version of project " << p->projectName << endl;
hasError=true;
break;
}
ret=p->createPackage();
if (ret!=0)
{
cout << "Error while create package of project " << p->projectName << endl;
hasError=true;
break;
}
ret=p->installPackages(false);
if (ret!=0)
{
cout << "Error while install package(s) of project " << p->projectName << endl;
hasError=true;
break;
}
if (debug)
{
cout << "press key to continue with next package"<<endl;
cin.get();
}
}
if (hasError)
{
getchar();
return ret;
}
cout << "Clean up" << endl;
for(auto p :packages)
{
p->cleanUp();
}
cout << "Created all packages, ready for install" << endl;
}
else if (downloadProject)
{
cout << "repo files will be downloaded in the output folder" << endl;
cout << "starting with downloading..." << endl;
qubesPkg::outputFolder=folderName;
qubesPkg::initForCreate();
for(auto p :packages)
{
if (p->projectName==dlProject)
{
foundProject=true;
ret=p->download(false);
if (ret!=0)
{
cout << "Error while downloading project " << p->projectName << endl;
hasError=true;
break;
}
//download only one project
break;
}
}
if (!foundProject)
{
cout << "Error couldn't find project " << dlProject << endl;
}
else if (hasError)
{
getchar();
return ret;
}
else
cout << "Downloaded project" << endl;
}
if (installQubes)
{
cout << "starting with installation..." << endl;
helper=new qubesInstallHelper(packages,folderName,installQubesManagerOnly);
helper->debug=debug;
if (helper->install())
{
cout << endl << "installation finished, please reboot" << endl;
}
}
else
{
cout << endl << "reached end of programm..." << endl;
}
getchar();
return 0;
}