1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p nix-prefetch-svn git curl
3set -euo pipefail
4
5nixpkgs="$(git rev-parse --show-toplevel)"
6path="$nixpkgs/pkgs/os-specific/linux/kernel/linux-libre.nix"
7
8old_rev="$(grep -o 'rev = ".*"' "$path" | awk -F'"' '{print $2}')"
9
10svn_url=https://www.fsfla.org/svn/fsfla/software/linux-libre/releases/branches/
11rev="$(curl -s "$svn_url" | grep -Em 1 -o 'Revision [0-9]+' | awk '{print $2}')"
12
13if [ "$old_rev" = "$rev" ]; then
14 echo "No updates for linux-libre"
15 exit 0
16fi
17
18old_hash="$(grep -o 'hash = ".*"' "$path" | awk -F'"' '{print $2}')"
19sha256="$(QUIET=1 nix-prefetch-svn "$svn_url" "$rev" | tail -1)"
20new_hash="$(nix --extra-experimental-features nix-command hash convert --to sri --hash-algo sha256 "$sha256")"
21
22if [ "$old_hash" = "$new_hash" ]; then
23 echo "No updates for linux-libre"
24 exit 0
25fi
26
27sed -i -e "s,rev = \".*\",rev = \"$rev\",; s,hash = \".*\",hash = \"$new_hash\"," "$path"
28
29if [ -n "${COMMIT-}" ]; then
30 git commit -qm "linux_latest-libre: $old_rev -> $rev" "$path" \
31 $nixpkgs/pkgs/os-specific/linux/kernel/linux-libre.nix
32 echo "Updated linux_latest-libre $old_rev -> $rev"
33fi