/
ssuks.cpp
120 lines (99 loc) · 3.36 KB
/
ssuks.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
/**
* @file ssuks.cpp
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bernd.wachter@jollamobile.com>
* @date 2013
*/
#include <QCoreApplication>
#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>
#include <QTimer>
#include <QStringList>
#include <QDirIterator>
#include "ssukickstarter.h"
#include "constants.h"
#include "libssu/sandbox_p.h"
#include "libssu/ssusettings_p.h"
#include "ssuks.h"
void SsuKs::run()
{
QStringList arguments = QCoreApplication::arguments();
// get rid of the binary name
arguments.removeFirst();
QTextStream qout(stdout);
QTextStream qerr(stderr);
QHash<QString, QString> repoParameters;
if (arguments.count() == 1 &&
(arguments.at(0) == "help" ||
arguments.at(0) == "--help" ||
arguments.at(0) == "-h")) {
usage();
return;
}
QString fileName;
if (arguments.count() >= 1 && !arguments.at(0).contains("=")) {
fileName = arguments.at(0);
arguments.removeFirst();
}
for (int i = 0; i < arguments.count(); i++) {
if (arguments.at(i).count("=") != 1) {
qout << "Invalid flag: " << arguments.at(i) << endl;
QCoreApplication::exit(1);
return;
}
QStringList split = arguments.at(i).split("=");
repoParameters.insert(split.at(0), split.at(1));
}
QString sandbox;
Sandbox *sb;
if (repoParameters.contains("sandbox")) {
sandbox = repoParameters.value("sandbox");
repoParameters.remove("sandbox");
sb = new Sandbox(sandbox, Sandbox::UseDirectly, Sandbox::ThisProcess);
if (!sb->addWorldFiles(SSU_DATA_DIR)) {
qerr << "Failed to copy files into sandbox, using empty sandbox" << endl;
}
if (sb->activate())
qerr << "Using sandbox at " << sandbox << endl;
else {
qerr << "Failed to activate sandbox" << endl;
QCoreApplication::exit(1);
return;
}
// force re-merge of settings
QFile::remove(Sandbox::map(SSU_BOARD_MAPPING_CONFIGURATION));
SsuSettings(SSU_BOARD_MAPPING_CONFIGURATION, SSU_BOARD_MAPPING_CONFIGURATION_DIR);
}
SsuKickstarter kickstarter;
kickstarter.setRepoParameters(repoParameters);
QCoreApplication::exit(!kickstarter.write(fileName));
return;
QCoreApplication::exit(0);
}
void SsuKs::usage()
{
QTextStream qout(stdout);
qout << "\nUsage: ssuks <filename> <flags>" << endl
<< endl
<< "Flags are in the form key=value. 'model', 'force', 'rnd' and 'sandbox' keys have special meanings." << endl
<< "To do a kickstart for N9 do 'ssuks model=N9'" << endl
<< "To force generating a kickstart for a non-existant device add force=true" << endl
<< endl;
qout.flush();
QCoreApplication::exit(1);
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QCoreApplication::setOrganizationName("Jolla");
QCoreApplication::setOrganizationDomain("http://www.jollamobile.com");
QCoreApplication::setApplicationName("ssuks");
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
SsuKs mw;
QTimer::singleShot(0, &mw, SLOT(run()));
return app.exec();
}