Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
debianmanager.cc
1 #include "package_manager/debianmanager.h"
2 
3 #include <stdio.h>
4 #include <unistd.h>
5 
6 Json::Value DebianManager::getInstalledPackages() const {
7  // Currently not implemented
8  return Json::Value(Json::arrayValue);
9 }
10 
11 data::InstallationResult DebianManager::install(const Uptane::Target &target) const {
12  std::lock_guard<std::mutex> guard(mutex_);
13  LOG_INFO << "Installing " << target.filename() << " as Debian package...";
14  std::string cmd = "dpkg -i ";
15  std::string output;
16  TemporaryDirectory package_dir("deb_dir");
17  auto target_file = storage_->openTargetFile(target);
18 
19  boost::filesystem::path deb_path = package_dir / target.filename();
20  target_file->writeToFile(deb_path);
21  target_file->rclose();
22 
23  int status = Utils::shell(cmd + deb_path.string(), &output, true);
24  if (status == 0) {
25  LOG_INFO << "... Installation of Debian package successful";
26  storage_->savePrimaryInstalledVersion(target, InstalledVersionUpdateMode::kCurrent);
27  return data::InstallationResult(data::ResultCode::Numeric::kOk, "Installing debian package was successful");
28  }
29  LOG_ERROR << "... Installation of Debian package failed";
31 }
32 
33 Uptane::Target DebianManager::getCurrent() const {
34  boost::optional<Uptane::Target> current_version;
35  storage_->loadPrimaryInstalledVersions(&current_version, nullptr);
36 
37  if (!!current_version) {
38  return *current_version;
39  }
40 
41  return Uptane::Target::Unknown();
42 }
data::InstallationResult
Definition: types.h:179
TemporaryDirectory
Definition: utils.h:82
Uptane::Target
Definition: tuf.h:238
data::ResultCode::Numeric::kInstallFailed
Package installation failed.