diff --git a/CMakeLists.txt b/CMakeLists.txt index f8111c49cb..dbb94c58aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,12 +119,6 @@ else(BUILD_OSTREE) unset(LIBOSTREE_LIBRARIES CACHE) endif(BUILD_OSTREE) -if(BUILD_DEB) - pkg_check_modules(LIBDPKG REQUIRED libdpkg) -else(BUILD_DEB) - unset(LIBDPKG_LIBRARIES CACHE) -endif(BUILD_DEB) - if(BUILD_DOCKERAPP) add_definitions(-DBUILD_DOCKERAPP) endif(BUILD_DOCKERAPP) @@ -377,7 +371,6 @@ set (AKTUALIZR_EXTERNAL_LIBS ${SQLITE3_LIBRARIES} ${LibArchive_LIBRARIES} ${LIBP11_LIBRARIES} - ${LIBDPKG_LIBRARIES} ${GLIB2_LIBRARIES} ${SYSTEMD_LIBRARY} ${ZLIB_LIBRARY}) diff --git a/README.adoc b/README.adoc index 094a776033..5839951983 100644 --- a/README.adoc +++ b/README.adoc @@ -65,7 +65,6 @@ Some features also require additional packages: * For PKCS#11 support, you will need `libp11-2 libp11-dev`. * For systemd support for secondaries, you will need `libsystemd-dev`. * For fault injection, you will need `fiu-utils libfiu-dev`. -* For Debian packagin support, you will need `libdpkg-dev`. ==== Mac support diff --git a/docker/Dockerfile.debian.testing b/docker/Dockerfile.debian.testing index d607ab9fe7..63984b78a7 100644 --- a/docker/Dockerfile.debian.testing +++ b/docker/Dockerfile.debian.testing @@ -19,7 +19,6 @@ RUN apt-get update && apt-get -y install --no-install-suggests --no-install-reco cmake \ curl \ doxygen \ - dpkg-dev \ e2fslibs-dev \ g++ \ gcc \ @@ -34,7 +33,6 @@ RUN apt-get update && apt-get -y install --no-install-suggests --no-install-reco libboost-test-dev \ libboost-thread-dev \ libcurl4-openssl-dev \ - libdpkg-dev \ libengine-pkcs11-openssl \ libexpat1-dev \ libfuse-dev \ diff --git a/docker/Dockerfile.ubuntu.bionic b/docker/Dockerfile.ubuntu.bionic index 29a540ca6d..2c90d5b7e9 100644 --- a/docker/Dockerfile.ubuntu.bionic +++ b/docker/Dockerfile.ubuntu.bionic @@ -30,7 +30,6 @@ RUN apt-get update && apt-get -y install --no-install-suggests --no-install-reco libboost-test-dev \ libboost-thread-dev \ libcurl4-openssl-dev \ - libdpkg-dev \ libengine-pkcs11-openssl \ libexpat1-dev \ libffi-dev \ diff --git a/docker/Dockerfile.ubuntu.xenial b/docker/Dockerfile.ubuntu.xenial index 667f4354b1..1cda8a35d1 100644 --- a/docker/Dockerfile.ubuntu.xenial +++ b/docker/Dockerfile.ubuntu.xenial @@ -30,7 +30,6 @@ RUN apt-get update && apt-get -y install --no-install-suggests --no-install-reco libboost-test-dev \ libboost-thread-dev \ libcurl4-openssl-dev \ - libdpkg-dev \ libengine-pkcs11-openssl \ libexpat1-dev \ libffi-dev \ diff --git a/include/libaktualizr-c.h b/include/libaktualizr-c.h new file mode 100644 index 0000000000..728fb6f917 --- /dev/null +++ b/include/libaktualizr-c.h @@ -0,0 +1,30 @@ +#ifndef AKTUALIZR_LIBAKTUALIZRC_H +#define AKTUALIZR_LIBAKTUALIZRC_H + +#ifdef __cplusplus +#include "primary/aktualizr.h" + +using Campaign = campaign::Campaign; + +extern "C" { +#else +typedef struct Aktualizr Aktualizr; +typedef struct Campaign Campaign; +#endif + +Aktualizr *Aktualizr_create(const char *config_path); +int Aktualizr_initialize(Aktualizr *a); +int Aktualizr_uptane_cycle(Aktualizr *a); +void Aktualizr_destroy(Aktualizr *a); + +Campaign *Aktualizr_campaign_check(Aktualizr *a); +int Aktualizr_campaign_accept(Aktualizr *a, Campaign *c); +int Aktualizr_campaign_postpone(Aktualizr *a, Campaign *c); +int Aktualizr_campaign_decline(Aktualizr *a, Campaign *c); +void Aktualizr_campaign_free(Campaign *c); + +#ifdef __cplusplus +} +#endif + +#endif //AKTUALIZR_LIBAKTUALIZR_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5da11bace..bd702ca8ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ if(BUILD_WITH_CODE_COVERAGE) endif() add_subdirectory("libaktualizr") +add_subdirectory("libaktualizr-c") add_subdirectory("virtual_secondary") add_subdirectory("sota_tools") add_subdirectory("aktualizr_primary") diff --git a/src/libaktualizr-c/CMakeLists.txt b/src/libaktualizr-c/CMakeLists.txt new file mode 100644 index 0000000000..0982c587d4 --- /dev/null +++ b/src/libaktualizr-c/CMakeLists.txt @@ -0,0 +1,10 @@ +SET(TARGET_NAME aktualizr-c) +SET(SOURCES libaktualizr-c.cc) + +add_library(${TARGET_NAME} SHARED ${SOURCES}) +target_include_directories(${TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(${TARGET_NAME} PRIVATE aktualizr_static_lib ${AKTUALIZR_EXTERNAL_LIBS}) + +aktualizr_source_file_checks(${SOURCES}) + +add_subdirectory(test) diff --git a/src/libaktualizr-c/libaktualizr-c.cc b/src/libaktualizr-c/libaktualizr-c.cc new file mode 100644 index 0000000000..c4918db0e3 --- /dev/null +++ b/src/libaktualizr-c/libaktualizr-c.cc @@ -0,0 +1,77 @@ +#include "libaktualizr-c.h" + +Aktualizr *Aktualizr_create(const char *config_path) { + Aktualizr *a; + try { + Config cfg(config_path); + a = new Aktualizr(cfg); + } catch (const std::exception &e) { + std::cerr << "Aktualizr_create exception: " << e.what() << std::endl; + return nullptr; + } + return a; +} + +int Aktualizr_initialize(Aktualizr *a) { + try { + a->Initialize(); + } catch (const std::exception &e) { + std::cerr << "Aktualizr_initialize exception: " << e.what() << std::endl; + return -1; + } + return 0; +} + +int Aktualizr_uptane_cycle(Aktualizr *a) { + try { + a->UptaneCycle(); + } catch (const std::exception &e) { + std::cerr << "Uptane cycle exception: " << e.what() << std::endl; + return -1; + } + return 0; +} + +void Aktualizr_destroy(Aktualizr *a) { delete a; } + +Campaign *Aktualizr_campaign_check(Aktualizr *a) { + try { + auto r = a->CampaignCheck().get(); + if (!r.campaigns.empty()) { + // We don't support multiple campaigns at the moment + return new Campaign(r.campaigns[0]); + } + } catch (const std::exception &e) { + std::cerr << "Campaign check exception: " << e.what() << std::endl; + return nullptr; + } + return nullptr; +} +int Aktualizr_campaign_accept(Aktualizr *a, Campaign *c) { + try { + a->CampaignControl(c->id, campaign::Cmd::Accept).get(); + } catch (const std::exception &e) { + std::cerr << "Campaign accept exception: " << e.what() << std::endl; + return -1; + } + return 0; +} +int Aktualizr_campaign_postpone(Aktualizr *a, Campaign *c) { + try { + a->CampaignControl(c->id, campaign::Cmd::Postpone).get(); + } catch (const std::exception &e) { + std::cerr << "Campaign postpone exception: " << e.what() << std::endl; + return -1; + } + return 0; +} +int Aktualizr_campaign_decline(Aktualizr *a, Campaign *c) { + try { + a->CampaignControl(c->id, campaign::Cmd::Decline).get(); + } catch (const std::exception &e) { + std::cerr << "Campaign decline exception: " << e.what() << std::endl; + return -1; + } + return 0; +} +void Aktualizr_campaign_free(Campaign *c) { delete c; } diff --git a/src/libaktualizr-c/test/CMakeLists.txt b/src/libaktualizr-c/test/CMakeLists.txt new file mode 100644 index 0000000000..caa5aa56fa --- /dev/null +++ b/src/libaktualizr-c/test/CMakeLists.txt @@ -0,0 +1,8 @@ +SET(TARGET_NAME api-test) +SET(SOURCES api-test.c) + +add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL ${SOURCES}) +add_dependencies(build_tests ${TARGET_NAME}) +target_link_libraries(${TARGET_NAME} aktualizr-c) + +aktualizr_source_file_checks(${SOURCES}) diff --git a/src/libaktualizr-c/test/api-test.c b/src/libaktualizr-c/test/api-test.c new file mode 100644 index 0000000000..8c10a5e573 --- /dev/null +++ b/src/libaktualizr-c/test/api-test.c @@ -0,0 +1,44 @@ +#include +#include + +#include "libaktualizr-c.h" + +int main(int argc, char **argv) { + Aktualizr *a; + Campaign *c; + int err; + + if (argc != 2) { + fprintf(stderr, "Missing config file\nUsage:\n\t%s CONFIG_FILE\n", argv[0]); + return EXIT_FAILURE; + } + + a = Aktualizr_create(argv[1]); + if (!a) { + return EXIT_FAILURE; + } + + err = Aktualizr_initialize(a); + if (err) { + return EXIT_FAILURE; + } + + c = Aktualizr_campaign_check(a); + if (c) { + printf("Accepting running campaign\n"); + err = Aktualizr_campaign_accept(a, c); + Aktualizr_campaign_free(c); + if (err) { + return EXIT_FAILURE; + } + } + + err = Aktualizr_uptane_cycle(a); + if (err) { + return EXIT_FAILURE; + } + + Aktualizr_destroy(a); + + return EXIT_SUCCESS; +} diff --git a/src/libaktualizr/package_manager/CMakeLists.txt b/src/libaktualizr/package_manager/CMakeLists.txt index 30ae023166..de369088b3 100644 --- a/src/libaktualizr/package_manager/CMakeLists.txt +++ b/src/libaktualizr/package_manager/CMakeLists.txt @@ -17,9 +17,6 @@ add_aktualizr_test(NAME packagemanagerfake SOURCES packagemanagerfake_test.cc) # Debian backend if(BUILD_DEB) set_property(SOURCE packagemanagerfactory.cc packagemanagerfactory_test.cc PROPERTY COMPILE_DEFINITIONS BUILD_DEB) - if (${LIBDPKG_VERSION} VERSION_GREATER "1.19.3") - set_property(SOURCE debianmanager.cc PROPERTY COMPILE_DEFINITIONS LIBDPKG_V011903) - endif() target_sources(package_manager PRIVATE debianmanager.cc) add_executable(t_packagemanager_deb EXCLUDE_FROM_ALL debianmanager_test.cc) add_dependencies(build_tests t_packagemanager_deb) diff --git a/src/libaktualizr/package_manager/debianmanager.cc b/src/libaktualizr/package_manager/debianmanager.cc index 1a2055f1b6..394bd72c31 100644 --- a/src/libaktualizr/package_manager/debianmanager.cc +++ b/src/libaktualizr/package_manager/debianmanager.cc @@ -1,37 +1,11 @@ #include "package_manager/debianmanager.h" -#define LIBDPKG_VOLATILE_API 1 -#include -#include -#include -#include #include #include Json::Value DebianManager::getInstalledPackages() const { - Json::Value packages(Json::arrayValue); - struct pkg_array array {}; - dpkg_program_init("a.out"); - modstatdb_open(msdbrw_available_readonly); - -#ifdef LIBDPKG_V011903 - pkg_array_init_from_hash(&array); -#else - pkg_array_init_from_db(&array); -#endif - pkg_array_sort(&array, pkg_sorter_by_nonambig_name_arch); - for (int i = 0; i < array.n_pkgs; ++i) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - struct pkginfo *pkg = array.pkgs[i]; - if (pkg->status == PKG_STAT_INSTALLED) { - Json::Value package; - package["name"] = pkg_name(pkg, pnaw_nonambig); - package["version"] = versiondescribe(&pkg->installed.version, vdew_nonambig); - packages.append(package); - } - } - dpkg_program_done(); - return packages; + // Currently not implemented + return Json::Value(Json::arrayValue); } data::InstallationResult DebianManager::install(const Uptane::Target &target) const { diff --git a/src/libaktualizr/primary/aktualizr.h b/src/libaktualizr/primary/aktualizr.h index c0348c84d4..c64b9845a7 100644 --- a/src/libaktualizr/primary/aktualizr.h +++ b/src/libaktualizr/primary/aktualizr.h @@ -158,6 +158,9 @@ class Aktualizr { */ boost::signals2::connection SetSignalHandler(const std::function)>& handler); + private: + Config config_; + protected: Aktualizr(Config& config, std::shared_ptr storage_in, std::shared_ptr http_in); @@ -166,7 +169,6 @@ class Aktualizr { private: static void systemSetup(); - Config& config_; std::shared_ptr storage_; std::shared_ptr sig_; api::CommandQueue api_queue_; diff --git a/src/load_tests/CMakeLists.txt b/src/load_tests/CMakeLists.txt index 5ad2e4e2f2..5c6b54b2ef 100644 --- a/src/load_tests/CMakeLists.txt +++ b/src/load_tests/CMakeLists.txt @@ -34,8 +34,7 @@ if (BUILD_LOAD_TESTS) ${LIBOSTREE_LIBRARIES} ${LIBP11_LIBRARIES} ${SQLITE3_LIBRARIES} - ${SYSTEMD_LIBRARY} - ${LIBDPKG_LIBRARIES}) + ${SYSTEMD_LIBRARY}) install(TARGETS ota-load-tests COMPONENT aktualizr diff --git a/thirdparty.spdx b/thirdparty.spdx index 3df10151fe..2d70f8e944 100644 --- a/thirdparty.spdx +++ b/thirdparty.spdx @@ -18,7 +18,6 @@ Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-sqlite3 Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-asn1c Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-libp11 Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-systemd -Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-dpkg PackageName: googletest @@ -209,18 +208,6 @@ FilesAnalyzed: false PackageComment: Dynamically linked. -PackageName: dpkg -SPDXID: SPDXRef-dpkg -PackageDownloadLocation: http://http.debian.net/debian/pool/main/d/dpkg/dpkg_1.19.0.5.tar.xz -PackageHomePage: https://packages.debian.org/source/sid/dpkg -PackageLicenseConcluded: GPL-2.0-or-later -PackageLicenseDeclared: GPL-2.0-or-later -PackageLicenseInfoFromFiles: GPL-2.0-or-later -PackageCopyrightText: NONE -FilesAnalyzed: false -PackageComment: Dynamically linked. - - PackageName: systemd SPDXID: SPDXRef-systemd PackageDownloadLocation: https://github.com/systemd/systemd/archive/v238.tar.gz