2018-03-04 23:11:09 +01:00
|
|
|
{ lib
|
|
|
|
, writeScript
|
|
|
|
, common-updater-scripts
|
|
|
|
, bash
|
|
|
|
, coreutils
|
|
|
|
, curl
|
|
|
|
, gnugrep
|
|
|
|
, gnupg
|
|
|
|
, gnused
|
|
|
|
, nix
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
downloadPageUrl = "https://dist.torproject.org";
|
|
|
|
|
2022-03-07 14:51:26 +01:00
|
|
|
# See https://support.torproject.org/little-t-tor/#fetching-the-tor-developers-key
|
2018-03-04 23:11:09 +01:00
|
|
|
signingKeys = [
|
2022-03-07 14:51:26 +01:00
|
|
|
"514102454D0A87DB0767A1EBBE6A0531C18A9179" # Alexander Færøy
|
|
|
|
"B74417EDDF22AC9F9E90F49142E86A2A11F48D36" # David Goulet
|
|
|
|
"2133BC600AB133E1D826D173FE43009C4607B1FB" # Nick Mathewson
|
2018-03-04 23:11:09 +01:00
|
|
|
];
|
|
|
|
in
|
|
|
|
|
|
|
|
writeScript "update-tor" ''
|
|
|
|
#! ${bash}/bin/bash
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
2023-01-24 17:35:54 +01:00
|
|
|
export PATH=${lib.makeBinPath [
|
2018-03-04 23:11:09 +01:00
|
|
|
common-updater-scripts
|
|
|
|
coreutils
|
|
|
|
curl
|
|
|
|
gnugrep
|
|
|
|
gnupg
|
|
|
|
gnused
|
|
|
|
nix
|
|
|
|
]}
|
|
|
|
|
|
|
|
srcBase=$(curl -L --list-only -- "${downloadPageUrl}" \
|
|
|
|
| grep -Eo 'tor-([[:digit:]]+\.?)+\.tar\.gz' \
|
|
|
|
| sort -Vu \
|
|
|
|
| tail -n1)
|
|
|
|
srcFile=$srcBase
|
|
|
|
srcUrl=${downloadPageUrl}/$srcBase
|
|
|
|
|
|
|
|
srcName=''${srcBase/.tar.gz/}
|
|
|
|
srcVers=(''${srcName//-/ })
|
|
|
|
version=''${srcVers[1]}
|
|
|
|
|
2022-03-07 14:51:26 +01:00
|
|
|
checksumUrl=$srcUrl.sha256sum
|
|
|
|
checksumFile=''${checksumUrl##*/}
|
|
|
|
|
|
|
|
sigUrl=$checksumUrl.asc
|
2018-03-04 23:11:09 +01:00
|
|
|
sigFile=''${sigUrl##*/}
|
|
|
|
|
|
|
|
# upstream does not support byte ranges ...
|
|
|
|
[[ -e "$srcFile" ]] || curl -L -o "$srcFile" -- "$srcUrl"
|
2022-03-07 14:51:26 +01:00
|
|
|
[[ -e "$checksumFile" ]] || curl -L -o "$checksumFile" -- "$checksumUrl"
|
2018-03-04 23:11:09 +01:00
|
|
|
[[ -e "$sigFile" ]] || curl -L -o "$sigFile" -- "$sigUrl"
|
|
|
|
|
|
|
|
export GNUPGHOME=$PWD/gnupg
|
|
|
|
mkdir -m 700 -p "$GNUPGHOME"
|
|
|
|
|
2023-01-24 17:35:54 +01:00
|
|
|
gpg --batch --recv-keys ${lib.concatStringsSep " " (map (x: "'${x}'") signingKeys)}
|
2022-03-07 14:51:26 +01:00
|
|
|
gpg --batch --verify "$sigFile" "$checksumFile"
|
2018-03-04 23:11:09 +01:00
|
|
|
|
2022-03-07 14:51:26 +01:00
|
|
|
sha256sum -c "$checksumFile"
|
2018-03-04 23:11:09 +01:00
|
|
|
|
2022-03-07 14:51:26 +01:00
|
|
|
update-source-version tor "$version" "$(cut -d ' ' "$checksumFile")"
|
2018-03-04 23:11:09 +01:00
|
|
|
''
|