summaryrefslogtreecommitdiff
path: root/website/tools/hardware-notes-processor.rb
blob: 4f2bd4fa9d778ac65de09fee7175956fa91028a3 (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
#!/usr/bin/env ruby
=begin

BSD 2-Clause License
Copyright (c) 2020-2022, The FreeBSD Project
Copyright (c) 2020-2022, Sergio Carlavilla <carlavilla@FreeBSD.org>

This script will generate the hardware notes

=end
require 'open3'

# Main method
puts "Processing hardware notes..."

if ARGV.length < 1 || ARGV.length > 1
  puts "Only expecting the release version"
  exit
end

hardwareNotesPath = ARGV[0]
hardwareNotesContent = ""

File.foreach(hardwareNotesPath).with_index do |line|
  if (line[/&hwlist.\b/])
    manualPage = line.gsub("&hwlist.", "").gsub(";", "").gsub("\n", "")

    if(File.exist?("tmp/share/man/man4/" + manualPage + ".4"))
      cmd = "mandoc -Tmarkdown tmp/share/man/man4/" + manualPage + ".4 | sed -n '/# HARDWARE/,/#/{/#/!p;}' "
      mandocOut, err, s = Open3::capture3(cmd)
      if s.success?
        hardwareNotesContent << mandocOut
      end
    else
      puts "WARNING: The manual page " + manualPage + " does not exists"
    end
  else
    hardwareNotesContent << line
  end
end

File.open(hardwareNotesPath, 'w') do |out|
  out << hardwareNotesContent
end