summary refs log tree commit diff
path: root/pkgs/applications/networking/browsers/firefox-bin/generate_sources.rb
blob: c4e140412881c0c188d0180918af362789bb0ac6 (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
# TODO share code with thunderbird-bin/generate_nix.rb

version = if ARGV.empty?
            "latest"
          else
            ARGV[0]
          end

base_path = "archive.mozilla.org/pub/firefox/releases"

arches = ["linux-i686", "linux-x86_64"]

arches.each do |arch|
  system("wget", "--recursive", "--continue", "--no-parent", "--reject-regex", ".*\\?.*", "--reject", "xpi", "http://#{base_path}/#{version}/#{arch}/")
end

locales = Dir.glob("#{base_path}/#{version}/#{arches[0]}/*").map do |path|
  File.basename(path)
end.sort

locales.delete("index.html")
locales.delete("xpi")

# real version number, e.g. "30.0" instead of "latest".
real_version = Dir.glob("#{base_path}/#{version}/#{arches[0]}/#{locales[0]}/firefox-*")[0].match(/firefox-([0-9.]*)/)[1][0..-2]

locale_arch_path_tuples = locales.flat_map do |locale|
  arches.map do |arch|
    path = Dir.glob("#{base_path}/#{version}/#{arch}/#{locale}/firefox-*")[0]

    [locale, arch, path]
  end
end

paths = locale_arch_path_tuples.map do |tuple| tuple[2] end

hashes = IO.popen(["sha256sum", "--binary", *paths]) do |input|
  input.each_line.map do |line|
    $stderr.puts(line)

    line.match(/^[0-9a-f]*/)[0]
  end
end


puts(<<"EOH")
# This file is generated from generate_sources.rb. DO NOT EDIT.
# Execute the following command in a temporary directory to update the file.
#
# ruby generate_sources.rb > sources.nix

{
  version = "#{real_version}";
  sources = [
EOH

locale_arch_path_tuples.zip(hashes) do |tuple, hash|
  locale, arch, path = tuple

  puts(%Q|    { locale = "#{locale}"; arch = "#{arch}"; sha256 = "#{hash}"; }|)
end

puts(<<'EOF')
  ];
}
EOF