git.iko.soy/typeable/nixpkgs
on master help sign in
kernel: Add update script
commit6e91f53d87adb8f8760ab01df6251e4881781123 authorWilliam A. Kennington III <william@wkennington.com> dateThu 16 Oct 2014, 13:59 (12 years ago) parentca92086
1 file changed+62
pkgs/os-specific/linux/kernel/update.sh+62
pkgs/os-specific/linux/kernel/update.shnew file+62
@@ -0,0 +1,62 @@
1+#!/usr/bin/env bash
2+set -e
3+
4+# Get the latest versions from kernel.org
5+LINUXSED='s/.*linux-\([0-9]\+\(.[0-9]\+\)*\).*/\1/p'
6+KDATA="$(curl -s https://www.kernel.org | sed -n -e '/Download complete/p')"
7+VERSIONS=($(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
11+if grep -q "^${VERSIONS[1]}" <<< "${VERSIONS[0]}"; then
12+ VERSIONS=(${VERSIONS[@]:0:1} ${VERSIONS[@]:2})
13+fi
14+
15+# Inspect each file and see if it has the latest version
16+NIXPKGS="$(git rev-parse --show-toplevel)"
17+ls $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 "\#import ./generic.nix (args // rec {#a \ modDirVersion = \"${V}.0\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
54+ fi
55+ sed -i "\#import ./generic.nix (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"
62+done