md2man.bash 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/bin/bash
  2. # Get OS type to calculate mtime properly later
  3. osType=$(uname)
  4. currentYear=$(date +%Y)
  5. authorAndCopyright=$(cat <<-END
  6. .SH "AUTHOR"
  7. .PP
  8. Manticore Software LTD (https://manticoresearch\&.com)
  9. .SH "COPYRIGHT"
  10. .PP
  11. Copyright 2017\-${currentYear} Manticore Software LTD (https://manticoresearch\&.com), 2008\-2016 Sphinx Technologies Inc (http://sphinxsearch\&.com), 2001\-2016 Andrew Aksyonoff
  12. .PP
  13. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 or any later version published by the Free Software Foundation\&.
  14. END
  15. )
  16. # indexer
  17. srcFile="../manual/english/Data_creation_and_modification/Adding_data_from_external_storages/Plain_tables_creation.md"
  18. destFile="indexer.1"
  19. cp $srcFile tmp.md
  20. # Remove all HTML comments
  21. sed -i '' '/<!--/,/-->/d' tmp.md
  22. # Remove all markdown links
  23. sed -i '' -r 's/\[([^]]+)\]\([^)]+\)/\`\1\`/g' tmp.md
  24. # Remove all before specified string, but not the string itself, and change the string to the new one
  25. sed -i '' -n '/## Indexer tool/,$p' tmp.md
  26. sed -i '' '1s/## Indexer tool/## DESCRIPTION/' tmp.md
  27. # Replace the long section name to just OPTIONS as the latter is canonical
  28. sed -i '' 's/### Indexer command line arguments/## OPTIONS/g' tmp.md
  29. # Remove all after specified string, including the string
  30. sed -i '' '/### Indexer configuration settings/,$d' tmp.md
  31. # Get mtime of the original file in the manual from where we generate the man page
  32. if [[ "$osType" == "Linux" ]]; then
  33. mtime=$(stat -c %y "$srcFile" | awk '{print $1}' | awk -F '-' '{print $3"/"$2"/"$1}')
  34. elif [[ "$osType" == "Darwin" ]]; then # For macOS
  35. mtime=$(stat -f "%Sm" -t "%d/%m/%Y" "$srcFile")
  36. else
  37. echo "Unsupported OS"
  38. exit 1
  39. fi
  40. # Prepare a header of the indexer man page
  41. cat << EOF > $destFile
  42. '\" t
  43. .\" Title: indexer
  44. .\" Author: [see the "Author" section]
  45. .\" Manual: Manticore Search
  46. .\" Source: Manticore Search
  47. .\" Language: English
  48. .\"
  49. .TH "INDEXER" "1" "$mtime" "Manticore Search" ""
  50. .SH "NAME"
  51. indexer \- Manticore Search Indexer Tool
  52. .SH "SYNOPSIS"
  53. sudo \-u manticore indexer ...
  54. EOF
  55. # Convert the temporary markdown file to man page
  56. md2man-roff tmp.md >> $destFile
  57. # Add a footer of the man page
  58. cat << EOF >> $destFile
  59. $authorAndCopyright
  60. .SH "SEE ALSO"
  61. .PP
  62. \fBsearchd\fR(1),
  63. \fBindextool\fR(1)
  64. .PP
  65. Manticore Search and its related programs are thoroughly documented
  66. in the \fIManticore Search reference manual\fR, which is accessible
  67. at https://manual.manticoresearch.com/
  68. EOF
  69. rm tmp.*
  70. # searchd
  71. srcFile="../manual/english/Starting_the_server/Manually.md"
  72. destFile="searchd.1"
  73. cp $srcFile tmp.md
  74. # Remove all HTML comments
  75. sed -i '' '/<!--/,/-->/d' tmp.md
  76. # Remove all markdown links
  77. sed -i '' -r 's/\[([^]]+)\]\([^)]+\)/\`\1\`/g' tmp.md
  78. # Remove all before specified string, but not the string itself, and change the string to the new one
  79. sed -i '' -n '/## searchd command line options/,$p' tmp.md
  80. sed -i '' '1s/## searchd command line options/## OPTIONS/' tmp.md
  81. # Capitalize section names
  82. sed -i '' 's/## Environment variables/## ENVIRONMENT VARIABLES/g' tmp.md
  83. sed -i '' 's/## Signals/## SIGNALS/g' tmp.md
  84. sed -i '' 's/## Plugin dir/## PLUGIN DIR/g' tmp.md
  85. # Prepare a header of the indexer man page
  86. cat << EOF > $destFile
  87. '\" t
  88. .\" Title: searchd
  89. .\" Author: [see the "Author" section]
  90. .\" Manual: Manticore Search
  91. .\" Source: Manticore Search
  92. .\" Language: English
  93. .\"
  94. .TH "SEARCHD" "1" "$mtime" "Manticore Search" ""
  95. .SH "NAME"
  96. searchd \- Manticore Search Server
  97. .SH "SYNOPSIS"
  98. .HP \w'\fBsearchd\fR\ 'u
  99. \fBsearchd\fR [\-\-config\ \fICONFIGFILE\fR] [OPTION ...]
  100. .HP \w'\fBsearchd\fR\ 'u
  101. \fBsearchd\fR \-\-stopwait [\-\-config\ \fICONFIGFILE\fR]
  102. EOF
  103. # Convert the temporary markdown file to man page
  104. md2man-roff tmp.md >> $destFile
  105. # Add a footer of the man page
  106. cat << EOF >> $destFile
  107. $authorAndCopyright
  108. .SH "SEE ALSO"
  109. .PP
  110. \fBindexer\fR(1),
  111. \fBindextool\fR(1)
  112. .PP
  113. Manticore Search and its related programs are thoroughly documented
  114. in the \fIManticore Search reference manual\fR, which is accessible
  115. at https://manual.manticoresearch.com/
  116. EOF
  117. rm tmp.*
  118. srcFile="../manual/english/Miscellaneous_tools.md"
  119. destFile="indextool.1"
  120. cp $srcFile tmp.md
  121. # Remove all HTML comments
  122. sed -i '' '/<!--/,/-->/d' tmp.md
  123. # Remove all markdown links
  124. sed -i '' -r 's/\[([^]]+)\]\([^)]+\)/\`\1\`/g' tmp.md
  125. # Remove all before specified string, but not the string itself, and change the string to the new one
  126. sed -i '' -n '/## indextool/,$p' tmp.md
  127. sed -i '' '1s/## indextool/## DESCRIPTION/' tmp.md
  128. # Replace the long section name to just OPTIONS as the latter is canonical
  129. sed -i '' 's/### Options/## OPTIONS/g' tmp.md
  130. # Remove all after specified string, including the string
  131. sed -i '' '/## spelldump/,$d' tmp.md
  132. # Get mtime of the original file in the manual from where we generate the man page
  133. if [[ "$osType" == "Linux" ]]; then
  134. mtime=$(stat -c %y "$srcFile" | awk '{print $1}' | awk -F '-' '{print $3"/"$2"/"$1}')
  135. elif [[ "$osType" == "Darwin" ]]; then # For macOS
  136. mtime=$(stat -f "%Sm" -t "%d/%m/%Y" "$srcFile")
  137. else
  138. echo "Unsupported OS"
  139. exit 1
  140. fi
  141. # Prepare a header of the indexer man page
  142. cat << EOF > $destFile
  143. '\" t
  144. .\" Title: indexer
  145. .\" Author: [see the "Author" section]
  146. .\" Manual: Manticore Search
  147. .\" Source: Manticore Search
  148. .\" Language: English
  149. .\"
  150. .TH "INDEXTOOL" "1" "$mtime" "Manticore Search" ""
  151. .SH "NAME"
  152. indextool
  153. .SH "SYNOPSIS"
  154. indextool <command> [options]
  155. EOF
  156. # Convert the temporary markdown file to man page
  157. md2man-roff tmp.md >> $destFile
  158. # Add a footer of the man page
  159. cat << EOF >> $destFile
  160. $authorAndCopyright
  161. .SH "SEE ALSO"
  162. .PP
  163. \fBsearchd\fR(1),
  164. \fBindexer\fR(1)
  165. .PP
  166. Manticore Search and its related programs are thoroughly documented
  167. in the \fIManticore Search reference manual\fR, which is accessible
  168. at https://manual.manticoresearch.com/
  169. EOF
  170. rm tmp.*