base-files: added /sbin/vkpurge, to remove old kernels.
This commit is contained in:
parent
d02cf7cc65
commit
d8b7847242
2 changed files with 109 additions and 3 deletions
103
srcpkgs/base-files/files/vkpurge.sh
Normal file
103
srcpkgs/base-files/files/vkpurge.sh
Normal file
|
@ -0,0 +1,103 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# A simple script to remove old kernel files/modules.
|
||||
# Brought to you by yours truly Juan RP in the Public Domain.
|
||||
#
|
||||
: ${progname:=$(basename $0)}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<_EOF
|
||||
Usage: $progname <target> [<version>]
|
||||
|
||||
Targets:
|
||||
list Lists old installed kernels.
|
||||
rm Remove kernel <version>
|
||||
|
||||
Example:
|
||||
$ $progname list
|
||||
$ $progname rm 2.6.39.2
|
||||
_EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
list_kernels()
|
||||
{
|
||||
local k kpkg installed skip
|
||||
|
||||
for k in /var/lib/initramfs-tools/*; do
|
||||
kver=$(basename $k)
|
||||
for kpkg in kernel kernel-snapshot; do
|
||||
installed=$(xbps-uhelper -r / version $kpkg)
|
||||
if [ -n "$installed" ]; then
|
||||
if [ "$installed" = "$kver" ]; then
|
||||
skip=1
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [ -n "$skip" ]; then
|
||||
unset skip
|
||||
continue
|
||||
fi
|
||||
echo "$kver"
|
||||
done
|
||||
}
|
||||
|
||||
run_hooks()
|
||||
{
|
||||
local dir="$1"
|
||||
local kver="$2"
|
||||
local d
|
||||
|
||||
for d in /etc/kernel.d/${dir}/*; do
|
||||
[ ! -x "$d" ] && continue
|
||||
echo "Running ${dir} kernel hook: $(basename $d)..."
|
||||
$d kernel $kver
|
||||
done
|
||||
}
|
||||
|
||||
remove_kernel()
|
||||
{
|
||||
local rmkver="$1"
|
||||
local installed f kfile
|
||||
|
||||
if [ ! -f /boot/vmlinuz-${rmkver} -a ! -d /lib/modules/${rmkver} ]; then
|
||||
echo "Kernel ${rmkver} not installed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
installed=$(xbps-uhelper -r / version $rmkver)
|
||||
if [ -n "$installed" ]; then
|
||||
echo "Kernel $rmkver is currently installed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Execute pre-remove kernel hooks.
|
||||
run_hooks pre-remove $rmkver
|
||||
# Remove kernel files in /boot.
|
||||
for f in config System.map vmlinuz; do
|
||||
kfile="/boot/${f}-${rmkver}"
|
||||
[ ! -f "${kfile}" ] && continue
|
||||
echo "Removing ${kfile}..."
|
||||
rm -f ${kfile}
|
||||
done
|
||||
# Remove kernel modules
|
||||
if [ -d "/lib/modules/${rmkver}" ]; then
|
||||
echo "Removing /lib/modules/${rmkver}..."
|
||||
rm -rf /lib/modules/${rmkver}
|
||||
fi
|
||||
# Execute post-remove kernel hooks.
|
||||
run_hooks post-remove $rmkver
|
||||
}
|
||||
|
||||
if [ "$1" = "list" ]; then
|
||||
list_kernels
|
||||
elif [ "$1" = "rm" ]; then
|
||||
[ -z "$2" ] && usage
|
||||
remove_kernel "$2"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
|
||||
exit 0
|
|
@ -1,10 +1,10 @@
|
|||
# Template file for 'base-files'
|
||||
pkgname=base-files
|
||||
version=0.43
|
||||
version=0.44
|
||||
build_style=custom-install
|
||||
short_desc="Vanilla Base System files"
|
||||
short_desc="Vanilla GNU/Linux base system files"
|
||||
maintainer="Juan RP <xtraeme@gmail.com>"
|
||||
homepage="http://code.google.com/p/xbps"
|
||||
homepage="https://vanilla.github.com/"
|
||||
license="public domain"
|
||||
long_desc="
|
||||
This package installs the base system files that aren't installed by any
|
||||
|
@ -57,4 +57,7 @@ do_install()
|
|||
#
|
||||
install -d ${DESTDIR}/usr/share/licenses
|
||||
install -m644 ${FILESDIR}/licenses/* ${DESTDIR}/usr/share/licenses
|
||||
|
||||
# vkpurge
|
||||
vinstall ${FILESDIR}/vkpurge.sh 755 sbin vkpurge
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue