Skip to content

Instantly share code, notes, and snippets.

@bvierra
Created December 13, 2024 14:23
Show Gist options
  • Save bvierra/b091b672b1d8e76e20100618d22bbb96 to your computer and use it in GitHub Desktop.
Save bvierra/b091b672b1d8e76e20100618d22bbb96 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Made by u/BinkReddit
# Taken From: https://www.reddit.com/r/linuxadmin/comments/1hcrge3/kernel_patch_changelog_summary/
# set -x
if ! command -v curl >/dev/null 2>&1; then
echo "This script requires curl."
exit 1
fi
oIFS=$IFS
# Get current kernel version if it was not provided
if [ -z "$1" ]; then
IFS='_-'
# Tokenize kernel version
# shellcheck disable=SC2162
version=$(uname -r | awk -F '[-_]' '{print $1}')
# Remove revision if any, currently handles revisions like 6.12.4_1 and 6.12.4-arch1-1
else
version=$1
fi
# Tokenize kernel version
IFS='.'
# shellcheck disable=SC2206
tversion=($version)
IFS=$oIFS
URL="https://cdn.kernel.org/pub/linux/kernel/v${tversion[0]}.x/ChangeLog-$version"
# Check if the URL exists
if curl -fIso /dev/null $URL; then
echo -e "Connecting to $URL...\n\nLinux $version"
commits=0
# Read the change log with blank lines removed and then sort it
while read -r first_word remaining_words; do
# curl -s $URL | grep "\S" | while read -r first_word remaining_words;
if [ "$title" = 1 ]; then
echo $first_word $remaining_words
title=0
continue
fi
# Commit title comes right after the date
if [ "X$first_word" = XDate: ]; then
((commits++))
title=1
fi
# Skip the first commit as it just has the Linux version and pollutes the sort
if [ $commits = 1 ]; then
title=0
fi
# Use process substitution so we don't lose the value of commits
done < <(curl -s $URL | grep "\S") > >(sort -f)
# done | { sed -u 1q; sort -f; }
# Wait for the process substitution above to complete, otherwise this is printed out of order
wait
echo -e "$((commits-1)) total commits"
else
echo "There was an issue connecting to $URL."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment