Last active
January 25, 2017 04:50
-
-
Save DylanGraham/9b46c86c61b62683267ab14f7b1defdd to your computer and use it in GitHub Desktop.
Remove your old kernels on Fedora
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
UNAME=$(uname -r) | |
CUR=($(echo "$UNAME" | awk -F'[.-]' '{print $1 $2 $3 $4}')) | |
CUR_1=($(echo "$UNAME" | awk -F'[.-]' '{print $1}')) | |
CUR_2=($(echo "$UNAME" | awk -F'[.-]' '{print $2}')) | |
CUR_3=($(echo "$UNAME" | awk -F'[.-]' '{print $3}')) | |
CUR_V=($(echo "$UNAME" | awk -F'[.-]' '{print $4}')) | |
FOUND=0 | |
function add_to_list { | |
DEV=$(echo $I | sed s/core/devel/) | |
if rpm --quiet -q ${DEV}; then | |
LIST+=($DEV) | |
fi | |
LIST+=($I) | |
FOUND=1 | |
} | |
function compare { | |
if (( "$1" > "$2" )); then continue | |
elif (( "$1" < "$2" )); then | |
add_to_list | |
continue | |
fi | |
} | |
for I in $(rpm -q kernel-core); do | |
THIS=($(echo "$I" | awk -F'[.-]' '{print $3 $4 $5 $6}')) | |
if [[ "${THIS}" == "${CUR}" ]]; then | |
continue | |
fi | |
THIS_1=($(echo "$I" | awk -F'[.-]' '{print $3}')) | |
THIS_2=($(echo "$I" | awk -F'[.-]' '{print $4}')) | |
THIS_3=($(echo "$I" | awk -F'[.-]' '{print $5}')) | |
THIS_V=($(echo "$I" | awk -F'[.-]' '{print $6}')) | |
compare "${THIS_1}" "${CUR_1}" | |
compare "${THIS_2}" "${CUR_2}" | |
compare "${THIS_3}" "${CUR_3}" | |
compare "${THIS_V}" "${CUR_V}" | |
done | |
if ((FOUND)); then | |
echo "Currently running kernel-$UNAME" | |
dnf remove "${LIST[@]}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment