[1/1] remove all newly installed packages after localepurge

Message ID 20260323094521.682576-1-felix.moessbauer@siemens.com
State Under Review
Headers show
Series [1/1] remove all newly installed packages after localepurge | expand

Commit Message

MOESSBAUER, Felix March 23, 2026, 9:45 a.m. UTC
To perform the localepurge, we install the localepurge package, run the
command and then remove it again from the rootfs. In case the set of
newly installed packages intersects with the set of suggested packages
from all previously installed packages, the intersection is not removed
on autopurge (as apt internally does not track why a package was
installed). However, we want these packages to be removed, as we never
intended to install them in the first place (except for the localepurge
operation).

We fix this by tracking which new packages will be installed when
installing localepurge and then remove exactly these.

One example package that is affected in the base image is "perl".

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes-recipe/image-locales-extension.bbclass | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jan Kiszka March 23, 2026, 11:09 a.m. UTC | #1
On 23.03.26 10:45, 'Felix Moessbauer' via isar-users wrote:
> To perform the localepurge, we install the localepurge package, run the
> command and then remove it again from the rootfs. In case the set of
> newly installed packages intersects with the set of suggested packages
> from all previously installed packages, the intersection is not removed
> on autopurge (as apt internally does not track why a package was
> installed). However, we want these packages to be removed, as we never
> intended to install them in the first place (except for the localepurge
> operation).
> 
> We fix this by tracking which new packages will be installed when
> installing localepurge and then remove exactly these.
> 
> One example package that is affected in the base image is "perl".
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  meta/classes-recipe/image-locales-extension.bbclass | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/meta/classes-recipe/image-locales-extension.bbclass b/meta/classes-recipe/image-locales-extension.bbclass
> index b6b07dba..45dcdb67 100644
> --- a/meta/classes-recipe/image-locales-extension.bbclass
> +++ b/meta/classes-recipe/image-locales-extension.bbclass
> @@ -69,6 +69,9 @@ __EOF__
>          else
>              localepurge_state='p'
>              echo 'localepurge was not installed (removing it later)'
> +            # track additional packages that will be installed, as these packages might be
> +            # in the suggested set of other packages and by that need to be explicitly removed
> +            localepurge_pkgs=$(chroot '${ROOTFSDIR}' apt-get ${ROOTFS_APT_ARGS} -s localepurge 2>&1 | sed -n 's/^Inst \([^ ]*\) .*/\1/p')
>              chroot '${ROOTFSDIR}' apt-get ${ROOTFS_APT_ARGS} localepurge
>          fi
>  
> @@ -105,7 +108,7 @@ EOSH
>          if [ "$localepurge_state" = 'p' ]
>          then
>              echo removing localepurge...
> -            chroot '${ROOTFSDIR}' apt-get autopurge --yes localepurge
> +            chroot '${ROOTFSDIR}' apt-get purge --yes $localepurge_pkgs
>          fi
>  EOSUDO
>  }

Ah, nice. I recall having seen this inconsistency before but was too
lazy to fix it...

Jan

Patch

diff --git a/meta/classes-recipe/image-locales-extension.bbclass b/meta/classes-recipe/image-locales-extension.bbclass
index b6b07dba..45dcdb67 100644
--- a/meta/classes-recipe/image-locales-extension.bbclass
+++ b/meta/classes-recipe/image-locales-extension.bbclass
@@ -69,6 +69,9 @@  __EOF__
         else
             localepurge_state='p'
             echo 'localepurge was not installed (removing it later)'
+            # track additional packages that will be installed, as these packages might be
+            # in the suggested set of other packages and by that need to be explicitly removed
+            localepurge_pkgs=$(chroot '${ROOTFSDIR}' apt-get ${ROOTFS_APT_ARGS} -s localepurge 2>&1 | sed -n 's/^Inst \([^ ]*\) .*/\1/p')
             chroot '${ROOTFSDIR}' apt-get ${ROOTFS_APT_ARGS} localepurge
         fi
 
@@ -105,7 +108,7 @@  EOSH
         if [ "$localepurge_state" = 'p' ]
         then
             echo removing localepurge...
-            chroot '${ROOTFSDIR}' apt-get autopurge --yes localepurge
+            chroot '${ROOTFSDIR}' apt-get purge --yes $localepurge_pkgs
         fi
 EOSUDO
 }