base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12 (#356361)
[NixPkgs.git] / pkgs / tools / networking / curl-impersonate / firefox / update.sh
blob76dd6099d417515d631f5d4811a8dcfa46007970
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p git nix jq coreutils gnugrep gnused curl common-updater-scripts
3 # shellcheck shell=bash
4 set -euo pipefail
6 nixpkgs="$(git rev-parse --show-toplevel || (printf 'Could not find root of nixpkgs repo\nAre we running from within the nixpkgs git repo?\n' >&2; exit 1))"
8 stripwhitespace() {
9 sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
12 narhash() {
13 nix --extra-experimental-features nix-command store prefetch-file --json "$1" | jq -r .hash
16 nixeval() {
17 nix --extra-experimental-features nix-command eval --json --impure -f "$nixpkgs" "$1" | jq -r .
20 vendorhash() {
21 (nix --extra-experimental-features nix-command build --no-link -f "$nixpkgs" --no-link "$1" 2>&1 >/dev/null | tail -n3 | grep -F got: | cut -d: -f2- | stripwhitespace) 2>/dev/null || true
24 findpath() {
25 path="$(nix --extra-experimental-features nix-command eval --json --impure -f "$nixpkgs" "$1.meta.position" | jq -r . | cut -d: -f1)"
26 outpath="$(nix --extra-experimental-features nix-command eval --json --impure --expr "builtins.fetchGit \"$nixpkgs\"")"
28 if [ -n "$outpath" ]; then
29 path="${path/$(echo "$outpath" | jq -r .)/$nixpkgs}"
32 echo "$path"
35 getvar() {
36 echo "$2" | grep -F "$1" | sed -e 's/:=/:/g' | cut -d: -f2- | stripwhitespace
39 attr="${UPDATE_NIX_ATTR_PATH:-curl-impersonate}"
40 version="$(curl -sSL "https://api.github.com/repos/lwthiker/curl-impersonate/releases/latest" | jq -r .tag_name | sed -e 's/^v//')"
42 pkgpath="$(findpath "$attr")"
44 updated="$(cd "$nixpkgs" && update-source-version "$attr" "$version" --file="$pkgpath" --print-changes | jq -r length)"
46 if [ "$updated" -eq 0 ]; then
47 echo 'update.sh: Package version not updated, nothing to do.'
48 exit 0
51 vars="$(curl -sSL "https://github.com/lwthiker/curl-impersonate/raw/v$version/Makefile.in" | grep '^ *[^ ]*_\(VERSION\|URL\|COMMIT\) *:=')"
53 cat >"$(dirname "$pkgpath")"/deps.nix <<EOF
54 # Generated by update.sh
55 { fetchurl }:
58 "$(getvar CURL_VERSION "$vars").tar.xz" = fetchurl {
59 url = "https://curl.se/download/$(getvar CURL_VERSION "$vars").tar.xz";
60 hash = "$(narhash "https://curl.se/download/$(getvar CURL_VERSION "$vars").tar.xz")";
63 "brotli-$(getvar BROTLI_VERSION "$vars").tar.gz" = fetchurl {
64 url = "https://github.com/google/brotli/archive/refs/tags/v$(getvar BROTLI_VERSION "$vars").tar.gz";
65 hash = "$(narhash "https://github.com/google/brotli/archive/refs/tags/v$(getvar BROTLI_VERSION "$vars").tar.gz")";
68 "$(getvar NSS_VERSION "$vars").tar.gz" = fetchurl {
69 url = "$(getvar NSS_URL "$vars")";
70 hash = "$(narhash "$(getvar NSS_URL "$vars")")";
73 "boringssl.zip" = fetchurl {
74 url = "https://github.com/google/boringssl/archive/$(getvar BORING_SSL_COMMIT "$vars").zip";
75 hash = "$(narhash "https://github.com/google/boringssl/archive/$(getvar BORING_SSL_COMMIT "$vars").zip")";
78 "$(getvar NGHTTP2_VERSION "$vars").tar.bz2" = fetchurl {
79 url = "$(getvar NGHTTP2_URL "$vars")";
80 hash = "$(narhash "$(getvar NGHTTP2_URL "$vars")")";
83 EOF
85 curhash="$(nixeval "$attr.curl-impersonate-chrome.boringssl-go-modules.outputHash")"
86 newhash="$(vendorhash "$attr.curl-impersonate-chrome.boringssl-go-modules")"
88 if [ -n "$newhash" ] && [ "$curhash" != "$newhash" ]; then
89 sed -i -e "s|\"$curhash\"|\"$newhash\"|" "$pkgpath"
90 else
91 echo 'update.sh: New vendorHash same as old vendorHash, nothing to do.'