~ubuntu-branches/ubuntu/trusty/bikeshed/trusty-proposed

« back to all changes in this revision

Viewing changes to purge-old-kernels

  • Committer: Package Import Robot
  • Author(s): Dustin Kirkland, Dustin Kirkland, Marius Gedminas
  • Date: 2012-05-06 10:43:34 UTC
  • mfrom: (1.1.22)
  • Revision ID: package-import@ubuntu.com-20120506104334-g5gtw3ucbzgk5fut
Tags: 1.23-0ubuntu1
[ Dustin Kirkland ]
* Makefile, purge-old-kernels, purge-old-kernels.1:
  - add the purge-old-kernels tool
* debian/control: recommend bzrtools (for cdiff)
* release-build:
  - drop hardy (too old of build tools to build)
  - drop maverick (deprecated)
  - add quantal

[ Marius Gedminas ]
* purge-old-kernels: fix counting of old kernels

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#    purge-old-kernels - remove old kernel packages
 
4
#    Copyright (C) 2012 Dustin Kirkland <kirkland@ubuntu.com>
 
5
#
 
6
#    Authors: Dustin Kirkland <kirkland@ubuntu.com>
 
7
#             Kees Cook <kees@ubuntu.com>
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU General Public License as published by
 
11
#    the Free Software Foundation, version 3 of the License.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
# Ensure we're running as root
 
22
if [ "$(id -u)" != 0 ]; then
 
23
        echo "ERROR: This script must run as root.  Hint..." 1>&2
 
24
        echo "  sudo $0 $@" 1>&2
 
25
        exit 1
 
26
fi
 
27
 
 
28
# NOTE: This script will ALWAYS keep the currently running kernel
 
29
# NOTE: Default is to keep 2 more, user overrides with --keep N
 
30
KEEP=2
 
31
# NOTE: Any unrecognized option will be passed straight through to apt-get
 
32
APT_OPTS=
 
33
while [ ! -z "$1" ]; do
 
34
        case "$1" in
 
35
                --keep)
 
36
                        # User specified the number of kernels to keep
 
37
                        KEEP="$2"
 
38
                        shift 2
 
39
                ;;
 
40
                *)
 
41
                        APT_OPTS="$APT_OPTS $1"
 
42
                        shift 1
 
43
                ;;
 
44
        esac
 
45
done
 
46
 
 
47
# Build our list of kernel packages to purge
 
48
PURGE=$(ls -tr /boot/vmlinuz-* | head -n -${KEEP} | grep -v "$(uname -r)$" | cut -d- -f2- | awk '{print "linux-image-" $0}')
 
49
 
 
50
if [ -z "$PURGE" ]; then
 
51
        echo "No kernels are eligible for removal"
 
52
        exit 0
 
53
fi
 
54
 
 
55
apt-get $APT_OPTS remove --purge $PURGE