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

  • about 8 hours ago: juliogonzalezgil liked this project.
  • 6 days ago: pperego liked this project.
  • 9 days ago: r1chard-lyu liked this project.
  • 19 days ago: ldragon joined this project.
  • over 7 years ago: blarson started this project.
  • over 7 years ago: blarson liked this project.
  • over 7 years ago: randybb liked this project.
  • over 7 years ago: mbrugger liked this project.
  • over 7 years ago: pluskalm liked this project.
  • over 7 years ago: dmacvicar liked this project.
  • over 7 years ago: e_bischoff added keyword "zypper" to this project.
  • over 7 years ago: e_bischoff originated this project.

  • Comments

    • dmacvicar
      over 7 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
      over 7 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
      over 7 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
      over 7 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.

    Similar Projects

    This project is one of its kind!