tor-browser: adjust update script for upcoming changes

Both Tor Browser & Mullvad Browser will use slightly different archive
names beginnign with release 13.0. In addition to adjusting to those
changes, the update script now supports prereleases via an argument.
This commit is contained in:
Felix Schröter 2023-09-23 19:06:38 +02:00 committed by Alyssa Ross
parent 0cb660d57d
commit d987335f49
2 changed files with 13 additions and 10 deletions

View file

@ -232,7 +232,7 @@ stdenv.mkDerivation rec {
updateScript = callPackage ../tor-browser/update.nix {
inherit pname version meta;
baseUrl = "https://cdn.mullvad.net/browser/";
prefix = "mullvad-browser-";
name = "mullvad-browser";
};
};

View file

@ -13,13 +13,16 @@
, version
, meta
, baseUrl ? "https://dist.torproject.org/torbrowser/"
# prefix used to match published archive
, prefix ? "tor-browser-"
# suffix used to match published archive
, suffix ? "_ALL.tar.xz"
# name used to match published archive
, name ? "tor-browser"
, prerelease ? false
}:
writeShellScript "update-${pname}" ''
let
versionMatch = if prerelease
then ''[0-9]+(\.[0-9]+)*.*''
else ''[0-9]+(\.[0-9]+)*'';
in writeShellScript "update-${pname}" ''
PATH="${lib.makeBinPath [ coreutils curl gnugrep gnused gnupg nix common-updater-scripts ]}"
set -euo pipefail
@ -27,7 +30,7 @@ writeShellScript "update-${pname}" ''
url=${baseUrl}
version=$(curl -s $url \
| sed -rne 's,^.*href="([0-9]+(\.[0-9]+)*)/".*,\1,p' \
| sed -rne 's,^.*href="(${versionMatch})/".*,\1,p' \
| sort --version-sort | tail -1)
if [[ "${version}" = "$version" ]]; then
@ -47,13 +50,13 @@ writeShellScript "update-${pname}" ''
gpgv --keyring=$HOME/tor.keyring $HOME/shasums.asc $HOME/shasums
declare -A platforms=(
['x86_64-linux']='linux64'
['i686-linux']='linux32'
['x86_64-linux']='linux-x86_64'
['i686-linux']='linux-i686'
)
for platform in ${lib.escapeShellArgs meta.platforms}; do
arch="''${platforms[$platform]}"
sha256=$(cat "$HOME/shasums" | grep "${prefix}""$arch-$version""${suffix}" | cut -d" " -f1)
sha256=$(grep "${name}-$arch-$version.tar.xz" "$HOME/shasums" | cut -d" " -f1)
hash=$(nix hash to-sri --type sha256 "$sha256")
update-source-version "${pname}" "0" "sha256-${lib.fakeSha256}" --source-key="sources.$platform"