cocktail.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #!/bin/bash
  2. VERBOSE=1
  3. DEBUG=0
  4. PROJET=MonProjet
  5. DOSSIER=MonDossier
  6. URL_BASE='https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt'
  7. URL_GARDE='https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt'
  8. die() {
  9. echo -e "$@" >&2
  10. exit 1
  11. }
  12. verbose() {
  13. if test "$VERBOSE" -ne 0;
  14. then
  15. echo "$@"
  16. fi
  17. }
  18. debug() {
  19. if test "$DEBUG" -ne 0;
  20. then
  21. echo "$@"
  22. fi
  23. }
  24. init_check() {
  25. if test -e $LOCK_FILE;
  26. then
  27. die "$FUNCNAME lock=$LOCK_FILE exists. Wait compilation or erase it"
  28. fi
  29. for tool in touch curl pandoc pdflatex
  30. do
  31. local tool_location=$(command -v $tool)
  32. if test "$tool_location";
  33. then
  34. verbose "init_check() $tool=$tool_location"
  35. else
  36. die "init_check() $tool unavailable"
  37. fi
  38. done
  39. }
  40. mirror_pad() {
  41. debug "$FUNCNAME ARGS:$@"
  42. if test $# -ne 2;
  43. then
  44. die 'usage: $FUNCNAME url filename'
  45. fi
  46. local url=$1
  47. local filename=$2
  48. verbose "$FUNCNAME url=$url filename=$filename"
  49. RESPONSE=$(curl --silent --show-error $url --output $filename 2>&1)
  50. RC=$?
  51. local errstr="$FUNCNAME url=$url filename$filename [RC:$RC] $RESPONSE"
  52. if test "$RC" -gt 0;
  53. then
  54. die "$errstr"
  55. fi
  56. verbose "$errstr"
  57. }
  58. pad2json() {
  59. debug "$FUNCNAME ARGS:$@"
  60. if test $# -ne 2;
  61. then
  62. die "usage: $FUNCNAME input_file output_file"
  63. fi
  64. local input=$1
  65. local output=$2
  66. verbose "$FUNCNAME input=$input output=$output"
  67. pandoc \
  68. -f markdown "$input" \
  69. -o "$output" -t json --self-contained
  70. }
  71. pad2docx() {
  72. debug "$FUNCNAME ARGS:$@"
  73. if test $# -ne 2;
  74. then
  75. die 'usage: $FUNCNAME input_file output_file'
  76. fi
  77. local input=$1
  78. local output=$2
  79. local refdoc=../../exegetesDoc/pandocincludes/exegetes.docx
  80. verbose "$FUNCNAME input=$input output=$output"
  81. if ! test -e "$refdoc";
  82. then
  83. die "$FUNCNAME refdoc=$refdoc unavailable"
  84. fi
  85. pandoc \
  86. -f markdown "$input" \
  87. -o "$output" -t docx --self-contained --smart \
  88. --reference-docx="$refdoc" \
  89. --filter pandoc-citeproc \
  90. --filter ../../exegetesDoc/filters/docx.zsh \
  91. --filter ../../exegetesDoc/filters/nettoyage.zsh \
  92. --filter ../../exegetesDoc/filters/nettoyage-etendu.zsh
  93. }
  94. pad2html() {
  95. debug "$FUNCNAME ARGS:$@"
  96. if test $# -ne 2;
  97. then
  98. die 'usage: $FUNCNAME input_file output_file'
  99. fi
  100. local input=$1
  101. local output=$2
  102. verbose "$FUNCNAME input=$input output=$output"
  103. pandoc \
  104. -f markdown "$input" \
  105. -o "$output" -t html --self-contained --smart \
  106. --filter pandoc-citeproc \
  107. --filter ../../exegetesDoc/filters/html.zsh \
  108. --filter ../../exegetesDoc/filters/nettoyage.zsh \
  109. --filter ../../exegetesDoc/filters/nettoyage-etendu.zsh
  110. }
  111. pad2markdown() {
  112. debug "$FUNCNAME ARGS:$@"
  113. if test $# -ne 2;
  114. then
  115. die 'usage: $FUNCNAME input_file output_file'
  116. fi
  117. local input=$1
  118. local output=$2
  119. verbose "$FUNCNAME input=$input output=$output"
  120. pandoc \
  121. -f markdown "$input" \
  122. -o "$output" -t markdown --wrap=none --self-contained --smart \
  123. --reference-location=block --reference-links \
  124. --filter pandoc-citeproc \
  125. --filter ../../exegetesDoc/filters/markdown.zsh \
  126. --filter ../../exegetesDoc/filters/nettoyage.zsh \
  127. --filter ../../exegetesDoc/filters/nettoyage-etendu.zsh
  128. }
  129. pad2tex() {
  130. debug "$FUNCNAME ARGS:$@"
  131. if test $# -ne 2;
  132. then
  133. die 'usage: $FUNCNAME input_file output_file'
  134. fi
  135. local input=$1
  136. local output=$2
  137. verbose "$FUNCNAME input=$input output=$output"
  138. pandoc \
  139. -f markdown "$input" \
  140. -o "$output" -t latex --self-contained \
  141. --template ../../exegetesDoc/pandocincludes/exegetes.latex \
  142. --filter pandoc-citeproc \
  143. --filter ../../exegetesDoc/filters/latex.zsh \
  144. --filter ../../exegetesDoc/filters/nettoyage.zsh \
  145. --filter pandoc-latex-environment \
  146. --filter ../../exegetesDoc/filters/paranumero.bash
  147. }
  148. tex2pdf() {
  149. debug "$FUNCNAME ARGS:$@"
  150. if test $# -ne 2;
  151. then
  152. die 'usage: $FUNCNAME input_file output_file'
  153. fi
  154. local input=$1
  155. local output=$2
  156. verbose "$FUNCNAME input=$input output=$output"
  157. mkdir pdftmp && \
  158. pdflatex -interaction=nonstopmode -output-directory=pdftmp "$input" >/dev/null
  159. pdflatex -interaction=nonstopmode -output-directory=pdftmp "$input" >/dev/null
  160. mv "pdftmp/$output" "./$output"
  161. # rm *.aux && rm *.out && rm *.log
  162. }
  163. lock_project() {
  164. verbose "$FUNCNAME $PROJET locked with $LOCK_FILE"
  165. touch $LOCK_FILE
  166. }
  167. release_project() {
  168. verbose "$FUNCNAME $PROJET released"
  169. rm -f $LOCK_FILE
  170. }
  171. #if test "$1";
  172. #then
  173. # URL_BASE=$1
  174. # tmp=${URL_BASE#*$} # remove prefix ending in "$"
  175. # tmp=${tmp%-Principal/export*} # remove suffix starting with
  176. # tmp=${tmp%-Garde/export*} # remove suffix starting with
  177. # PROJET=$tmp
  178. #fi
  179. LOCK_FILE="$PROJET.lock"
  180. echo "[$PROJET]"
  181. mkdir -p "$DOSSIER"
  182. cd "$DOSSIER" || die
  183. init_check
  184. lock_project
  185. mirror_pad "$URL_BASE" "$PROJET.txt"
  186. mirror_pad "$URL_GARDE" "garde.tex"
  187. # hack specifique Abro Tele2
  188. touch annexe-tableau.tex
  189. pad2json "$PROJET.txt" "$PROJET.json"
  190. pad2docx "$PROJET.txt" "$PROJET.docx"
  191. pad2html "$PROJET.txt" "$PROJET.html"
  192. pad2markdown "$PROJET.txt" "$PROJET.markdown.txt"
  193. pad2tex "$PROJET.txt" "$PROJET.tex"
  194. tex2pdf "$PROJET.tex" "$PROJET.pdf"
  195. release_project
  196. exit