Last active
July 20, 2021 13:35
-
-
Save jkniiv/f224334c281163dc3c8bbaf6129fe863 to your computer and use it in GitHub Desktop.
The new apt(8) high-level command, when run with the subcommand 'update', kindly suggests you run 'apt list --upgradable' when upgrades are available. Let's automate that :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Run 'apt update' and print every (nonempty) line except the last one with the suggestion to run | |
# 'apt list --upgradable'. | |
# In fact we do as suggested instead. :) | |
apt update 2>&1 | \ | |
awk ' | |
BEGIN { eatnextemptyline = 0 } | |
/^$/ { if (eatnextemptyline) { eatnextemptyline = 0; next } } | |
/WARNING: apt does not have a stable CLI interface. Use with caution in scripts./ { eatnextemptyline = 1; next } | |
/apt list --upgradable/ { | |
print "It seems the following packages can be upgraded:"; | |
system("apt list --upgradable"); | |
next; | |
} | |
{ print $0; } | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment