Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 68 lines 3.0 kB view raw
1#!/usr/bin/env nix-shell 2#! nix-shell -i bash --pure -p curl cacert libxml2 yq nix jq 3#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/3c7487575d9445185249a159046cc02ff364bff8.tar.gz 4# ^ 5# | 6# nixos-unstable ~ 2023-07-06 -----------------/ 7 8set -o errexit 9set -o nounset 10 11# scrape the downloads page for release info 12 13curl -s -o eclipse-dl.html https://download.eclipse.org/eclipse/downloads/ 14trap "rm eclipse-dl.html" EXIT 15 16dlquery() { 17 q=$1 18 xmllint --html eclipse-dl.html --xmlout 2>/dev/null | xq -r ".html.body.main.div.table[3].tr[1].td[0].a${q}"; 19} 20 21# extract release info from download page HTML 22 23platform_major=$(dlquery '."#text" | split(".") | .[0]' -r); 24platform_minor=$(dlquery '."#text" | split(".") | .[1]' -r); 25 26year=$(dlquery '."@href" | split("/") | .[] | select(. | startswith("R")) | split("-") | .[2] | .[0:4]') 27buildmonth=$(dlquery '."@href" | split("/") | .[] | select(. | startswith("R")) | split("-") | .[2] | .[4:6]') 28builddaytime=$(dlquery '."@href" | split("/") | .[] | select(. | startswith("R")) | split("-") | .[2] | .[6:12]') 29timestamp="${year}${buildmonth}${builddaytime}"; 30 31# account for possible release-month vs. build-month mismatches 32 33month=$buildmonth; 34case "$buildmonth" in 35 '02'|'04') month='03' ;; 36 '05'|'07') month='06' ;; 37 '08'|'10') month='09' ;; 38 '11'|'01') month='12' ;; 39esac 40 41ECLIPSES_JSON=$(dirname $0)/eclipses.json; 42 43t=$(mktemp); 44# note: including platform_major, platform_minor, and version may seem redundant 45# the first two are needed for the derivation itself; the third is necessary so 46# that nixpkgs-update can see that the version changes as a result of this update 47# script. 48cat $ECLIPSES_JSON | jq ". + {platform_major: \"${platform_major}\",platform_minor: \"${platform_minor}\",version:\"${platform_major}.${platform_minor}\",year: \"${year}\",month: \"${month}\",buildmonth: \"${buildmonth}\",dayHourMinute: \"${builddaytime}\"}" > $t; 49mv $t $ECLIPSES_JSON; 50 51# prefetch new download hashes 52 53for id in $(cat $ECLIPSES_JSON | jq -r '.eclipses | keys | .[]'); do 54 for arch in x86_64 aarch64; do 55 if [ $(cat $ECLIPSES_JSON | jq -r ".eclipses.${id}.dropUrl") == "true" ]; then 56 url="https://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/eclipse/downloads/drops${platform_major}/R-${platform_major}.${platform_minor}-${timestamp}/eclipse-${id}-${platform_major}.${platform_minor}-linux-gtk-${arch}.tar.gz"; 57 else 58 url="https://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/technology/epp/downloads/release/${year}-${month}/R/eclipse-${id}-${year}-${month}-R-linux-gtk-${arch}.tar.gz"; 59 fi 60 61 echo "prefetching ${id} ${arch}"; 62 h=$(nix store prefetch-file --json "$url" | jq -r .hash); 63 64 t=$(mktemp); 65 cat $ECLIPSES_JSON | jq -r ".eclipses.${id}.hashes.${arch} = \"${h}\"" > $t; 66 mv $t $ECLIPSES_JSON; 67 done 68done