-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
generate-hashes.nix
91 lines (72 loc) · 2.97 KB
/
generate-hashes.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{ pkgs ? import <nixpkgs> { } }:
pkgs.writeShellApplication {
name = "generate-hashes";
runtimeInputs = [
pkgs.curl
pkgs.jq
pkgs.nix
];
bashOptions = [ "nounset" "pipefail" ];
text = ''
RELEASE="''${1:-${import ./latest-release.nix}}"
FEEDS="base luci packages routing telephony"
UPSTREAM_URL=https://downloads.openwrt.org
RELEASE_URL="''${UPSTREAM_URL}/releases/''${RELEASE}"
if [ "''${RELEASE}" == "snapshot" ]; then
RELEASE_URL="''${UPSTREAM_URL}/snapshots";
fi
KMODS_SEPARATE=false
if [[ "''${RELEASE}" == "snapshot" || "''${RELEASE}" == 24* ]]; then
KMODS_SEPARATE=true
fi
declare -g -A arches_fetched
hash() {
TARGET=$1
VARIANT=$2
echo "- ''${TARGET}/''${VARIANT}" >&2
BASE_URL="''${RELEASE_URL}/targets/''${TARGET}/''${VARIANT}"
SUMS_HASH=$(nix store prefetch-file --json "''${BASE_URL}/sha256sums" 2>/dev/null | jq -r .hash)
if [ -n "$SUMS_HASH" ]; then
echo " targets.\"''${TARGET}\".\"''${VARIANT}\".sha256 = \"''${SUMS_HASH}\";"
PROFILES=$(curl --silent --fail "''${BASE_URL}/profiles.json" || true)
if [ -z "$PROFILES" ]; then
echo "Failed to fetch ''${BASE_URL}/profiles.json" >&2
else
if ''${KMODS_SEPARATE}; then
KERNEL_RELEASE=$(jq -r '.linux_kernel.release' <<< "''${PROFILES}")
KERNEL_VERSION=$(jq -r '.linux_kernel.version' <<< "''${PROFILES}")
KERNEL_VERMAGIC=$(jq -r '.linux_kernel.vermagic' <<< "''${PROFILES}")
KMODS_TARGET="''${KERNEL_VERSION}-''${KERNEL_RELEASE}-''${KERNEL_VERMAGIC}"
echo " - kmods" >&2
KMODS_HASH=$(nix store prefetch-file --json "''${BASE_URL}/kmods/''${KMODS_TARGET}/Packages" 2>/dev/null | jq -r .hash)
echo " kmods.\"''${TARGET}\".\"''${VARIANT}\".\"''${KMODS_TARGET}\".sha256 = \"''${KMODS_HASH}\";"
fi
ARCH=$(jq -r '.arch_packages' <<< "''${PROFILES}")
if [ -n "$ARCH" ]; then
echo " targets.\"''${TARGET}\".\"''${VARIANT}\".packagesArch = \"''${ARCH}\";"
if [ -z "''${arches_fetched[$ARCH]:-}" ]; then
for FEED in ''${FEEDS}; do
echo " - ''${FEED}" >&2
PACKAGES_HASH=$(nix store prefetch-file --json "''${RELEASE_URL}/packages/''${ARCH}/''${FEED}/Packages" 2>/dev/null | jq -r .hash)
echo " packages.\"''${ARCH}\".\"''${FEED}\".sha256 = \"''${PACKAGES_HASH}\";"
done
arches_fetched[$ARCH]="done"
fi
fi
fi
fi
}
mkdir -p hashes
(
echo "{"
curl -s "''${RELEASE_URL}/targets/?json-targets" | jq -r .[] | while IFS=/ read -r TARGET VARIANT; do
hash "''${TARGET}" "''${VARIANT}"
done
echo "}"
) > "hashes/''${RELEASE}.nix"
if [ "$(stat -c %s "hashes/''${RELEASE}.nix")" -le 10 ] ; then
# Too small, no entries, discard.
rm -v "hashes/''${RELEASE}.nix"
fi
'';
}