#! /bin/bash
# Copyright (C) 2020, meta-linux-mainline contributors
# SPDX-License-Identifier: MIT

set -euo pipefail

usage() {
    echo "This script finds the latest patch release in a given kernel version"
    echo "series."
    echo ""
    echo "Usage: $0 VERSION"
    echo "    where VERSION is the first two components of a Linux kernel version,"
    echo "    e.g. '4.19' or '5.4'"
}

if [ "$1" == "--help" ]; then
    usage
    exit 0
fi

if [ $# != 1 ]; then
    echo "ERROR: Incorrect number of arguments provided!" > /dev/stderr
    usage > /dev/stderr
    exit 1
fi

VERSION=$1
VMAJOR=`echo ${VERSION} | cut -d. -f1`
curl -s https://cdn.kernel.org/pub/linux/kernel/v${VMAJOR}.x/sha256sums.asc | grep ChangeLog-${VERSION} | tail -n1 | cut -d'-' -f2
