#!/usr/bin/env zsh # # Copyright © 2012 Nick Bowler # # Prunes directories in /lib/modules that do not correspond to any kernel # version in /boot. If the -f option is not specified, only print out what # will be removed. # # License WTFPL2: Do What The Fuck You Want To Public License, version 2. # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. force=no verbose=no while getopts 'fv' opt $@; do case $opt in f) force=yes ;; v) verbose=yes ;; \?) exit 1 ;; esac done [[ force = yes ]] || verbose=yes boot=/boot kernbase=$boot/vmlinuz- kernels=($kernbase*(N)) if ! [[ $#kernels -ge 1 ]]; then printf '%s: no kernels found in %s, aborting\n' "$0" "$boot" exit 1 fi typeset -A kernmap for v in ${${kernels%.old}#$kernbase}; do kernmap[$v]=false done modbase=/lib/modules for d in $modbase/*; do v=${d#$modbase/} if $kernmap[$v] :; then [[ $verbose = yes ]] && printf '%s\n' "$d" [[ $force = yes ]] && rm -rf "$d" fi done