From 9360135b2c2a346ae6b1c309445564ade6daa6b1 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 18 Sep 2018 09:01:12 +0200 Subject: [PATCH 1/6] Minimize the number of manually installed packages in images by marking dependencies of metapackages as automatically installed. --- debian/changelog | 7 +++++ debian/control | 1 + live-build/auto/build | 2 ++ live-build/auto/minimize-manual.py | 48 ++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 live-build/auto/minimize-manual.py diff --git a/debian/changelog b/debian/changelog index e773ad65..76e885e8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +livecd-rootfs (2.536ubuntu1) UNRELEASED; urgency=medium + + * Minimize the number of manually installed packages in images by marking + dependencies of metapackages as automatically installed. + + -- Julian Andres Klode Tue, 18 Sep 2018 08:55:04 +0200 + livecd-rootfs (2.536) cosmic; urgency=medium * Fix live-server journald config snippet to actually disable journald rate diff --git a/debian/control b/debian/control index f6468b91..9d47c949 100644 --- a/debian/control +++ b/debian/control @@ -26,6 +26,7 @@ Depends: ${misc:Depends}, parted, procps, python-minimal | python, + python3-apt, python3-software-properties, qemu-utils, rsync, diff --git a/live-build/auto/build b/live-build/auto/build index 50831ba2..160f471a 100755 --- a/live-build/auto/build +++ b/live-build/auto/build @@ -445,6 +445,8 @@ EOF (cd chroot && find usr/share/doc -maxdepth 1 -type d | xargs du -s | sort -nr) echo END docdirs + live-build/auto/minimize-manual.py chroot + lb binary "$@" touch binary.success ) 2>&1 | tee binary.log diff --git a/live-build/auto/minimize-manual.py b/live-build/auto/minimize-manual.py new file mode 100644 index 00000000..712f35a4 --- /dev/null +++ b/live-build/auto/minimize-manual.py @@ -0,0 +1,48 @@ +#!/usr/bin/python3 +"""Minimize the number of manually installed packages in the image. + +Finds all manually meta packages and marks their dependencies as +automatically installed. +""" +import apt +import sys + + +def is_root(pkg): + return (pkg.is_installed and + not pkg.is_auto_installed and + (pkg.section == "metapackages" or + pkg.section.endswith("/metapackages"))) + + +c = apt.Cache(rootdir=sys.argv[1] if len(sys.argv) > 1 else None) + +roots = set(pkg for pkg in c if is_root(pkg)) +workset = set(roots) +seen = set() + +with c.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) + + # Mark every + if pkg not in roots: + pkg.mark_auto() + + for dep in pkg.installed.dependencies + pkg.installed.recommends: + if dep.rawtype not in ('Depends', 'PreDepends', 'Recommends'): + continue + for bdep in dep.or_dependencies: + for v in bdep.target_versions: + if v.package.is_installed: + workset.add(v.package) + + seen.add(pkg) + + c.commit() From 2e9349c543b970aea09c5a2bed1aad30e830c1eb Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 18 Sep 2018 09:15:42 +0200 Subject: [PATCH 2/6] minimize-manual.py: Followup with some cleanup, correct permissions --- live-build/auto/minimize-manual.py | 58 ++++++++++++++++-------------- 1 file changed, 31 insertions(+), 27 deletions(-) mode change 100644 => 100755 live-build/auto/minimize-manual.py diff --git a/live-build/auto/minimize-manual.py b/live-build/auto/minimize-manual.py old mode 100644 new mode 100755 index 712f35a4..6bd18780 --- a/live-build/auto/minimize-manual.py +++ b/live-build/auto/minimize-manual.py @@ -1,48 +1,52 @@ #!/usr/bin/python3 """Minimize the number of manually installed packages in the image. -Finds all manually meta packages and marks their dependencies as -automatically installed. +Finds all manually installed meta packages, and marks their dependencies +as automatically installed. """ -import apt import sys +import apt + def is_root(pkg): + """Check if the package is a root package (manually inst. meta)""" return (pkg.is_installed and not pkg.is_auto_installed and (pkg.section == "metapackages" or pkg.section.endswith("/metapackages"))) -c = apt.Cache(rootdir=sys.argv[1] if len(sys.argv) > 1 else None) +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() -roots = set(pkg for pkg in c if is_root(pkg)) -workset = set(roots) -seen = 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) -with c.actiongroup(): - while True: + if pkg not in roots: + pkg.mark_auto() - 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) + 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: + workset.add(ver.package) - # Mark every - if pkg not in roots: - pkg.mark_auto() + seen.add(pkg) - for dep in pkg.installed.dependencies + pkg.installed.recommends: - if dep.rawtype not in ('Depends', 'PreDepends', 'Recommends'): - continue - for bdep in dep.or_dependencies: - for v in bdep.target_versions: - if v.package.is_installed: - workset.add(v.package) + cache.commit() - seen.add(pkg) - c.commit() +if __name__ == '__main__': + main() From fc6907b701c526bc8030ac7ac6f5dd20955d82a7 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 18 Sep 2018 09:27:27 +0200 Subject: [PATCH 3/6] fixup: Do not assume current directory --- live-build/auto/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live-build/auto/build b/live-build/auto/build index 160f471a..cd738855 100755 --- a/live-build/auto/build +++ b/live-build/auto/build @@ -445,7 +445,7 @@ EOF (cd chroot && find usr/share/doc -maxdepth 1 -type d | xargs du -s | sort -nr) echo END docdirs - live-build/auto/minimize-manual.py chroot + /usr/share/livecd-rootfs/live-build/auto/minimize-manual.py chroot lb binary "$@" touch binary.success From 08376f8e64c6ed110ad6ed3f08bfd1cd81d271f4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 18 Sep 2018 09:29:58 +0200 Subject: [PATCH 4/6] Fix version number --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 76e885e8..a42e5981 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -livecd-rootfs (2.536ubuntu1) UNRELEASED; urgency=medium +livecd-rootfs (2.537) UNRELEASED; urgency=medium * Minimize the number of manually installed packages in images by marking dependencies of metapackages as automatically installed. From 3bb028c86dcb46f6d7aebec53f5e474314ace152 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 18 Sep 2018 10:39:59 +0200 Subject: [PATCH 5/6] Fix debian/rules test for shell scripts to ignore python --- debian/rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/rules b/debian/rules index 5e853009..ed27747b 100755 --- a/debian/rules +++ b/debian/rules @@ -7,7 +7,7 @@ DEB_HOST_MULTIARCH := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) override_dh_auto_test: dh_auto_test set -e; for x in live-build/auto/*; do \ - sh -n "$$x"; \ + echo "$$x" | grep -q .py || sh -n "$$x"; \ done override_dh_install: From 1746e65953eb9ef9e0c4777804cf90f78dc4a216 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 18 Sep 2018 11:44:06 +0200 Subject: [PATCH 6/6] Reorganize minimal-manual file location. This also gets rid of the change to debian/rules --- debian/install | 1 + debian/rules | 2 +- live-build/auto/build | 2 +- live-build/auto/minimize-manual.py => minimize-manual | 0 4 files changed, 3 insertions(+), 2 deletions(-) rename live-build/auto/minimize-manual.py => minimize-manual (100%) diff --git a/debian/install b/debian/install index 91d6ea37..4eb70070 100644 --- a/debian/install +++ b/debian/install @@ -1,2 +1,3 @@ live-build usr/share/livecd-rootfs get-ppa-fingerprint usr/share/livecd-rootfs +minimize-manual usr/share/livecd-rootfs diff --git a/debian/rules b/debian/rules index ed27747b..5e853009 100755 --- a/debian/rules +++ b/debian/rules @@ -7,7 +7,7 @@ DEB_HOST_MULTIARCH := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) override_dh_auto_test: dh_auto_test set -e; for x in live-build/auto/*; do \ - echo "$$x" | grep -q .py || sh -n "$$x"; \ + sh -n "$$x"; \ done override_dh_install: diff --git a/live-build/auto/build b/live-build/auto/build index cd738855..ec3d61bc 100755 --- a/live-build/auto/build +++ b/live-build/auto/build @@ -445,7 +445,7 @@ EOF (cd chroot && find usr/share/doc -maxdepth 1 -type d | xargs du -s | sort -nr) echo END docdirs - /usr/share/livecd-rootfs/live-build/auto/minimize-manual.py chroot + /usr/share/livecd-rootfs/minimize-manual chroot lb binary "$@" touch binary.success diff --git a/live-build/auto/minimize-manual.py b/minimize-manual similarity index 100% rename from live-build/auto/minimize-manual.py rename to minimize-manual