Tomáš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 1 | #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áš Pecka | 594a676 | 2021-01-29 11:06:08 +0100 | [diff] [blame] | 7 | #include "system/Firmware.h" |
Václav Kubernát | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame] | 8 | #include "system/Authentication.h" |
| 9 | #include "system_vars.h" |
Tomáš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 10 | #include "system/IETFSystem.h" |
Tomáš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 11 | #include "utils/exceptions.h" |
| 12 | #include "utils/journal.h" |
Václav Kubernát | 6018f08 | 2021-02-11 01:32:18 +0100 | [diff] [blame^] | 13 | #include "utils/log.h" |
Tomáš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 14 | #include "utils/log-init.h" |
| 15 | |
Tomáš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 16 | static const char usage[] = |
| 17 | R"(Sysrepo-powered system management. |
| 18 | |
| 19 | Usage: |
| 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 | |
| 27 | Options: |
| 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 | |
| 37 | DBUS_EVENTLOOP_INIT |
| 38 | |
| 39 | int 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áš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 65 | auto sysrepoIETFSystem = velia::system::IETFSystem(srSess, "/etc/os-release"); |
Tomáš Pecka | d51d4cb | 2021-02-03 14:15:49 +0100 | [diff] [blame] | 66 | |
| 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áš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 70 | |
Václav Kubernát | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame] | 71 | 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áš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 74 | DBUS_EVENTLOOP_END |
| 75 | return 0; |
| 76 | } catch (std::exception& e) { |
| 77 | velia::utils::fatalException(spdlog::get("main"), e, "main"); |
| 78 | } |
| 79 | } |