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

Commit

Permalink
Merge pull request #594 from advancedtelematic/bugfix/PRO-4877/build-…
Browse files Browse the repository at this point in the history
…ubuntu

Build Ubuntu package with BUILD_DEB & Self-update fixes
  • Loading branch information
cajun-rat authored Feb 16, 2018
2 parents bab7981 + 588700c commit 6f55335
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion scripts/build-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

mkdir -p build-ubuntu
cd build-ubuntu
cmake -DCMAKE_BUILD_TYPE=Release ../src
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_OSTREE=OFF -DBUILD_DEB=ON ../src

make -j8
make package
Expand Down
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 6f55335

Please sign in to comment.