* usr/bin/purge-old-kernels, usr/share/man/man1/purge-old-kernels.1: LP: #1686138

- deprecate the logic in purge-old-kernel, as apt autoremove is supposed
    to work properly now
This commit is contained in:
Dustin Kirkland 2017-04-27 16:20:01 -05:00
commit e4e1944409
3 changed files with 15 additions and 71 deletions

4
debian/changelog vendored
View file

@ -1,6 +1,8 @@
byobu (5.117) unreleased; urgency=medium
* UNRELEASED
* usr/bin/purge-old-kernels, usr/share/man/man1/purge-old-kernels.1: LP: #1686138
- deprecate the logic in purge-old-kernel, as apt autoremove is supposed
to work properly now
-- Dustin Kirkland <kirkland@ubuntu.com> Sat, 18 Mar 2017 12:05:58 -0500

View file

@ -18,70 +18,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Ensure we're running as root
if [ "$(id -u)" != 0 ]; then
echo "ERROR: This script must run as root. Hint..." 1>&2
echo " sudo $0 $@" 1>&2
exit 1
fi
# apt autoremove supposedly works correctly now.
#
# Thus, we're deprecating the functionality previously found
# in purge-old-kernels.
#
# If you still have old kernels lying around after this, please
# file a bug against apt: https://bugs.launchpad.net/ubuntu/+source/apt/+filebug
# NOTE: This script will ALWAYS keep the currently running kernel
# NOTE: Default is to keep 2 more, user overrides with --keep N
KEEP=2
# NOTE: This script will give a hint if no kernels are eligible for removal
# NOTE: You can disable this with the --quit parameter
QUIET=0
# NOTE: Any unrecognized option will be passed straight through to apt
APT_OPTS=
while [ ! -z "$1" ]; do
case "$1" in
--quiet)
# No hint on no kernels for removal, better for cronjobs
QUIET=1
shift 1
;;
--keep)
# User specified the number of kernels to keep
KEEP="$2"
shift 2
;;
*)
APT_OPTS="$APT_OPTS $1"
shift 1
;;
esac
done
# Build our list of kernel packages to purge, make sure we exclude the current running kernel
current="$(uname -r)"
VERSIONS=$(ls -f /boot/vmlinuz-* | grep -v "$current$" | grep -v '.efi.signed' | sed -e "s/[^\-]*-//" -e "s/-[^\-]*$//" | sort -rh)
count=0
for v in $VERSIONS; do
count=$((count+1))
if [ $count -le $KEEP ]; then
continue
fi
for k in linux-image linux-headers linux-signed-image linux-image-virtual; do
for f in generic lowlatency; do
dpkg-query -s "$k-$v-$f" >/dev/null 2>&1 && PURGE="$PURGE $k-$v-$f"
done
done
done
if [ -z "$PURGE" ]; then
if [ "${QUIET}" -ne "1" ]; then
echo "No kernels are eligible for removal"
exit 0
else
exit 0
fi
fi
# Use apt-get, rather than apt, for compatibility with precise/trusty
if ! apt-get install --fix-broken --dry-run >/dev/null 2>&1; then
echo "APT is broken, trying with dpkg"
dpkg --purge $PURGE
apt-get install --fix-broken
fi
apt-get remove $APT_OPTS --purge $PURGE
apt-get autoremove $APT_OPTS --purge
sudo apt-get autoremove

View file

@ -3,18 +3,18 @@
purge-old-kernels - remove old kernel and header packages from the system
.SH SYNOPSIS
\fBpurge-old-kernels\fP [--keep N] [--quiet] [*]
\fBpurge-old-kernels\fP
.SH DESCRIPTION
This program will remove old kernel and header packages from the system, freeing disk space. It will never remove the currently running kernel. By default, it will keep at least the latest 2 kernels, but the user can override that value using the --keep parameter. Any additional parameters will be passed directly to \fBapt-get\fP(8).
This utility is now deprecated. The functionality it used to provide should be integrated into \fIapt\fP(8).
The --quiet option is useful for cronjobs, to ensure silence messages when there's nothing new to do.
If you still have old kernels lying around after this, please file a bug against apt: https://bugs.launchpad.net/ubuntu/+source/apt/+filebug
This program requires administrative access.
.SH EXAMPLE
sudo purge-old-kernels --keep 3 -qy
sudo purge-old-kernels
.SH SEE ALSO
\fBapt-get\fP(8)