Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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 -e $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 -e "s/sha256 = \".*\"/sha256 = \"$HASH\"/g" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 49 50 # Rewrite the expression 51 sed -i -e '/version = /d' $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 52 sed -i -e "\#buildLinux (args // rec {#a \ version = \"$V\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 53 54 # Commit the changes 55 git add -u $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE 56 git commit -m "linux: $OLDVER -> $V" >/dev/null 2>&1 57 58 echo "Updated $OLDVER -> $V" 59done 60 61# Update linux-rt 62COMMIT=1 $NIXPKGS/pkgs/os-specific/linux/kernel/update-rt.sh 63 64# Update linux-libre 65COMMIT=1 $NIXPKGS/pkgs/os-specific/linux/kernel/update-libre.sh 66 67# Update linux-hardened 68COMMIT=1 $NIXPKGS/pkgs/os-specific/linux/kernel/hardened/update.py