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.

82 lines
1.9 KiB

16 years ago
17 years ago
17 years ago
17 years ago
17 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/doc/'
  10. DOC_PATH = '../doc/'
  11. DOCS = [ 'quickstart', 'upgrading', 'configuration', 'faq' ]
  12. MANS = [ 'pamusb-check', 'pamusb-agent', 'pamusb-conf' ]
  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. Dir.chdir(File.dirname($0))
  43. DOCS.each do |doc|
  44. print "Fetching doc:#{doc}... "
  45. STDOUT.flush
  46. text = fetch_doc(doc)
  47. File.open(File.join(DOC_PATH, doc.upcase), 'w') { |f| f.write(text) }
  48. puts "Done."
  49. end
  50. MANS.each do |man|
  51. print "Fetching man:#{man}... "
  52. STDOUT.flush
  53. doc = fetch_doc("man/#{man}")
  54. cmd = "txt2man -v \"PAM_USB\" -s1 -t#{man}"
  55. cmd += ' | sed "s/\\\\\\\\\\\\\\\\/\\\\\\/g"'
  56. File.popen("#{cmd} > #{File.join(DOC_PATH, man)}.1", 'w') do |f|
  57. f.write(doc)
  58. end
  59. begin
  60. File.unlink("#{File.join(DOC_PATH, man)}.1.gz")
  61. rescue Exception
  62. end
  63. system("gzip #{File.join(DOC_PATH, man)}.1")
  64. puts "Done."
  65. end