at 18.09-beta 2.2 kB view raw
1#!/usr/bin/env bash 2set -e 3 4# Get the latest versions from kernel.org 5LINUXSED='s/.*linux-\([0-9]\+\(.[0-9]\+\)*\).*/\1/p' 6KDATA="$(curl -s https://www.kernel.org | sed -n -e '/Download complete/p')" 7VERSIONS=($(sed -n -e $LINUXSED <<< "$KDATA" | sort -Vr)) 8 9# Remove mainline version if there is a stable update 10# Note due to sorting these two will always exist at the bottom 11if grep -q "^${VERSIONS[1]}" <<< "${VERSIONS[0]}"; then 12 VERSIONS=(${VERSIONS[@]:0:1} ${VERSIONS[@]:2}) 13fi 14 15# Inspect each file and see if it has the latest version 16NIXPKGS="$(git rev-parse --show-toplevel)" 17ls $NIXPKGS/pkgs/os-specific/linux/kernel | while read FILE; do 18 KERNEL="$(sed -n $LINUXSED <<< "$FILE")" 19 [ -z "$KERNEL" ] && continue 20 21 # Find the matching new kernel version 22 MATCHING="" 23 for V in "${VERSIONS[@]}"; do 24 if grep -q "^$KERNEL" <<< "$V"; then 25 MATCHING="$V" 26 break 27 fi 28 done 29 if [ -z "$MATCHING" ]; then 30 echo "Out-of-support $KERNEL" 31 continue 32 fi 33 34 # Inspect the nix expression to check for changes 35 DATA="$(<$NIXPKGS/pkgs/os-specific/linux/kernel/$FILE)" 36 URL="$(sed -n -e 's/.*url = "\(.*\)";.*/\1/p' <<< "$DATA" | sed -e "s/\${version}/$MATCHING/g")" 37 OLDVER=$(sed -n -e 's/.*version = "\(.*\)".*/\1/p' <<< "$DATA") 38 if [ "$OLDVER" = "$V" ]; then 39 echo "No updates for $KERNEL" 40 continue 41 fi 42 43 # Download the new file for the hash 44 if ! HASH="$(nix-prefetch-url $URL 2>/dev/null)"; then 45 echo "Failed to get hash of $URL" 46 continue 47 fi 48 sed -i "s/sha256 = \".*\"/sha256 = \"$HASH\"/g" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 49 50 # Rewrite the expression 51 sed -i -e '/version = /d' -e '/modDirVersion = /d' $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 52 if grep -q '^[0-9]\+.[0-9]\+$' <<< "$V"; then 53 sed -i "\#buildLinux (args // rec {#a \ modDirVersion = \"${V}.0\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 54 fi 55 sed -i "\#buildLinux (args // rec {#a \ version = \"$V\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 56 57 # Commit the changes 58 git add -u $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 59 git commit -m "kernel: $OLDVER -> $V" >/dev/null 2>&1 60 61 echo "Updated $OLDVER -> $V" 62done