ssu
Loading...
Searching...
No Matches
ssuks.cpp
Go to the documentation of this file.
1
7
8#include <QCoreApplication>
9#include <QTranslator>
10#include <QLocale>
11#include <QLibraryInfo>
12#include <QTimer>
13#include <QStringList>
14#include <QDirIterator>
15
16#include "ssukickstarter.h"
17#include "constants.h"
18#include "libssu/sandbox_p.h"
20
21#include "ssuks.h"
22
23void SsuKs::run()
24{
25 QStringList arguments = QCoreApplication::arguments();
26 // get rid of the binary name
27 arguments.removeFirst();
28
29 QTextStream qout(stdout);
30 QTextStream qerr(stderr);
31 QHash<QString, QString> repoParameters;
32
33 if (arguments.count() == 1 &&
34 (arguments.at(0) == "help" ||
35 arguments.at(0) == "--help" ||
36 arguments.at(0) == "-h")) {
37 usage();
38 return;
39 }
40
41 QString fileName;
42 if (arguments.count() >= 1 && !arguments.at(0).contains("=")) {
43 fileName = arguments.at(0);
44 arguments.removeFirst();
45 }
46
47 for (int i = 0; i < arguments.count(); i++) {
48 if (arguments.at(i).count("=") != 1) {
49 qout << "Invalid flag: " << arguments.at(i) << endl;
50 QCoreApplication::exit(1);
51 return;
52 }
53 QStringList split = arguments.at(i).split("=");
54 repoParameters.insert(split.at(0), split.at(1));
55 }
56
57 QString sandbox;
58 Sandbox *sb;
59 if (repoParameters.contains("sandbox")) {
60 sandbox = repoParameters.value("sandbox");
61 repoParameters.remove("sandbox");
62
63 sb = new Sandbox(sandbox, Sandbox::UseDirectly, Sandbox::ThisProcess);
64
65 if (!sb->addWorldFiles(SSU_DATA_DIR)) {
66 qerr << "Failed to copy files into sandbox, using empty sandbox" << endl;
67 }
68
69 if (sb->activate())
70 qerr << "Using sandbox at " << sandbox << endl;
71 else {
72 qerr << "Failed to activate sandbox" << endl;
73 QCoreApplication::exit(1);
74 return;
75 }
76
77 // force re-merge of settings
78 QFile::remove(Sandbox::map(SSU_BOARD_MAPPING_CONFIGURATION));
80 }
81
82 SsuKickstarter kickstarter;
83 kickstarter.setRepoParameters(repoParameters);
84 QCoreApplication::exit(!kickstarter.write(fileName));
85 return;
86
87
88 QCoreApplication::exit(0);
89}
90
91void SsuKs::usage()
92{
93 QTextStream qout(stdout);
94 qout << "\nUsage: ssuks <filename> <flags>" << endl
95 << endl
96 << "Flags are in the form key=value. 'model', 'force', 'rnd' and 'sandbox' keys have special meanings." << endl
97 << "To do a kickstart for N9 do 'ssuks model=N9'" << endl
98 << "To force generating a kickstart for a non-existant device add force=true" << endl
99 << endl;
100 qout.flush();
101 QCoreApplication::exit(1);
102}
103
104int main(int argc, char **argv)
105{
106 QCoreApplication app(argc, argv);
107 QCoreApplication::setOrganizationName("Jolla");
108 QCoreApplication::setOrganizationDomain("http://www.jollamobile.com");
109 QCoreApplication::setApplicationName("ssuks");
110
111 QTranslator qtTranslator;
112 qtTranslator.load("qt_" + QLocale::system().name(),
113 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
114 app.installTranslator(&qtTranslator);
115
116 SsuKs mw;
117 QTimer::singleShot(0, &mw, SLOT(run()));
118
119 return app.exec();
120}
bool addWorldFiles(const QString &directory, QDir::Filters filters=QDir::NoFilter, const QStringList &filterNames=QStringList(), bool recurse=true)
Definition sandbox.cpp:146
Definition ssuks.h:15
#define SSU_DATA_DIR
Directory where all the non-user modifiable data sits.
Definition constants.h:22
#define SSU_BOARD_MAPPING_CONFIGURATION
Path to board / device family mappings file.
Definition constants.h:18
#define SSU_BOARD_MAPPING_CONFIGURATION_DIR
Path to config.d for board mappings.
Definition constants.h:20