12 def build_used_package_list(source_uri)
13 source_uri.map do |source_uri|
14 fetch_file(source_uri).split("\n").reject do |l|
15 l.strip.start_with?('#') or l.strip == ""
20 def parse_debian_sources(data)
21 data.split("\n").push('').inject({}) do |pkgs, l|
23 pkg = pkgs[:_tmp] || {}
26 pkg[:_tmp][:data] << l.strip
28 pkg[pkg[:_tmp][:hdr]] = pkg[:_tmp][:data].compact
34 pkgs[pkg['Package'][0]] = pkg
37 hdr, data = l.strip.split(':', 2)
38 data.strip! unless data.nil?
39 pkg[:_tmp] = {:hdr => hdr, :data => [data]}
51 def build_package_list(repos, used, sources)
53 repos.each do |pkg, path|
54 g = Git.bare(working_dir = path)
55 tree = g.ls_tree('HEAD')["tree"]
56 if pkg == 'grml-kernel'
57 tree = g.ls_tree(g.ls_tree("HEAD")["tree"]["linux-3"][:sha])["tree"]
59 next if not tree.keys.include?("debian")
61 current_head = g.gcommit('HEAD')
62 next if not current_head.parent
65 :head_is_tagged => false,
71 :git_browser => "http://git.grml.org/?p=%s.git;a=summary" % pkg,
72 :git_anon => "git://git.grml.org/%s.git" % pkg,
73 :repo_url => "http://deb.grml.org/pool/main/%s/%s/" % [pkg[0..0], pkg],
76 p[:used][dist] = l.include?(pkg)
79 p[:repo_version] = sources[pkg]['Version'][0]
80 p[:source_name] = sources[pkg]['Package'][0]
83 for tag in g.tags.reverse
85 t = g.gcommit(tag.name)
87 #$stderr.puts "#{pkg}: Checking tag #{tag.name}: tag parent: #{t.parent.sha} HEAD: #{current_head.parent.sha}"
88 if t.parent.sha === current_head.parent.sha
89 p[:head_is_tagged] = true
90 p[:git_version] = tag.name
101 response = Net::HTTP.get_response(URI.parse(uri))
103 if uri.match(/\.gz$/)
104 body = Zlib::GzipReader.new(StringIO.new(body.to_s)).read
109 def update_git_repos(git_repos)
110 git_repos.each do |name, path|
111 out = %x{cd #{path} && git remote update --prune 2>&1}
112 puts "#{name}: " + out if DEBUG
116 template = ERB.new <<-EOF
119 <meta charset="utf-8">
120 <title>Grml.org Package Index</title>
121 <link rel="stylesheet" href="style.css">
125 <h1>All Grml packages</h1>
130 <th>Package</th><th>Git</th><th>Download</th><th>Git Version</th><th>grml-testing</th><th>In FULL?</th>
132 <% packages.keys.sort.each do |pn|
136 <td><%= p[:name] %></td>
137 <td class="git"><a href="<%= p[:git_browser] %>">Git</a></td>
138 <td class="download">
139 <% if p[:has_tags] %>
140 <a href="<%= p[:repo_url] %>">Download</a>
143 <% if p[:head_is_tagged] %>
144 <td class="ok">Version <%= p[:git_version] %></td>
146 <td class="error <% if p[:used][:full] %>important<% end %>">Untagged changes</td>
148 <td><%= p[:repo_version] || "" %></td>
149 <td class="installed"><%= p[:used][:full] ? "Yes" : "No" %></td>
155 Other packages: <%= other_packages.join(" ") %>
158 <p>Last update: <%= Time.now.to_s %></p>
165 :full => build_used_package_list([
166 'http://git.grml.org/?p=grml-live.git;a=blob_plain;f=etc/grml/fai/config/package_config/GRMLBASE',
167 'http://git.grml.org/?p=grml-live.git;a=blob_plain;f=etc/grml/fai/config/package_config/GRML_FULL',
171 parse_debian_sources(fetch_file('http://deb.grml.org/dists/grml-testing/main/source/Sources.gz')).each do |k,v|
172 if v['Vcs-Git'] and v['Vcs-Git'][0]
173 m = v['Vcs-Git'][0].match 'git.grml.org\/(.*).git$'
179 git_repos = Hash[*(Dir.glob('git/*.git').map do |p| [File.basename(p, '.git'), p] end.flatten)]
181 update_git_repos git_repos
183 packages = build_package_list(git_repos, used_packages, sources)
184 other_packages = (sources.keys - git_repos.keys)
186 File.open('index.html.new','w') do |f|
187 f.write template.result(binding)
189 File.open('packages.yaml.new','w') do |f|
190 f.write packages.to_yaml
193 FileUtils.mv 'index.html.new', 'index.html'
194 FileUtils.mv 'packages.yaml.new', 'packages.yaml'