Browse Source

apt_upgrade: remove obsolete kernels to free /boot space

Signed-off-by: Alejandro Mery <amery@hanoverdisplays.com>
master
Alejandro Mery 8 years ago
committed by Alejandro Mery
parent
commit
2d66299d45
1 changed files with 38 additions and 1 deletions
  1. +38
    -1
      files/bin/apt_upgrade

+ 38
- 1
files/bin/apt_upgrade

@ -1,5 +1,6 @@
#!/bin/sh
set -eu
apt_opt=
if [ $# -eq 0 ]; then
: # interactive
@ -8,6 +9,42 @@ elif [ "${1:-}" = "-y" ]; then
shift
fi
obsolete_kernels() {
local current= latest=
local v= p=
if [ $# -gt 2 ]; then
current="$1" latest="$2"
shift 2
for v; do
COLUMNS=500 dpkg -l "linux*$v*" | sed -n -e 's|^.. \(linux[^ \]\+\)[ \t].*|\1|p'
done | while read p; do
case "$p" in
*$current*|*$latest*)
echo "$p: SKIP" >&2
;;
*)
printf "$p "
;;
esac
done
fi
}
remove=$(obsolete_kernels "$(uname -r)" \
$(ls -1 /boot/vmlinuz-* | \
sed -e 's|^/boot/vmlinuz-||' -e 's|\.efi\.signed$||' -e 's|-generic$||' | \
sort -urV))
aptget="apt-get${apt_opt:+ $apt_opt}"
cmd="$aptget update && $aptget autoremove --purge && $aptget upgrade && $aptget dist-upgrade"
cmd="$aptget update"
cmd="$cmd && $aptget autoremove --purge"
if [ -n "$remove" ]; then
cmd="$cmd && $aptget remove --purge $remove"
fi
cmd="$cmd && $aptget upgrade && $aptget dist-upgrade"
exec sudo sh -c "$cmd"

Loading…
Cancel
Save