Fix installation of apt packages more consistently (LP: #2089494).

This commit is contained in:
Simon Quigley 2025-02-24 04:02:12 -06:00
parent bffde9297a
commit 0fea5bd853
8 changed files with 92 additions and 38 deletions

View File

@ -2,15 +2,20 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
include(FeatureSummary)
set( CMAKE_CXX_STANDARD 20 )
set( CMAKE_CXX_STANDARD 23 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( CALAMARES_VERSION_REQUIRED 3.3.9 )
find_library(APT_PKG_LIB apt-pkg)
if (NOT APT_PKG_LIB)
message(FATAL_ERROR "Could not find libapt-pkg")
endif()
find_package(ECM "6.0.0" NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
include(KDEInstallDirs)
find_package(KF6 REQUIRED COMPONENTS CoreAddons)
include(KDEInstallDirs)
set( CALAMARES_VERSION_REQUIRED 3.3.9 )
find_package(Calamares ${CALAMARES_VERSION_REQUIRED} NO_CMAKE_PACKAGE_REGISTRY)
if (NOT TARGET Calamares::calamares OR NOT TARGET Calamares::calamaresui)
find_package(Calamares ${CALAMARES_VERSION_REQUIRED} REQUIRED)
@ -28,3 +33,5 @@ calamares_add_plugin( pkgselectprocess
SHARED_LIB
NO_CONFIG
)
add_executable(check_package checkpackage-backend.cpp)
target_link_libraries(check_package PRIVATE ${APT_PKG_LIB})

View File

@ -360,29 +360,16 @@ Calamares::JobResult PackageSelectProcess::exec()
if (!debPackages.isEmpty()) {
const QString packageList = debPackages.join(" ");
const QString installCommand = QString(
"packages_to_install=$(for pkg in %1; do "
"if ! dpkg -s \"$pkg\" &>/dev/null && apt-cache show \"$pkg\" &>/dev/null; then "
"printf \"%s \" \"$pkg\"; "
"fi; "
"done); "
"if [ -n \"$packages_to_install\" ]; then "
"DEBIAN_FRONTEND=noninteractive apt-get -y install $packages_to_install; "
"fi"
).arg(packageList);
const QString installCommand = QString("DEBIAN_FRONTEND=noninteractive apt-get -y install $(/usr/libexec/checkpackage-backend %1);").arg(packageList);
Calamares::JobResult installResult = runAptCommand(installCommand,
rootMountPoint,
installStart,
installEnd,
true);
if (!installResult) { // Using operator bool() to check for errors
return std::move(installResult); // Move to avoid copy
}
}
else {
qDebug() << "No packages to install.";
if (!installResult) return std::move(installResult);
}
else qDebug() << "No packages to install.";
QStringList removeDebPackages;
for (const QVariant& var : packagesToRemove) {

View File

@ -0,0 +1,39 @@
#include <iostream>
#include <string>
#include <apt-pkg/algorithms.h>
#include <apt-pkg/cacheiterators.h>
#include <apt-pkg/init.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/pkgsystem.h>
#include <apt-pkg/progress.h>
int main(int argc, char* argv[]) {
pkgInitConfig(*_config);
pkgInitSystem(*_config, _system);
if (_system == 0) {
std::cerr << "apt-pkg not initialized\n";
return 1;
}
// Open the package cache.
pkgCacheFile *cache = new pkgCacheFile();
OpProgress progress;
if (!cache || cache->Open(&progress, false) == false) {
std::cerr << "Error: could not open APT cache.\n";
return 1;
}
pkgApplyStatus(*cache);
std::vector<std::string> package_names(argv + 1, argv + argc);
if (package_names.empty()) return 0;
for (std::string package_name : package_names) {
pkgCache::PkgIterator it = cache->GetPkgCache()->FindPkg(package_name);
if (!it.end()) std::cout << package_name << " ";
}
std::cout << "\n";
cache->Close();
return 0;
}

View File

@ -0,0 +1 @@
usr/lib/calamares/modules/automirror usr/lib/${DEB_HOST_MULTIARCH}/calamares/modules/automirror

View File

@ -1,4 +0,0 @@
# this is an internal implementation detail, no manpage needed
calamares-settings-ubuntu-common: no-manual-page [usr/bin/calamares_snap_install]
# this is normal and not a problem
calamares-settings-ubuntu-common: executable-in-usr-lib [usr/lib/x86_64-linux-gnu/calamares/modules/automirror/main.py]

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
calamares-settings-ubuntu (1:25.04.16) plucky; urgency=medium
* Fix installation of apt packages more consistently (LP: #2089494).
-- Simon Quigley <tsimonq2@ubuntu.com> Mon, 24 Feb 2025 03:53:14 -0600
calamares-settings-ubuntu (1:25.04.15) plucky; urgency=medium
* Move calamares -> libcalamares-dev for build dependencies.

21
debian/control vendored
View File

@ -8,6 +8,7 @@ Build-Depends: debhelper-compat (= 13),
cmake,
extra-cmake-modules,
intltool,
libapt-pkg-dev,
libcalamares-dev (>= 3.3.13-0ubuntu4),
libkf6coreaddons-dev,
libqt6svg6-dev,
@ -68,19 +69,33 @@ Description: Ubuntu Unity Calamares Settings and Branding
Package: calamares-settings-ubuntu-common
Architecture: any
Depends: calamares (>= 3.3.13-0ubuntu4),
calamares-settings-ubuntu-common-data (= ${binary:Version}),
cryptsetup,
dracut-core,
kdialog,
keyutils,
python3,
python3-distro,
snapd-seed-glue,
squashfs-tools,
sudo,
${misc:Depends},
${qml6:Depends},
${shlibs:Depends}
Description: Common Calamares Settings
This package contains the common Calamares settings for all flavors.
There is also a automirror Python script to set sources based on
geolocation.
.
Common settings for all Ubuntu flavors.
Package: calamares-settings-ubuntu-common-data
Architecture: all
Depends: ${misc:Depends},
python3,
python3-distro,
Conflicts: calamares-settings-ubuntu-common (<< 1:25.04.16)
Replaces: calamares-settings-ubuntu-common (<< 1:25.04.16)
Description: Data for Common Calamares Settings
This package contains the common Calamares settings for all flavors.
There is also a automirror Python script to set sources based on
geolocation.
.
Architecture-independent data for the common Calamares settings.

27
debian/rules vendored
View File

@ -7,7 +7,10 @@ export GO111MODULE=off
export GOCACHE=$(CURDIR)/.gocache
export PKGSELECT = "common/modules/pkgselect"
export PKGSELECTPROCESS = "common/modules/pkgselectprocess"
export USRDIR = "debian/calamares-settings-ubuntu-common/usr"
export DATA_USRDIR = "debian/calamares-settings-ubuntu-common-data/usr"
export MODULES_DIR = "debian/calamares-settings-ubuntu-common/usr/lib/$(DEB_HOST_MULTIARCH)/calamares/modules"
export DATA_MODULES_DIR = "debian/calamares-settings-ubuntu-common-data/usr/lib/calamares/modules"
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
@ -29,22 +32,22 @@ override_dh_auto_clean:
override_dh_auto_install:
(cd $(PKGSELECT)/build && $(MAKE) DESTDIR=$(CURDIR)/debian/calamares-settings-ubuntu-common/ install)
(cd $(PKGSELECTPROCESS)/build && $(MAKE) DESTDIR=$(CURDIR)/debian/calamares-settings-ubuntu-common/ install)
override_dh_missing:
dh_missing
mkdir -pv $(MODULES_DIR)
cp -vr common/modules/automirror $(MODULES_DIR)
mkdir -pv debian/calamares-settings-ubuntu-common/etc/calamares/modules
cp -vr common/modules/*.conf debian/calamares-settings-ubuntu-common/etc/calamares/modules
chmod -R 755 debian/calamares-settings-ubuntu-common/usr/lib/
chmod 644 $(MODULES_DIR)/automirror/automirror.conf
chmod 644 $(MODULES_DIR)/automirror/module.desc
mkdir -pv $(MODULES_DIR) $(DATA_MODULES_DIR)
cp -vr common/modules/automirror $(DATA_MODULES_DIR)
mkdir -pv debian/calamares-settings-ubuntu-common-data/etc/calamares/modules
cp -vr common/modules/*.conf debian/calamares-settings-ubuntu-common-data/etc/calamares/modules
chmod 644 $(DATA_MODULES_DIR)/automirror/automirror.conf
chmod 644 $(DATA_MODULES_DIR)/automirror/module.desc
chmod 644 $(MODULES_DIR)/pkgselect/libcalamares_viewmodule_pkgselect.so
chmod 644 $(MODULES_DIR)/pkgselect/module.desc
mkdir -pv $(MODULES_DIR)/pkgselectprocess
cp -v $(PKGSELECTPROCESS)/build/*.so $(PKGSELECTPROCESS)/build/*.desc $(MODULES_DIR)/pkgselectprocess
chmod 644 $(MODULES_DIR)/pkgselectprocess/libcalamares_job_pkgselectprocess.so
chmod 644 $(MODULES_DIR)/pkgselectprocess/module.desc
mkdir -pv debian/calamares-settings-ubuntu-common/usr/bin/
mkdir -pv debian/calamares-settings-ubuntu-common/usr/libexec/
cp -v common/fixconkeys-part1 debian/calamares-settings-ubuntu-common/usr/libexec/fixconkeys-part1
cp -v common/fixconkeys-part2 debian/calamares-settings-ubuntu-common/usr/libexec/fixconkeys-part2
mkdir -pv $(USRDIR)/libexec/ $(DATA_USRDIR)/libexec/
cp -v common/fixconkeys-part1 $(DATA_USRDIR)/libexec/fixconkeys-part1
cp -v common/fixconkeys-part2 $(DATA_USRDIR)/libexec/fixconkeys-part2
cp -v $(PKGSELECTPROCESS)/build/check_package $(USRDIR)/libexec/checkpackage-backend