blob: f534aa1888c5336be5c00f3766d7e6a927da898a [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áš Pecka271d5602021-04-13 21:35:34 +020010#include "system/IETFInterfaces.h"
Tomáš Peckaf976c5b2021-01-23 21:19:52 +010011#include "system/IETFSystem.h"
Tomáš Pecka7226bcf2021-04-26 21:12:26 +020012#include "system/LED.h"
Tomáš Pecka625b7a12021-01-23 20:55:51 +010013#include "utils/exceptions.h"
Tomáš Pecka5c19e722021-02-15 20:41:29 +010014#include "utils/exec.h"
Tomáš Pecka625b7a12021-01-23 20:55:51 +010015#include "utils/journal.h"
Václav Kubernát6018f082021-02-11 01:32:18 +010016#include "utils/log.h"
Tomáš Pecka625b7a12021-01-23 20:55:51 +010017#include "utils/log-init.h"
Tomáš Pecka41784702021-05-26 13:57:32 +020018#include "utils/sysrepo.h"
Tomáš Pecka625b7a12021-01-23 20:55:51 +010019
Tomáš Pecka625b7a12021-01-23 20:55:51 +010020static const char usage[] =
21 R"(Sysrepo-powered system management.
22
23Usage:
24 veliad-system
Tomáš Pecka625b7a12021-01-23 20:55:51 +010025 [--sysrepo-log-level=<Level>]
26 [--system-log-level=<Level>]
27 veliad-system (-h | --help)
28 veliad-system --version
29
30Options:
31 -h --help Show this screen.
32 --version Show version.
Václav Kubernát5f57dec2021-02-11 02:02:46 +010033 --sysrepo-log-level=<N> Log level for the sysrepo library [default: 2]
Tomáš Pecka625b7a12021-01-23 20:55:51 +010034 --system-log-level=<N> Log level for the system stuff [default: 3]
Tomáš Pecka625b7a12021-01-23 20:55:51 +010035 (0 -> critical, 1 -> error, 2 -> warning, 3 -> info,
36 4 -> debug, 5 -> trace)
Tomáš Pecka625b7a12021-01-23 20:55:51 +010037)";
38
39DBUS_EVENTLOOP_INIT
40
41int main(int argc, char* argv[])
42{
43 std::shared_ptr<spdlog::sinks::sink> loggingSink;
44 if (velia::utils::isJournaldActive()) {
45 loggingSink = velia::utils::create_journald_sink();
46 } else {
47 loggingSink = std::make_shared<spdlog::sinks::ansicolor_stderr_sink_mt>();
48 }
49
50 auto args = docopt::docopt(usage, {argv + 1, argv + argc}, true, "veliad-system " VELIA_VERSION, true);
51
52 velia::utils::initLogs(loggingSink);
Tomáš Pecka41784702021-05-26 13:57:32 +020053 velia::utils::initLogsSysrepo();
Tomáš Pecka625b7a12021-01-23 20:55:51 +010054 spdlog::set_level(spdlog::level::info);
55
56 try {
Tomáš Pecka625b7a12021-01-23 20:55:51 +010057 spdlog::get("sysrepo")->set_level(parseLogLevel("Sysrepo library", args["--sysrepo-log-level"]));
Tomáš Pecka1935f192021-03-08 19:40:06 +010058 spdlog::get("system")->set_level(parseLogLevel("System logging", args["--system-log-level"]));
Tomáš Pecka625b7a12021-01-23 20:55:51 +010059
Tomáš Pecka625b7a12021-01-23 20:55:51 +010060 auto srConn = std::make_shared<sysrepo::Connection>();
61 auto srSess = std::make_shared<sysrepo::Session>(srConn);
62
63 DBUS_EVENTLOOP_START
64
65 // initialize ietf-system
Tomáš Peckaf976c5b2021-01-23 21:19:52 +010066 auto sysrepoIETFSystem = velia::system::IETFSystem(srSess, "/etc/os-release");
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010067
68 auto dbusConnection = sdbus::createConnection(); // second connection for RAUC (for calling methods).
69 dbusConnection->enterEventLoopAsync();
Tomáš Pecka5c19e722021-02-15 20:41:29 +010070
Tomáš Pecka271d5602021-04-13 21:35:34 +020071 // implements ietf-interfaces and ietf-routing
72 auto sysrepoIETFInterfaces = std::make_shared<velia::system::IETFInterfaces>(srSess);
73
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010074 auto sysrepoFirmware = velia::system::Firmware(srConn, *g_dbusConnection, *dbusConnection);
Tomáš Pecka625b7a12021-01-23 20:55:51 +010075
Václav Kubernátbabbab92021-01-27 09:25:05 +010076 auto srSess2 = std::make_shared<sysrepo::Session>(srConn);
77 auto authentication = velia::system::Authentication(srSess2, REAL_ETC_PASSWD_FILE, REAL_ETC_SHADOW_FILE, AUTHORIZED_KEYS_FORMAT, velia::system::impl::changePassword);
78
Tomáš Pecka7226bcf2021-04-26 21:12:26 +020079 auto leds = velia::system::LED(srConn, "/sys/class/leds");
80
Tomáš Pecka625b7a12021-01-23 20:55:51 +010081 DBUS_EVENTLOOP_END
82 return 0;
83 } catch (std::exception& e) {
84 velia::utils::fatalException(spdlog::get("main"), e, "main");
85 }
86}