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