diff options
author | William A. Kennington III <william@wkennington.com> | 2014-10-16 13:59:24 -0700 |
---|---|---|
committer | William A. Kennington III <william@wkennington.com> | 2014-10-30 14:37:22 -0700 |
commit | 6e91f53d87adb8f8760ab01df6251e4881781123 (patch) | |
tree | d98ed2575f598f17ae2dd7bf97d6a0cc9fadc4ef /pkgs/os-specific/linux/kernel/update.sh | |
parent | ca9208610110b9583541a49dfbc11e5588353a19 (diff) |
kernel: Add update script
Diffstat (limited to 'pkgs/os-specific/linux/kernel/update.sh')
-rwxr-xr-x | pkgs/os-specific/linux/kernel/update.sh | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/kernel/update.sh b/pkgs/os-specific/linux/kernel/update.sh new file mode 100755 index 0000000000000..d9db7f9f916cf --- /dev/null +++ b/pkgs/os-specific/linux/kernel/update.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +set -e + +# Get the latest versions from kernel.org +LINUXSED='s/.*linux-\([0-9]\+\(.[0-9]\+\)*\).*/\1/p' +KDATA="$(curl -s https://www.kernel.org | sed -n -e '/Download complete/p')" +VERSIONS=($(sed -n -e $LINUXSED <<< "$KDATA" | sort -Vr)) + +# Remove mainline version if there is a stable update +# Note due to sorting these two will always exist at the bottom +if grep -q "^${VERSIONS[1]}" <<< "${VERSIONS[0]}"; then + VERSIONS=(${VERSIONS[@]:0:1} ${VERSIONS[@]:2}) +fi + +# Inspect each file and see if it has the latest version +NIXPKGS="$(git rev-parse --show-toplevel)" +ls $NIXPKGS/pkgs/os-specific/linux/kernel | while read FILE; do + KERNEL="$(sed -n $LINUXSED <<< "$FILE")" + [ -z "$KERNEL" ] && continue + + # Find the matching new kernel version + MATCHING="" + for V in "${VERSIONS[@]}"; do + if grep -q "^$KERNEL" <<< "$V"; then + MATCHING="$V" + break + fi + done + if [ -z "$MATCHING" ]; then + echo "Out-of-support $KERNEL" + continue + fi + + # Inspect the nix expression to check for changes + DATA="$(<$NIXPKGS/pkgs/os-specific/linux/kernel/$FILE)" + URL="$(sed -n -e 's/.*url = "\(.*\)";.*/\1/p' <<< "$DATA" | sed -e "s/\${version}/$MATCHING/g")" + OLDVER=$(sed -n -e 's/.*version = "\(.*\)".*/\1/p' <<< "$DATA") + if [ "$OLDVER" = "$V" ]; then + echo "No updates for $KERNEL" + continue + fi + + # Download the new file for the hash + if ! HASH="$(nix-prefetch-url $URL 2>/dev/null)"; then + echo "Failed to get hash of $URL" + continue + fi + sed -i "s/sha256 = \".*\"/sha256 = \"$HASH\"/g" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE + + # Rewrite the expression + sed -i -e '/version = /d' -e '/modDirVersion = /d' $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE + if grep -q '^[0-9]\+.[0-9]\+$' <<< "$V"; then + sed -i "\#import ./generic.nix (args // rec {#a \ modDirVersion = \"${V}.0\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE + fi + sed -i "\#import ./generic.nix (args // rec {#a \ version = \"$V\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE + + # Commit the changes + git add -u $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE + git commit -m "kernel: $OLDVER -> $V" >/dev/null 2>&1 + + echo "Updated $OLDVER -> $V" +done |