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