blob: 280fe7956bfdb4593b64afd269fa4ccc69003b7b [file] [log] [blame]
Tomáš Pecka625b7a12021-01-23 20:55:51 +01001#include <docopt.h>
2#include <spdlog/sinks/ansicolor_sink.h>
3#include <spdlog/spdlog.h>
4#include <sysrepo-cpp/Session.hpp>
5#include "VELIA_VERSION.h"
6#include "main.h"
Tomáš Pecka594a6762021-01-29 11:06:08 +01007#include "system/Firmware.h"
Václav Kubernátbabbab92021-01-27 09:25:05 +01008#include "system/Authentication.h"
9#include "system_vars.h"
Tomáš Peckaf976c5b2021-01-23 21:19:52 +010010#include "system/IETFSystem.h"
Tomáš Pecka625b7a12021-01-23 20:55:51 +010011#include "utils/exceptions.h"
12#include "utils/journal.h"
Václav Kubernát6018f082021-02-11 01:32:18 +010013#include "utils/log.h"
Tomáš Pecka625b7a12021-01-23 20:55:51 +010014#include "utils/log-init.h"
15
Tomáš Pecka625b7a12021-01-23 20:55:51 +010016static const char usage[] =
17 R"(Sysrepo-powered system management.
18
19Usage:
20 veliad-system
21 [--log-level=<Level>]
22 [--sysrepo-log-level=<Level>]
23 [--system-log-level=<Level>]
24 veliad-system (-h | --help)
25 veliad-system --version
26
27Options:
28 -h --help Show this screen.
29 --version Show version.
30 --log-level=<N> Log level for everything [default: 3]
31 (0 -> critical, 1 -> error, 2 -> warning, 3 -> info,
32 4 -> debug, 5 -> trace)
33 --sysrepo-log-level=<N> Log level for the sysrepo library [default: 3]
34 --system-log-level=<N> Log level for the system stuff [default: 3]
35)";
36
37DBUS_EVENTLOOP_INIT
38
39int main(int argc, char* argv[])
40{
41 std::shared_ptr<spdlog::sinks::sink> loggingSink;
42 if (velia::utils::isJournaldActive()) {
43 loggingSink = velia::utils::create_journald_sink();
44 } else {
45 loggingSink = std::make_shared<spdlog::sinks::ansicolor_stderr_sink_mt>();
46 }
47
48 auto args = docopt::docopt(usage, {argv + 1, argv + argc}, true, "veliad-system " VELIA_VERSION, true);
49
50 velia::utils::initLogs(loggingSink);
51 spdlog::set_level(spdlog::level::info);
52
53 try {
54 spdlog::set_level(parseLogLevel("Generic", args["--log-level"]));
55 spdlog::get("sysrepo")->set_level(parseLogLevel("Sysrepo library", args["--sysrepo-log-level"]));
56
57 spdlog::get("main")->debug("Opening Sysrepo connection");
58 auto srConn = std::make_shared<sysrepo::Connection>();
59 auto srSess = std::make_shared<sysrepo::Session>(srConn);
60
61 DBUS_EVENTLOOP_START
62
63 // initialize ietf-system
64 spdlog::get("main")->debug("Initializing Sysrepo for system models");
Tomáš Peckaf976c5b2021-01-23 21:19:52 +010065 auto sysrepoIETFSystem = velia::system::IETFSystem(srSess, "/etc/os-release");
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010066
67 auto dbusConnection = sdbus::createConnection(); // second connection for RAUC (for calling methods).
68 dbusConnection->enterEventLoopAsync();
69 auto sysrepoFirmware = velia::system::Firmware(srConn, *g_dbusConnection, *dbusConnection);
Tomáš Pecka625b7a12021-01-23 20:55:51 +010070
Václav Kubernátbabbab92021-01-27 09:25:05 +010071 auto srSess2 = std::make_shared<sysrepo::Session>(srConn);
72 auto authentication = velia::system::Authentication(srSess2, REAL_ETC_PASSWD_FILE, REAL_ETC_SHADOW_FILE, AUTHORIZED_KEYS_FORMAT, velia::system::impl::changePassword);
73
Tomáš Pecka625b7a12021-01-23 20:55:51 +010074 DBUS_EVENTLOOP_END
75 return 0;
76 } catch (std::exception& e) {
77 velia::utils::fatalException(spdlog::get("main"), e, "main");
78 }
79}