firefox-extensions: fix the damn uBlock update script
This commit is contained in:
53
pkgs/by-name/firefox-extensions/addon-version-lister
Executable file
53
pkgs/by-name/firefox-extensions/addon-version-lister
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p bash -p common-updater-scripts -p coreutils -p curl
|
||||
|
||||
NEWLINE=$'\n'
|
||||
|
||||
numeric_version() {
|
||||
# TODO: consider `b<n>` or `rc<n>` suffixes?
|
||||
echo "$1" | egrep --only-matching "[0-9.]+" | head -n1
|
||||
}
|
||||
|
||||
sort_versions() {
|
||||
local lines=
|
||||
for v in $1; do
|
||||
local n=$(numeric_version "$v")
|
||||
lines="$lines$n $v$NEWLINE"
|
||||
done
|
||||
echo "$lines" | sort --version-sort --reverse | cut -d" " -f 2
|
||||
}
|
||||
|
||||
set -ex
|
||||
url="$1"
|
||||
|
||||
MAX_VERSIONS=${MAX_VERSIONS:-10}
|
||||
|
||||
# check that caller supplied all arguments
|
||||
test -n "$url"
|
||||
test -n "$UPDATE_NIX_OLD_VERSION"
|
||||
|
||||
# we need the bare git URL.
|
||||
# strip `https://github.com/OWNER/NAME/releases/download/...` -> `https://github.com/OWNER/NAME`
|
||||
repo_url="${url/\/releases*/}"
|
||||
|
||||
set +x
|
||||
all_versions=$(list-git-tags --url="$repo_url")
|
||||
all_versions=$(sort_versions "$all_versions")
|
||||
|
||||
# filter to the versions for which we can actually download an artifact.
|
||||
# some packages (uBlock) publish releases even before all artifacts are available.
|
||||
versions=()
|
||||
for v in $all_versions; do
|
||||
test_url=''${url//$UPDATE_NIX_OLD_VERSION/$v}
|
||||
if $(set -x; curl --fail "$test_url"); then
|
||||
versions+=("$v")
|
||||
fi
|
||||
|
||||
if [[ ${#versions[@]} -ge $MAX_VERSIONS ]]; then
|
||||
# if we have a bunch of versions already, then exit now instead of crawling through hundreds more tags we're just going to throw away.
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
set -x
|
||||
echo "${versions[*]}"
|
@@ -2,18 +2,27 @@
|
||||
callPackage,
|
||||
concatTextFile,
|
||||
fetchurl,
|
||||
genericUpdater,
|
||||
jq,
|
||||
lib,
|
||||
newScope,
|
||||
nix-update-script,
|
||||
runCommand,
|
||||
static-nix-shell,
|
||||
stdenv,
|
||||
strip-nondeterminism,
|
||||
unzip,
|
||||
writers,
|
||||
writeShellScript,
|
||||
zip,
|
||||
}:
|
||||
let
|
||||
addon-version-lister = static-nix-shell.mkBash {
|
||||
pname = "addon-version-lister";
|
||||
pkgs = [ "common-updater-scripts" "coreutils" "curl" ];
|
||||
srcRoot = ./.;
|
||||
};
|
||||
|
||||
wrapAddon = addon: args:
|
||||
let
|
||||
extid = addon.passthru.extid;
|
||||
@@ -107,14 +116,17 @@ let
|
||||
cp $src $out
|
||||
'';
|
||||
|
||||
passthru.updateScript = nix-update-script {
|
||||
# ignore beta versions
|
||||
extraArgs = [ "--version-regex" "([0-9.]+)$" ];
|
||||
passthru.updateScript = genericUpdater {
|
||||
versionLister = writeShellScript "${pname}-version-lister" ''
|
||||
${lib.getExe addon-version-lister} ${url}
|
||||
'';
|
||||
};
|
||||
passthru.extid = extid;
|
||||
};
|
||||
|
||||
firefox-extensions = (lib.makeScope newScope (self: with self; {
|
||||
inherit addon-version-lister;
|
||||
|
||||
unwrapped = lib.recurseIntoAttrs {
|
||||
# get names from:
|
||||
# - ~/ref/nix-community/nur-combined/repos/rycee/pkgs/firefox-addons/generated-firefox-addons.nix
|
||||
|
Reference in New Issue
Block a user