From 332389611ac8cf4d6c09b763890164771d6124f2 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Sun, 14 Jan 2018 13:58:15 -0600 Subject: [PATCH] mendeley: Add update-checker script, add myself as maintainer Doesn't actually edit the file, but reports when an update is available and provides useful information. --- pkgs/applications/office/mendeley/default.nix | 11 +++- pkgs/applications/office/mendeley/update.nix | 60 +++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 pkgs/applications/office/mendeley/update.nix diff --git a/pkgs/applications/office/mendeley/default.nix b/pkgs/applications/office/mendeley/default.nix index c2b6dc710ba2..8c69c8f891c6 100644 --- a/pkgs/applications/office/mendeley/default.nix +++ b/pkgs/applications/office/mendeley/default.nix @@ -31,6 +31,8 @@ # will leave entries on your system after uninstalling mendeley. # (they can be removed by running '$out/bin/install-mendeley-link-handler.sh -u') , autorunLinkHandler ? true +# Update script +, writeScript }: assert stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux"; @@ -133,11 +135,14 @@ stdenv.mkDerivation { dontStrip = true; dontPatchElf = true; - meta = { + updateScript = import ./update.nix { inherit writeScript; }; + + meta = with stdenv.lib; { homepage = http://www.mendeley.com; description = "A reference manager and academic social network"; - license = stdenv.lib.licenses.unfree; - platforms = stdenv.lib.platforms.linux; + license = licenses.unfree; + platforms = platforms.linux; + maintainers = with maintainers; [ dtzWill ]; }; } diff --git a/pkgs/applications/office/mendeley/update.nix b/pkgs/applications/office/mendeley/update.nix new file mode 100644 index 000000000000..9ac82615c561 --- /dev/null +++ b/pkgs/applications/office/mendeley/update.nix @@ -0,0 +1,60 @@ +{ writeScript }: + +writeScript "update-mendeley" '' + function follow() { + local URL=$1 + while true; do + NEWURL=$(curl -m20 -sI "$URL" -o /dev/null -w '%{redirect_url}') + [ -z "$NEWURL" ] && break + [[ $NEWURL = $URL ]] && (echo "redirect loop?!"; exit 1) + echo "Following $URL -> $NEWURL ..." >&2 + URL=$NEWURL + done + + echo $URL + } + + amd64URL=$(follow https://www.mendeley.com/repositories/ubuntu/stable/amd64/mendeleydesktop-latest) + amd64V=$(basename $amd64URL|grep -m1 -o "[0-9]\+\.[0-9]\+\.[0-9]\+") + i386URL=$(follow https://www.mendeley.com/repositories/ubuntu/stable/i386/mendeleydesktop-latest) + i386V=$(basename $i386URL|grep -m1 -o "[0-9]\+\.[0-9]\+\.[0-9]\+") + + echo "amd64 version: $amd64V" + echo "i386 version: $i386V" + if [[ $amd64V != $i386V ]]; then + echo "Versions not the same!" + exit 1 + fi + + if grep -q -F "$amd64V" ${./default.nix}; then + echo "No new version yet, nothing to do." + echo "Have a nice day!" + exit 0 + fi + + amd64OldHash=$(nix-instantiate --eval --strict -A "mendeley.src.drvAttrs.outputHash" --argstr system "x86_64-linux"| tr -d '"') + i386OldHash=$(nix-instantiate --eval --strict -A "mendeley.src.drvAttrs.outputHash" --argstr system "i686-linux"| tr -d '"') + + echo "Prefetching amd64..." + amd64NewHash=$(nix-prefetch-url $amd64URL) + echo "Prefetching i386..." + i386NewHash=$(nix-prefetch-url $i386URL) + + # Don't actually update, just report that an update is available + cat <