bump-stable-kernel-versions 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: MIT-0
  3. # Copyright (C) 2024 by Gero Schwäricke <gero.schwaericke@grandcentrix.net>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy of this
  6. # software and associated documentation files (the "Software"), to deal in the Software
  7. # without restriction, including without limitation the rights to use, copy, modify,
  8. # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  9. # permit persons to whom the Software is furnished to do so.
  10. #
  11. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  12. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  13. # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  14. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
  15. # OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  16. # OTHER DEALINGS IN THE SOFTWARE.
  17. # Check for updates to Linux stable releases. The script uses the versions found in
  18. # linux/linux.hash. For each of the versions it downloads the related hash list and tries
  19. # to find an updated stable release. If found it updates all related files and hashes.
  20. set -euo pipefail
  21. latest_version=$(sed -rn 's|^\tdefault "(.+)" if BR2_LINUX_KERNEL_LATEST_VERSION$|\1|p' linux/Config.in)
  22. latest_release_version=$(echo "${latest_version}" | cut -f 1-2 -d .)
  23. echo "${latest_version} -> ${latest_release_version}"
  24. updated_releases_list=''
  25. hash_list=
  26. while read -r line; do
  27. # e.g.: # From https://www.kernel.org/pub/linux/kernel/v6.x/sha256sums.asc
  28. url=$(echo "${line}" | sed -n 's|^# From \(https://www\.kernel\.org/pub/linux/kernel/.*/sha256sums.asc\)|\1|p')
  29. # e.g.: sha256 f905f1238ea7a8e85314bacf283302e8097006010d25fcea726d0de0ea5bc9b6 linux-6.8.9.tar.xz
  30. old_hash=$(echo "${line}" | sed -rn 's|^sha256 +([0-9a-f]+) +linux-.*$|\1|p')
  31. old_version=$(echo "${line}" | sed -rn 's|^sha256 +[0-9a-f]+ +linux-(.+)\.tar\.xz$|\1|p')
  32. if [ -n "${url}" ]; then
  33. # Line contained a URL: Download hash list and use it.
  34. if [ -a "${hash_list}" ]; then
  35. rm "${hash_list}"
  36. fi
  37. hash_list=$(basename "${url}")
  38. echo ">>> Downloading hash list from ${url}"
  39. wget --no-verbose "${url}"
  40. gpg --verify "${hash_list}"
  41. echo "${line}" >> linux/linux.hash.new
  42. elif [ -n "${old_version}" ]; then
  43. # Line contained a hash entry: Search for newer versions.
  44. release_version=$(echo "${old_version}" | cut -f 1-2 -d .) # e.g.: 6.8 instead of 6.8.9
  45. # e.g.: 19b31956d229b5b9ca5671fa1c74320179682a3d8d00fc86794114b21da86039 linux-6.8.12.tar.xz
  46. new_hash_entry=$(grep "^[0-9a-f]\+ \+linux-${release_version//./\\.}\.[0-9]\+\.tar\.xz$" "${hash_list}" | sort -V --key '2' | tail -1)
  47. new_hash=$(echo "${new_hash_entry}" | cut -f 1 -d ' ')
  48. new_version=$(echo "${new_hash_entry}" | cut -f 3 -d ' ' | sed -rn 's|linux-(.+)\.tar\.xz|\1|p')
  49. if [ "$new_version" == "$old_version" ]; then
  50. # Same version as before
  51. echo ">>> Release ${release_version}.x already on newest version ${new_version}."
  52. echo "${line}" >> linux/linux.hash.new
  53. if [ "${old_hash}" != "${new_hash}" ]; then
  54. # Hash changed! This should never happen!
  55. echo ">>> Version hash changed for ${release_version}.x!"
  56. echo ">>> It was: ${old_hash}"
  57. echo ">>> It is: ${new_hash}"
  58. exit 1
  59. fi
  60. else
  61. # Different version: update hash list, default headers, and possibly latest
  62. # version.
  63. echo ">>> Updating hash for ${release_version}.x in linux/linux.hash"
  64. echo "sha256 ${new_hash} linux-${new_version}.tar.xz" >> linux/linux.hash.new
  65. echo ">>> Updating version from ${old_version} to ${new_version} in Config.in files"
  66. sed -Ei "s/\tdefault \"${old_version}\"([\t ]+)if /\tdefault \"${new_version}\"\1if /" \
  67. package/linux-headers/Config.in.host linux/Config.in
  68. updated_releases_list="${updated_releases_list} ${release_version}.x"
  69. fi
  70. else
  71. # Different line: Reset hash list and just copy this line over as is.
  72. if [ -a "${hash_list}" ]; then
  73. rm "${hash_list}"
  74. hash_list=
  75. fi
  76. echo "${line}" >> linux/linux.hash.new
  77. fi
  78. done < linux/linux.hash
  79. # We were iterating over this file so we could not edit in-place.
  80. mv linux/linux.hash.new linux/linux.hash
  81. if [ -n "${updated_releases_list}" ]; then
  82. echo ">>> Suggested subject: {linux, linux-headers}: bump${updated_releases_list//.x /.x, } series"
  83. else
  84. echo '>>> Nothing happened.'
  85. fi