The purpose would be to have the equivalent of Ubuntu's "apt-get autoremove" functionality.

When you install package P, it might draw in dependancies D1, D2, ... Dn automatically.

When you later uninstall P, the dependancies D1, D2, ..., Dn might remain on your system.

If you keep installing and uninstalling packages, after a while your system remains cluttered with things you don't need.

The idea would be to mark all dependancies that were installed but not explicitely requested as "installed automatically". Then a command like "zypper autoremove" could remove them at once if they are not needed anymore.

Approaches seen online

After scouring forms for solutions these are some alias's used to replicate the functionality

  1. zypper packages --unneeded | awk -F'|' 'NR==0 || NR==1 || NR==2 || NR==3 || NR==4 {next} {print $3}' | grep -v Name | sudo xargs zypper remove --clean-deps

  2. This one is a script and has bashisms bash mapfile -t unneeded < <(zypper --quiet pa --unneeded | awk '$1 == "i" { print $5, "-", $7 }') (( ${#unneeded@]} )) && sudo zypper --quiet rm --clean-deps --details "${unneeded@]}"

  3. sudo zypper rm $(zypper pa --unneeded | awk '/i / {print $3}' FS='|' | uniq | tr -d ' ')

Based on testing zypper packages --orphaned provides packages that are not in any repo, even if a user has explicitly installed them, so --orphaned may not be the way to go, instead focusing on --unneeded

Looking for hackers with the skills:

zypper

This project is part of:

Hack Week 15 Hack Week 24

Activity

  • 28 days ago: tdz liked this project.
  • 29 days ago: janvhs liked this project.
  • 29 days ago: janvhs joined this project.
  • about 1 month ago: tneau liked this project.
  • about 1 month ago: amanzini liked this project.
  • about 1 month ago: toe liked this project.
  • about 1 month ago: berndschubert liked this project.
  • about 1 month ago: berndschubert disliked this project.
  • about 1 month ago: berndschubert liked this project.
  • about 2 months ago: joachimwerner liked this project.
  • 2 months ago: juliogonzalezgil liked this project.
  • 2 months ago: pperego liked this project.
  • 2 months ago: r1chard-lyu liked this project.
  • 3 months ago: ldragon joined this project.
  • almost 8 years ago: blarson started this project.
  • almost 8 years ago: blarson liked this project.
  • almost 8 years ago: randybb liked this project.
  • almost 8 years ago: mbrugger liked this project.
  • almost 8 years ago: pluskalm liked this project.
  • almost 8 years ago: dmacvicar liked this project.
  • almost 8 years ago: e_bischoff added keyword "zypper" to this project.
  • almost 8 years ago: e_bischoff originated this project.

  • Comments

    • dmacvicar
      almost 8 years ago by dmacvicar | Reply

      There is zypper packages --unneeded which I am not sure if it takes into account /var/lib/zypp/AutoInstalled.

      In any case a worth project is to:

      • Fix the man page
      • Expose the functionality somehow present zypper packages --unneeded (only lists) and zypper rm -U foo (not usable without a package argument) into an usable command.

    • e_bischoff
      almost 8 years ago by e_bischoff | Reply

      Thanks Duncan. I did not know about the --unneeded flags.

      After searching a bit, I found it was described by

             https://features.opensuse.org/300758
      

      I don't think that

        "packages which are not required by other packages and are not in wanted selections"
      

      match the list of "automatically installed" packages that I described, but it seems to address pretty much the same use case:

                 A typical use case: user installs an application which pulls in some
                 dependencies to test it, uninstalls the application shortly after or way later
                 but the dependencies stay unused installed on the system.
      

      In any case, turning this list of packages into a command currently requires quite a bit of sed/awk:

            https://forums.opensuse.org/showthread.php/422841-Remove-unused-packages-with-zypper-or-yast/page2
      

      so a "usable command" as you say it would make sense.

    • e_bischoff
      almost 8 years ago by e_bischoff | Reply

      My first tests show that once you remove packages listed with zypper packages --unneeded, new unneeded packages appear. This shows that the --unneeded feature does not explore the tree in depth, or said otherwise, it does not mark as unneeded the packages that would become unneeded if the "immediately" unneeded were removed.

      I also remarked that packages you installed explicitely but are not in "wanted selections" are marked as "unneeded". That one is bad.

      In short, this "unneeded" feature does not really work the same way as the "installed automatically" feature on Debian / Ubuntu.

    • mlandres
      almost 8 years ago by mlandres | Reply

      IMO prerequisite for any automatic cleanup is the ability to inspect and manipulate a packages 'autoinstalled' property. This is the base on which the resolver decides which packages can be cleaned and which are requested by the user. If you can not change this property, you can not influence the resolvers decision.

    • e_bischoff
      over 5 years ago by e_bischoff | Reply

      Right.

      At the end I had not the time to work on this in Hackweek 17.

    • e_bischoff
      over 5 years ago by e_bischoff | Reply

      I meant Hackweek 15.

    • ldragon
      29 days ago by ldragon | Reply

      I've opened a pr here https://github.com/openSUSE/zypper/pull/578/. the autoremove command works pretty well in testing

    • e_bischoff
      25 days ago by e_bischoff | Reply

      Congrats! I can't wait until it is integrated into the official zypper!

    Similar Projects

    Ansible for add-on management by lmanfredi

    Description

    Machines can contains various combinations of add-ons and are often modified during the time.

    The list of repos can change so I would like to create an automation able to reset the status to a given state, based on metadata available for these machines

    Goals

    Create an Ansible automation able to take care of add-on (repo list) configuration using metadata as reference

    Resources

    Results

    Created WIP project Ansible-add-on-openSUSE