@@ -0,0 +1,60 @@
1+{ writeScript }:
2+
3+writeScript "update-mendeley" ''
4+ function follow() {
5+ local URL=$1
6+ while true; do
7+ NEWURL=$(curl -m20 -sI "$URL" -o /dev/null -w '%{redirect_url}')
8+ [ -z "$NEWURL" ] && break
9+ [[ $NEWURL = $URL ]] && (echo "redirect loop?!"; exit 1)
10+ echo "Following $URL -> $NEWURL ..." >&2
11+ URL=$NEWURL
12+ done
13+
14+ echo $URL
15+ }
16+
17+ amd64URL=$(follow https://www.mendeley.com/repositories/ubuntu/stable/amd64/mendeleydesktop-latest)
18+ amd64V=$(basename $amd64URL|grep -m1 -o "[0-9]\+\.[0-9]\+\.[0-9]\+")
19+ i386URL=$(follow https://www.mendeley.com/repositories/ubuntu/stable/i386/mendeleydesktop-latest)
20+ i386V=$(basename $i386URL|grep -m1 -o "[0-9]\+\.[0-9]\+\.[0-9]\+")
21+
22+ echo "amd64 version: $amd64V"
23+ echo "i386 version: $i386V"
24+ if [[ $amd64V != $i386V ]]; then
25+ echo "Versions not the same!"
26+ exit 1
27+ fi
28+
29+ if grep -q -F "$amd64V" ${./default.nix}; then
30+ echo "No new version yet, nothing to do."
31+ echo "Have a nice day!"
32+ exit 0
33+ fi
34+
35+ amd64OldHash=$(nix-instantiate --eval --strict -A "mendeley.src.drvAttrs.outputHash" --argstr system "x86_64-linux"| tr -d '"')
36+ i386OldHash=$(nix-instantiate --eval --strict -A "mendeley.src.drvAttrs.outputHash" --argstr system "i686-linux"| tr -d '"')
37+
38+ echo "Prefetching amd64..."
39+ amd64NewHash=$(nix-prefetch-url $amd64URL)
40+ echo "Prefetching i386..."
41+ i386NewHash=$(nix-prefetch-url $i386URL)
42+
43+ # Don't actually update, just report that an update is available
44+ cat <<EOF
45+
46+
47+ Time to update to $amd64V !
48+
49+ 32bit (i386):
50+ Old: $i386OldHash
51+ New: $i386NewHash
52+ 64bit (amd64):
53+ Old: $amd64OldHash
54+ New: $amd64NewHash
55+
56+ Exiting so this information is seen...
57+ (no update is actually performed here)
58+ EOF
59+ exit 1
60+''