|
|
|
1 |
#!/bin/bash |
2 |
# |
3 |
# Univention Corporate Client |
4 |
# remove old, unused kernel packages |
5 |
# |
6 |
# Copyright 2013 Univention GmbH |
7 |
# |
8 |
# http://www.univention.de/ |
9 |
# |
10 |
# All rights reserved. |
11 |
# |
12 |
# The source code of this program is made available |
13 |
# under the terms of the GNU Affero General Public License version 3 |
14 |
# (GNU AGPL V3) as published by the Free Software Foundation. |
15 |
# |
16 |
# Binary versions of this program provided by Univention to you as |
17 |
# well as other copyrighted, protected or trademarked materials like |
18 |
# Logos, graphics, fonts, specific documentations and configurations, |
19 |
# cryptographic keys etc. are subject to a license agreement between |
20 |
# you and Univention and not subject to the GNU AGPL V3. |
21 |
# |
22 |
# In the case you use this program under the terms of the GNU AGPL V3, |
23 |
# the program is provided in the hope that it will be useful, |
24 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 |
# GNU Affero General Public License for more details. |
27 |
# |
28 |
# You should have received a copy of the GNU Affero General Public |
29 |
# License with the Debian GNU/Linux or Univention distribution in file |
30 |
# /usr/share/common-licenses/AGPL-3; if not, see |
31 |
# <http://www.gnu.org/licenses/>. |
32 |
|
33 |
# returns latest kernel package for given kernel version |
34 |
|
35 |
export LC_ALL=C |
36 |
export DEBIAN_FRONTEND=noninteractive |
37 |
|
38 |
removeOldKernelPackages () { |
39 |
|
40 |
local kernel_regex="$1" |
41 |
local running_kernel="$(uname -r)" |
42 |
|
43 |
local pkg="" |
44 |
local pkg_ver="" |
45 |
local latest_pkg="" |
46 |
local latest_pkg_ver="" |
47 |
local kernel_packages="" |
48 |
|
49 |
# remove all $kernel_regex packages except |
50 |
# the running kernel |
51 |
for pkg in $(dpkg-query -W -f '${Package}\n' | grep "$kernel_regex" | sort -n); do |
52 |
if [ "$(dpkg-query -W -f='${Status}\n' "$pkg" 2>/dev/null)" = "install ok installed" ]; then |
53 |
kernel_packages="$kernel_packages $pkg" |
54 |
pkg_ver="$(dpkg-query -W -f '${Version}\n' $pkg)" |
55 |
if dpkg --compare-versions "$pkg_ver" gt "$latest_pkg_ver" ; then |
56 |
latest_pkg_ver="$pkg_ver" |
57 |
latest_pkg="$pkg" |
58 |
fi |
59 |
fi |
60 |
done |
61 |
|
62 |
# remove kernel package |
63 |
for i in $kernel_packages; do |
64 |
# do not remove running and latest kernel |
65 |
if ! echo "$i" | grep -q "$running_kernel\|$latest_pkg"; then |
66 |
echo "removing kernel as requested in $0" |
67 |
dpkg -P $i || true |
68 |
fi |
69 |
done |
70 |
|
71 |
} |
72 |
|
73 |
remove=$(/usr/sbin/ucr get ucc/update/remove/old/kernel) |
74 |
remove_regex=$(/usr/sbin/ucr get ucc/update/remove/old/kernel/pkgregex) |
75 |
|
76 |
if [ -n "$remove" -a "$remove" = "true" ]; then |
77 |
if [ -z "$remove_regex" ]; then |
78 |
remove_regex="linux-image-[[:digit:]]" |
79 |
fi |
80 |
removeOldKernelPackages "$remove_regex" |
81 |
fi |
82 |
|
83 |
exit 0 |
0 |
+ * |
84 |
+ * |