From 2e7eb0d4bced62776d570711493122bea112df08 Mon Sep 17 00:00:00 2001 From: CloudBuilder Date: Thu, 14 Nov 2019 00:18:14 +0000 Subject: [PATCH] Imported 2.624 No reason for CPC update specified. --- auto-markable-pkgs | 63 +++++++++++++++++++++++++++++++++++++++++ debian/changelog | 8 ++++++ debian/install | 1 + minimize-manual | 70 ++++++++-------------------------------------- 4 files changed, 83 insertions(+), 59 deletions(-) create mode 100755 auto-markable-pkgs diff --git a/auto-markable-pkgs b/auto-markable-pkgs new file mode 100755 index 00000000..e1e9cafb --- /dev/null +++ b/auto-markable-pkgs @@ -0,0 +1,63 @@ +#!/usr/bin/python3 +"""List the packages which could be automatically installed without becoming autoremovable + +Finds all manually installed meta packages, and prints their dependencies +which could be marked as automatically installed. +""" +import sys + +import apt + + +def is_root(pkg): + """Check if the package is a root package (manually inst. meta)""" + section = pkg.candidate.section if pkg.candidate else "" + return (pkg.is_installed and + not pkg.is_auto_installed and + (section == "metapackages" or + section.endswith("/metapackages"))) + + +def main(): + """Main function""" + cache = apt.Cache(rootdir=sys.argv[1] if len(sys.argv) > 1 else None) + roots = set(pkg for pkg in cache if is_root(pkg)) + workset = set(roots) + seen = set() + ubiquity_depends = set() + + with cache.actiongroup(): + while True: + print("Iteration", file=sys.stderr) + to_proc = workset - seen + if not to_proc: + break + for pkg in sorted(to_proc): + print(" Visiting", pkg, file=sys.stderr) + + if pkg not in roots and pkg not in ubiquity_depends: + if not pkg.is_auto_installed: + print(pkg.name) + + for dep in (pkg.installed.dependencies + + pkg.installed.recommends): + for bdep in dep.or_dependencies: + for ver in bdep.target_versions: + if ver.package.is_installed: + if pkg.name == "ubiquity": + ubiquity_depends.add(ver.package) + if pkg.name != "ubiquity": + # Reprocess this package again, as we did not mark it when we visited it from ubiquity + try: + ubiquity_depends.remove(ver.package) + # This will raise the KeyError here if ubiquity did not depend on it + seen.remove(ver.package) + except KeyError: + pass + workset.add(ver.package) + + seen.add(pkg) + + +if __name__ == '__main__': + main() diff --git a/debian/changelog b/debian/changelog index bc2955aa..8c840cb2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +livecd-rootfs (2.624) focal; urgency=medium + + * Mark packages as autoinstalled using apt-mark in the chroot + instead of using python-apt that potentially starts talking to the build + system's dbus causing various problems. (LP: #1835406) + + -- Balint Reczey Wed, 13 Nov 2019 21:01:51 +0100 + livecd-rootfs (2.623) focal; urgency=medium * Add new buildd based bootable image for snapcraft builds. diff --git a/debian/install b/debian/install index 339c4f2c..541221b4 100644 --- a/debian/install +++ b/debian/install @@ -1,3 +1,4 @@ +auto-markable-pkgs usr/share/livecd-rootfs live-build usr/share/livecd-rootfs get-ppa-fingerprint usr/share/livecd-rootfs minimize-manual usr/share/livecd-rootfs diff --git a/minimize-manual b/minimize-manual index 5dcd9d30..393ec2cb 100755 --- a/minimize-manual +++ b/minimize-manual @@ -1,64 +1,16 @@ -#!/usr/bin/python3 -"""Minimize the number of manually installed packages in the image. +#!/bin/sh -Finds all manually installed meta packages, and marks their dependencies -as automatically installed. -""" -import sys +# Minimize the number of manually installed packages in the image -import apt +# Finds all packages which could be marked as automatically installed and marks +# them as such +set -e -def is_root(pkg): - """Check if the package is a root package (manually inst. meta)""" - section = pkg.candidate.section if pkg.candidate else "" - return (pkg.is_installed and - not pkg.is_auto_installed and - (section == "metapackages" or - section.endswith("/metapackages"))) +chroot=$1 - -def main(): - """Main function""" - cache = apt.Cache(rootdir=sys.argv[1] if len(sys.argv) > 1 else None) - roots = set(pkg for pkg in cache if is_root(pkg)) - workset = set(roots) - seen = set() - ubiquity_depends = set() - - with cache.actiongroup(): - while True: - print("Iteration", file=sys.stderr) - to_proc = workset - seen - if not to_proc: - break - for pkg in sorted(to_proc): - print(" Visiting", pkg, file=sys.stderr) - - if pkg not in roots and pkg not in ubiquity_depends: - pkg.mark_auto() - - for dep in (pkg.installed.dependencies + - pkg.installed.recommends): - for bdep in dep.or_dependencies: - for ver in bdep.target_versions: - if ver.package.is_installed: - if pkg.name == "ubiquity": - ubiquity_depends.add(ver.package) - if pkg.name != "ubiquity": - # Reprocess this package again, as we did not mark it when we visited it from ubiquity - try: - ubiquity_depends.remove(ver.package) - # This will raise the KeyError here if ubiquity did not depend on it - seen.remove(ver.package) - except KeyError: - pass - workset.add(ver.package) - - seen.add(pkg) - - cache.commit() - - -if __name__ == '__main__': - main() +auto_packages=$(/usr/share/livecd-rootfs/auto-markable-pkgs $chroot) +if [ -n "$auto_packages" ]; then + chroot chroot apt-mark auto $auto_packages +fi +[ -z "$(/usr/share/livecd-rootfs/auto-markable-pkgs $chroot 2> /dev/null)" ]