blob: 5a2a81cd927a48244770357fab9ec816d5790d4a (
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
55
56
57
58
59
60
61
62
63
64
65
66
|
#! /usr/bin/env sh
set -e
tmpHomePath="$(mktemp -d "${TMPDIR:-/tmp}/nix-prefetch-url-XXXXXXXXXX")"
cleanup() {
chmod -R u+w "$tmpHomePath"
rm -rf "$tmpHomePath"
}
trap cleanup EXIT
info() {
echo "$1" 1>&2
}
# Returns a name based on the url and reference
#
# This function needs to be in sync with nix's fetchgit implementation
# of urlToName() to re-use the same nix store paths.
url_to_name() {
url=$1
basename "$url" .git | cut -d: -f2
}
get_sha256() {
url="$1"
storePathName="$(url_to_name "$url")"
hashType="sha256"
tmpOut="$tmpHomePath/$storePathName"
info "Prefetching '$url'..."
curl --follow "$url" >"$tmpOut"
# Compute the hash.
hash=$(nix-hash --flat --type "$hashType" --sri "$tmpOut")
# Add the downloaded file to the Nix store.
finalPath=$(nix-store --add-fixed "$hashType" "$tmpOut")
info " -> Downloaded to '$finalPath'"
echo "$hash"
}
old_version="$(jq .version --raw-output <./files.json)"
new_version="$(curl --follow https://download.tails.net/tails/stable/ 2>/dev/null | html2text -links | grep --regexp='\s*[0-9]\. tails-amd64-' | sed 's/\s*[0-9]\. tails-amd64-\(.*\)\//\1/')"
if [ "$old_version" = "$new_version" ]; then
# No need to update.
info exit 0
fi
final_version="amd64-$new_version"
cat <<EOF | jq . | tee ./files.json
{
"version": "$new_version",
"files": {
"iso.sig": "$(get_sha256 "https://tails.net/torrents/files/tails-$final_version.iso.sig")",
"iso": "$(get_sha256 "https://download.tails.net/tails/stable/tails-$final_version/tails-$final_version.iso")"
}
}
EOF
# vim: ft=sh
|