Hardware authentication for Linux using ordinary USB Flash Drives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.8 KiB

18 years ago
18 years ago
  1. #!/usr/bin/env ruby
  2. #
  3. # fetch_doc.rb
  4. #
  5. # Fetch the documentation from the wiki and translate it
  6. # to be human readable.
  7. #
  8. require 'open-uri'
  9. BASE_URI = 'http://www.pamusb.org/wiki/doc/'
  10. DOC_PATH = './pam_usb/doc/'
  11. DOCS = [ 'installation', 'upgrading', 'configuration' ]
  12. MANS = [ 'pusb_hotplug' ]
  13. REPLACE_LIST = [
  14. # Remove wiki links [[link|name]]
  15. { :pattern => /\[\[.+\|(.+)\]\]/, :with => '\1' },
  16. # Remove misc xhtml/wiki characters
  17. { :pattern => /\/\//, :with => '' },
  18. { :pattern => /\\\\ /, :with => '' },
  19. { :pattern => /\*\*/, :with => '' },
  20. { :pattern => /&lt;/, :with => '<' },
  21. { :pattern => /&gt;/, :with => '>' },
  22. { :pattern => /&quot;/, :with => '"' },
  23. { :pattern => /<code .+>.*\n/, :with => '' },
  24. { :pattern => /<\/code>.*\n/, :with => '' },
  25. { :pattern => /<file>(.+)<\/file>/m, :with => '\1' },
  26. # Remove trailing whitespaces
  27. { :pattern => /^ /, :with => '' },
  28. # Fit 80 colums
  29. { :pattern => /(.{1,80})( +|$\n?)|(.{1,80})/, :with => "\\1\\3\n" },
  30. ]
  31. def fetch_raw_doc(name)
  32. uri = BASE_URI + name + '?do=edit'
  33. body = open(uri) { |f| f.read }
  34. body.gsub!(/.*<textarea .+>\n(.*)<\/textarea>.*/m, '\1')
  35. body.gsub(/\r\n/, "\n")
  36. end
  37. def fetch_doc(name)
  38. body = fetch_raw_doc(name)
  39. REPLACE_LIST.each { |r| body.gsub!(r[:pattern], r[:with]) }
  40. body
  41. end
  42. DOCS.each do |doc|
  43. print "Fetching doc:#{doc}... "
  44. STDOUT.flush
  45. text = fetch_doc(doc)
  46. File.open(File.join(DOC_PATH, doc), 'w') { |f| f.write(text) }
  47. puts "Done."
  48. end
  49. MANS.each do |man|
  50. print "Fetching man:#{man}... "
  51. STDOUT.flush
  52. doc = fetch_doc("man/#{man}")
  53. cmd = "txt2man -v \"PAMUSB\" -s1 -t#{man}"
  54. cmd += ' | sed "s/\\\\\\\\\\\\\\\\/\\\\\\/g"'
  55. File.popen("#{cmd} > #{File.join(DOC_PATH, man)}.1", 'w') do |f|
  56. f.write(doc)
  57. end
  58. system("gzip #{File.join(DOC_PATH, man)}.1")
  59. puts "Done."
  60. end