about summary refs log tree commit diff
path: root/pkgs/applications/networking/browsers/chromium/update.py
blob: 0a0d512004b54b4d3ff34b00b59001b2fb9f351c (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
#! /usr/bin/env nix-shell
#! nix-shell -i python -p python3 nix

import csv
import json
import subprocess
from codecs import iterdecode
from os.path import abspath, dirname
from sys import stderr
from urllib.request import urlopen

HISTORY_URL = 'https://omahaproxy.appspot.com/history?os=linux'
DEB_URL = 'https://dl.google.com/linux/chrome/deb/pool/main/g'
BUCKET_URL = 'https://commondatastorage.googleapis.com/chromium-browser-official'

JSON_PATH = dirname(abspath(__file__)) + '/upstream-info.json'

def load_json(path):
    with open(path, 'r') as f:
        return json.load(f)

def nix_prefetch_url(url, algo='sha256'):
    print(f'nix-prefetch-url {url}')
    out = subprocess.check_output(['nix-prefetch-url', '--type', algo, url])
    return out.decode('utf-8').rstrip()

channels = {}
last_channels = load_json(JSON_PATH)

print(f'GET {HISTORY_URL}', file=stderr)
with urlopen(HISTORY_URL) as resp:
    builds = csv.DictReader(iterdecode(resp, 'utf-8'))
    for build in builds:
        channel_name = build['channel']

        # If we've already found a newer build for this channel, we're
        # no longer interested in it.
        if channel_name in channels:
            continue

        # If we're back at the last build we used, we don't need to
        # keep going -- there's no new version available, and we can
        # just reuse the info from last time.
        if build['version'] == last_channels[channel_name]['version']:
            channels[channel_name] = last_channels[channel_name]
            continue

        channel = {'version': build['version']}
        suffix = 'unstable' if channel_name == 'dev' else channel_name

        try:
            channel['sha256'] = nix_prefetch_url(f'{BUCKET_URL}/chromium-{build["version"]}.tar.xz')
            channel['sha256bin64'] = nix_prefetch_url(f'{DEB_URL}/google-chrome-{suffix}/google-chrome-{suffix}_{build["version"]}-1_amd64.deb')
        except subprocess.CalledProcessError:
            # This build isn't actually available yet.  Continue to
            # the next one.
            continue

        channels[channel_name] = channel

with open(JSON_PATH, 'w') as out:
    json.dump(channels, out, indent=2)
    out.write('\n')