Feature request: The command should work like this

Bug #1633180 reported by Jarno Suni
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux-purge
Fix Released
Undecided
Jarno Suni

Bug Description

Bash completions and manual page should be implemented.

Usage (using short options):

linux-purge [-bcnosy] [{-k NUM [-a]} | -m] [-i APP]

linux-purge -f [-sn] [-i APP]

linux-purge {-h | -v}

Purge versioned kernel packages according to user's orders. Purging is
not restricted to linux-image packages, but all versioned linux-*
packages matching desired releases. Also purges such versioned
kernel packages that have the respective linux-image package missing
or marked for removal or purge, and packages that have just
configuration files remaining. Does not purge such versioned kernel
packages that have respective successfully installed linux-image
package marked with "hold" unless chosen interactively with -c option.

If usual purging fails, using -f option may help.

Options:
    -a, --auto-only Only purge kernels that have been marked as being
                    automatically installed.
    -b, --clear-boot
                    Check /boot for kernels unknown to the package
                    management system, and if such files are found,
                    offer to remove them.
    -c, --choose Choose interactively which kernels to purge. Other
                    options determine which kernels are selected to
                    start with.
    -f, --fix Use this, if the program fails otherwise. Try to fix
                    broken dependencies, which are typical in case a
                    filesystem has no space left. If needed, try to purge
                    given kernel(s) interactively by using different
                    methods to be able to purge kernels from a system
                    with broken dependencies and/or lack of free inodes.
    -h, --help Display this help and exit.
    -i APP, -iAPP, --interface APP, --interface=APP
                    Choose application used for generating user interface,
                    when selecting kernels; see option -c.

                    Supported values for APP:

                    d or dialog (default)

                    w or whiptail (fallback)
    -k NUM, -kNUM, --keep NUM, --keep=NUM
                    Keep NUM latest kernels that have earlier version
                    and same flavour than each kernel a meta-kernel
                    (such as linux-image-generic) depends on.
    -m, --manual Purge kernels that have been marked as being
                    manually installed.
    -n, --no-legend Do not display legend in checklist used by -c and -f.
    -o, --optimize Run update-grub only once in normal operation.
    -s, --simulate Dry-run; do not actually remove packages. You may
                    run this as regular user. Note that in some cases
                    simulation is not complete since some actions may
                    depend on others being done for real beforehand.
    -v, --version Print version.
    -y, --yes Purge without user confirmation.

Exit Status:
    0: Command finished successfully.
    1: Command-line is invalid.
    2: Command was run with wrong privileges.
    other integer: Command failed for some other reason.

Revision history for this message
Jarno Suni (jarnos) wrote :

A demonstration of the command with slightly different usage due to earlier stage of development:
https://youtu.be/TpsZoAnOVTU

Revision history for this message
Doug Smythies (dsmythies) wrote :

As mentioned on the doc team e-mail list on July 21st, I still have a use for the --choose option of such a script.

Where can I find your version of the script to try/test?

Revision history for this message
Jarno Suni (jarnos) wrote :

Doug Smythies, thank you for your interest, but the script is not available for testing at the moment. You can post a bounty at https://www.bountysource.com/issues/38300038-feature-request-the-command-should-work-like-this motivate me to publish the script in the "Code" page.

Revision history for this message
Jarno Suni (jarnos) wrote :

Doug Smythies, do you have use for the information that my script shows of each kernel in -c mode in the linked video? I mean +, if it is latest of its series and vital for updates, M, if it is manually installed, H, if it is marked for hold, and size in megabytes it takes in /boot? I could publish a stripped version of the script with lower bounty goal..

Revision history for this message
Doug Smythies (dsmythies) wrote :

Yes, I would find the additional information useful, except I don't care about the size it takes in /boot.

Question: at 3:35 of your video there is an error exit saying "Run simulation as regular user". Why not allow dry-run mode to be as "sudo"?

Revision history for this message
Jarno Suni (jarnos) wrote :

Well, with -f and -b the script may use command rm to delete some files, and rm does not have an option for dry-run. However, if you run some rm command that fails due to permissions, it kind of acts like simulation showing what would have been removed. Do you need to use dry-run mode as superuser?

Revision history for this message
Doug Smythies (dsmythies) wrote :

> Do you need to use dry-run mode as superuser?

No, but I expect I'll do exactly as you did in the video resulting in execution as superuser.

Revision history for this message
Jarno Suni (jarnos) wrote :

Ok, I can change it so that simulation can be run as superuser.

Jarno Suni (jarnos)
description: updated
Revision history for this message
Jarno Suni (jarnos) wrote :
Revision history for this message
Jarno Suni (jarnos) wrote :

I have written bash completions for the script.

Besides current version also waits that package database lock opens, before running apt-get, if needed. I think it would be even greater, if the script could lock the database for its own needs before deciding which packages to purge.

Revision history for this message
Doug Smythies (dsmythies) wrote :

Jarno : There is another person working on a selective kernel purging script. See:
http://askubuntu.com/questions/892076/how-to-selectively-purge-old-kernels-all-at-once
And also some exchanges in the general chat room.

I would still be interested to try/test your script, but I do have a workaround that works good enough for my purposes.

Revision history for this message
Jarno Suni (jarnos) wrote :

I am considering to change the script so that it does not use USE_DIALOG environment variable. 'sudo linux-purge -c' does not see it anyway, but 'sudo -E linux-purge -c' will currently. Perhaps people want to use the safer and shorter former command, so the environment variable set in /etc/environment does not have effect. 'dialog' is somewhat more advanced and seems to be better design than 'whiptail' which is available in all(?) Ubuntu variants by default. Thus I am considering to use 'dialog' by default, if it is available, and maybe add -w, --whiptail option for those who want to stick with 'whiptail'.

Revision history for this message
Jarno Suni (jarnos) wrote :

I chose to use --interface option for choosing whether to use dialog or whiptail. Changed the bug description accordingly.

description: updated
Revision history for this message
Jarno Suni (jarnos) wrote :
Jarno Suni (jarnos)
Changed in linux-purge:
status: New → Fix Committed
Revision history for this message
Doug Smythies (dsmythies) wrote :

@Jarno: I did not realize that you have now provided the script for us to try. I tried it.

On my test main computer it seems to want to delete a bunch of stuff, even though I only asked it to purge one kernel. I was only using --simulate, because of the risk.

So, I also have a test VM that I clone from another VM. i.e. so that I do not have to worry about any problem. On that VM the script crashes (still only using --simulate, so far), with this error message:

awk: line 2: regular expression /-(4\.4\.0- ... exceeds implementation size limit
[linux-purge] ERROR: Aborting due to an unknown error (2).

The only other thing I noticed was that the free space listed for /boot is wrong on both computers.

I am using this command:

./linux-purge --simulate --choose

but, on the test VM only, also tried these commands:

sudo ./linux-purge --simulate --choose
sudo ./linux-purge --choose

with the same results.

Revision history for this message
Jarno Suni (jarnos) wrote :

As for purging more stuff, it may be intentional: e.g. if there are just some configuration files left from some kernel. What is the output of
dpkg-query -W -f='${db:Status-Abbrev} ${Package}\n' linux-'*'
What was the full output of the linux-purge command? Which kernel release you chose to purge? Which packages do you think should not have been purged?

As for the awk problem, what is the output of 'awk -W version'?
It seems I may need to improve debugging features for the script. Currently you could try to modify the script by adding line
set -x
to the script after shebang and then re-run and attach the output.

Generally, please open a separate bug report of each issue for proper bug tracking, and please respond there.

Are you sure it shows wrong free space? It is designed to show free space in Megabytes available to superuser which is different than what is available to regular user.

Revision history for this message
Doug Smythies (dsmythies) wrote :

> As for purging more stuff, it may be intentional:

No, I meant I bunch of kernels I didn't ask it to purge.
I'll open a separate bug report.

> As for the awk problem, what is the output of 'awk -W version'?

It seems that on my main test server "awk" means gawk 1:4.1.3+dfsg-0.1
and on my VM it means mawk 1.3.3-17ubuntu2. I do not know why.

If I install gawk on the VM then it behaves the same as on the server.

> Are you sure it shows wrong free space?

No, my mistake sorry.

Revision history for this message
Jarno Suni (jarnos) wrote :

In some Ubuntu distributions very old and somewhat buggy mawk is still the default awk, and gawk is not installed. gawk may also be a dependency of some packages you have installed. If you have many implementations installed, you can choose the default one by
sudo update-alternatives --config awk
You could get more recent awk from http://invisible-island.net/mawk/mawk.html
and try, if the script works better with a more recent mawk.

Revision history for this message
Doug Smythies (dsmythies) wrote :

> gawk may also be a dependency of some packages you have installed.

Agreed, and very likely as my main test server has a lot of extra packages installed.

> You could get more recent awk from http://invisible-island.net/mawk/mawk.html
> and try, if the script works better with a more recent mawk.

No. I try to deviate as little as possible from a pure Ubuntu install. And I do not want to have to jump through hoops to get this to work. The version from askubuntu.com works very very well for me, I just thought to try your version, since it is now actually available.

Jarno Suni (jarnos)
Changed in linux-purge:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.