Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Partial fix for PRO-4872
Browse files Browse the repository at this point in the history
This is a partial fix that makes self-update on Aktualizr work, although we
should build a proper solution soon.  It does at least work end-to-end, and
unblocks the remaining testing.

Change-Id: I03d8c1dd461fd21c244145f641d808e8bbdfd450
  • Loading branch information
Phil Wise committed Feb 15, 2018
1 parent abd0db4 commit 1f3d405
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
25 changes: 17 additions & 8 deletions src/deb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@ Json::Value DebianManager::getInstalledPackages() {

data::InstallOutcome DebianManager::install(const Uptane::Target &target) const {
LOG_INFO << "Installing " << target.filename() << " as Debian package...";
std::string cmd = "dpkg -i ";
std::string output;
TemporaryDirectory package_dir("deb_dir");
std::stringstream sstr;
sstr << *storage_->openTargetFile(target.filename());
boost::filesystem::path deb_path = package_dir / target.filename();
Utils::writeFile(deb_path, sstr.str());

int status = Utils::shell(cmd + deb_path.string(), &output, true);
// Install the new package. This is complicated by the fact that it needs to
// support self-update, where aktualizr installs a new aktualzr Debian
// package. Removing the old package stops the Aktualizr systemd service,
// which causes Aktualizr to get killed. Therefore we perform the
// installation in a separate cgroup, using systemd-run.
// This is a temporary solution--in the future we should juggle things to
// report the installation status correctly.
const std::string tmp_deb_file("/tmp/incoming-package.deb", std::ofstream::trunc); // TODO Make this secure
std::ofstream package(tmp_deb_file);
package << *storage_->openTargetFile(target.filename());
package.close();

std::string cmd = "systemd-run --no-ask-password dpkg -i " + tmp_deb_file;

std::string output;
int status = Utils::shell(cmd, &output, true);
if (status == 0) {
// This is only checking the result of the systemd-run command
LOG_INFO << "... Installation of Debian package successful";
storage_->saveInstalledVersion(target);
return data::InstallOutcome(data::OK, "Installing debian package was successful");
Expand Down
6 changes: 3 additions & 3 deletions tests/packagemanager_deb_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ TEST(PackageManagerFactory, Debian_Install_Good) {

Json::Value target_json_test;
target_json_test["hashes"]["sha256"] = "hash_old";
target_json_test["length"] = 0;
target_json_test["length"] = 5;
Uptane::Target target_test("test.deb", target_json_test);
storage->saveInstalledVersion(target_test);

std::unique_ptr<StorageTargetWHandle> fhandle = storage->allocateTargetFile(false, "good.deb", 2);
std::stringstream("ab") >> *fhandle;
std::unique_ptr<StorageTargetWHandle> fhandle = storage->allocateTargetFile(false, "good.deb", 5);
std::stringstream("GOOD\n") >> *fhandle;

EXPECT_EQ(pacman->install(target).first, data::OK);
std::map<std::string, InstalledVersion> versions_loaded;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env bash
set -e

if [[ "$2" == */good.deb ]]
then
if grep -q GOOD "${@: -1}"; then
exit 0
else
echo -ne "Error installing"
Expand Down

0 comments on commit 1f3d405

Please sign in to comment.