Skip to content

Instantly share code, notes, and snippets.

@DylanGraham
Created June 13, 2017 03:39
Show Gist options
  • Save DylanGraham/5c3068bed9bed5b6a3f37d1291a1bfd6 to your computer and use it in GitHub Desktop.
Save DylanGraham/5c3068bed9bed5b6a3f37d1291a1bfd6 to your computer and use it in GitHub Desktop.
Remove your old kernels on SUSE
#!/bin/bash
UNAME=$(uname -r)
CUR_array=($(echo "$UNAME" | awk -F'[.-]' '{print $1 "\n" $2 "\n" $3 "\n" $4}'))
CUR=$(echo ${CUR_array[@]} | tr -d ' ')
FOUND=0
function compare {
for J in {0..3}; do
if (( "${THIS_array[J]}" > "${CUR_array[J]}" )); then break
elif (( "${THIS_array[J]}" < "${CUR_array[J]}" )); then
LIST+=($I)
FOUND=1
break
fi
done
}
for I in $(rpm -q kernel-default); do
THIS_array=($(echo "$I" | awk -F'[.-]' '{print $3 "\n" $4 "\n" $5 "\n" $6}'))
THIS=$(echo ${THIS_array[@]} | tr -d ' ')
if [[ "${THIS}" == "${CUR}" ]]; then continue
else compare
fi
done
if ((FOUND)); then
echo "Currently running kernel-$UNAME"
zypper remove "${LIST[@]}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment