summary refs log tree commit diff
path: root/pkgs/development/web/iojs/update-iojs
blob: 4e01ecfd63e0a8104017d335990ccd5a3c0f5455 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
#
# Fetch the latest io.js release (stable/nightly) and update
# `default.nix` in this directory.
#
# Call this from the root of your nixpkgs directory.
#

set -e

HERE="$(dirname "$0")"

latest() {
    curl -s "$1" | grep 'href="v' \
        | tail -1 | sed 's/.*href="v//;s/\/".*//'
}

latest_log() {
    echo "Getting latest $1 version from $2" >&2
    version=$(latest "$2")
    echo " -> $version" >&2
    echo "$version"
}

url() {
    nix-instantiate -A "$1" \
        | xargs cat \
        | sed 's/.*"urls","//;s/".*//'
}

hash() {
    nix-prefetch-url "$1"
}

hash_log() {
    echo "Finding hash for $1" >&2
    value=$(hash "$1")
    echo " -> $value" >&2
    echo "$value"
}

stable=$(latest_log stable 'https://iojs.org/dist/')
nightly=$(latest_log nightly 'https://iojs.org/download/nightly/')

sed -i \
    "/version = if nightly/s/then.*/then \"$nightly\" else \"$stable\";/" \
    "$HERE/default.nix"

stableHash=$(hash_log "$(url iojs.src)")
nightlyHash=$(hash_log "$(url iojs-nightly.src)")

sed -i \
    "/sha256 = if nightly/{N;s/\"[^\"]*\"/\"$nightlyHash\"/;N;s/\"[^\"]*\";/\"$stableHash\";/}" \
    "$HERE/default.nix"