4
0

genman 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. set -e
  3. # Set variables
  4. # in - input man page (something_foo.3.in)
  5. # out - output file (something_foo.3)
  6. # common - common ipc error file
  7. in="$1"
  8. out="$2"
  9. common="$3"
  10. # make sure to trap on error and ctrl+c
  11. # so we can cleanup our temporary files
  12. # and provide error back to Makefile
  13. cleanup() {
  14. rm -f "$out"-t "$out"
  15. }
  16. trap "cleanup" ABRT
  17. trap "cleanup" QUIT
  18. trap "cleanup" TERM
  19. trap "cleanup" INT
  20. trap "cleanup" ERR
  21. # Determine build date in man page format YYYY-MM-DD
  22. date="$(LC_ALL=C date "+%F")"
  23. # do the hack.. it looks ugly but it works fine
  24. # remove temporary file
  25. rm -f "$out"-t
  26. # insert the $common ipc error file in the man page
  27. if grep -q @COMMONIPCERRORS@ "$in"; then
  28. awk "{print}(\$1 ~ /@COMMONIPCERRORS@/){exit 0}" "$in" > "$out"-t
  29. cat "$common" >> "$out"-t
  30. awk -v p=0 "(\$1 ~ /@COMMONIPCERRORS@/){p = 1} {if(p==1)print}" "$in" >> "$out"-t
  31. else
  32. cp "$in" "$out"-t
  33. fi
  34. # substitute BUILDDATE with precalculated date
  35. # and remove COMMONIPCERRORS tag from above
  36. sed -i \
  37. -e 's#@BUILDDATE@#'$date'#g' \
  38. -e 's#@COMMONIPCERRORS@##g' \
  39. "$out"-t
  40. # move in place as requested
  41. mv "$out"-t "$out"