1 #include "update_agent_ostree.h"
3 #include "package_manager/ostreemanager.h"
7 static void extractCredentialsArchive(
const std::string& archive, std::string* ca, std::string* cert, std::string* pkey,
8 std::string* treehub_server);
10 bool OstreeUpdateAgent::isTargetSupported(
const Uptane::Target& target)
const {
return target.
IsOstree(); }
15 installed_image_info.hash = _ostreePackMan->getCurrentHash();
18 installed_image_info.name = _targetname_prefix +
"-" + installed_image_info.hash;
19 installed_image_info.len = 0;
21 }
catch (
const std::exception& exc) {
22 LOG_ERROR <<
"Failed to get the currently installed revision: " << exc.what();
27 bool OstreeUpdateAgent::download(
const Uptane::Target& target,
const std::string&
data) {
28 std::string treehub_server;
29 bool download_result =
false;
32 std::string ca, cert, pkey, server_url;
33 extractCredentialsArchive(
data, &ca, &cert, &pkey, &server_url);
35 _keyMngr->loadKeys(&pkey, &cert, &ca);
36 boost::trim(server_url);
37 treehub_server = server_url;
38 }
catch (std::runtime_error& exc) {
39 LOG_ERROR << exc.what();
43 auto install_res = OstreeManager::pull(_sysrootPath, treehub_server, *_keyMngr, target);
45 switch (install_res.result_code.num_code) {
46 case data::ResultCode::Numeric::kOk: {
47 LOG_INFO <<
"The target revision has been successfully downloaded: " << target.sha256Hash();
48 download_result =
true;
52 LOG_INFO <<
"The target revision is already present on the local ostree repo: " << target.sha256Hash();
53 download_result =
true;
57 LOG_ERROR <<
"Failed to download the target revision: " << target.sha256Hash() <<
" ( "
58 << install_res.result_code.toString() <<
" ): " << install_res.description;
62 return download_result;
66 return (_ostreePackMan->install(target)).result_code.num_code;
70 if (!_ostreePackMan->rebootDetected()) {
74 "Reboot is required for the pending update application");
80 _ostreePackMan->rebootFlagClear();
81 return install_result;
84 void extractCredentialsArchive(
const std::string& archive, std::string* ca, std::string* cert, std::string* pkey,
85 std::string* treehub_server) {
87 std::stringstream as(archive);
88 *ca = Utils::readFileFromArchive(as,
"ca.pem");
91 std::stringstream as(archive);
92 *cert = Utils::readFileFromArchive(as,
"client.pem");
95 std::stringstream as(archive);
96 *pkey = Utils::readFileFromArchive(as,
"pkey.pem");
99 std::stringstream as(archive);
100 *treehub_server = Utils::readFileFromArchive(as,
"server.url",
true);