shell dot on steroids https://pagure.io/shellfu

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # ffoo - Fast Foo - a Bash Library
  3. # See LICENSE file for copyright and license details.
  4. tmp=$(mktemp)
  5. sed -e 's/ = /=/' < config.mk > $tmp
  6. . $tmp
  7. rm -f $tmp
  8. bindir=${DESTDIR}${PREFIX}/bin
  9. mandir=${DESTDIR}${MANPREFIX}
  10. docdir=${DESTDIR}${PREFIX}/share/doc/ffoo
  11. shrdir=${DESTDIR}${PREFIX}/share/ffoo
  12. list_of_bins() {
  13. echo bin/ffdoc
  14. echo bin/fff
  15. echo bin/ffoom
  16. }
  17. list_of_installed_bins() {
  18. list_of_bins | sed -e "s/bin/$(sed -e 's/\//\\\//g' <<<$bindir)/"
  19. }
  20. list_of_docs() {
  21. echo doc/fff.1.md
  22. echo doc/ffoo.3.md
  23. }
  24. list_of_shrs() {
  25. echo ffoo.sh
  26. echo include
  27. }
  28. clean() {
  29. test -f built.list && {
  30. cat built.list | xargs rm -f
  31. rm -f built.list
  32. } || :
  33. }
  34. dist() {
  35. local dirname=ffoo-${VERSION}
  36. mkdir -p $dirname
  37. cp -R bin \
  38. config.mk \
  39. doc \
  40. include \
  41. Makefile \
  42. ffoo.sh.in \
  43. README \
  44. LICENSE \
  45. setup \
  46. test \
  47. $dirname
  48. tar -cf $dirname.tar $dirname
  49. gzip $dirname.tar
  50. rm -rf $dirname
  51. echo $dirname.tar.gz >> built.list
  52. }
  53. install() {
  54. mkdir -p $bindir \
  55. $docdir \
  56. $shrdir
  57. list_of_bins | xargs cp -vrt $bindir
  58. list_of_docs | xargs cp -vrt $docdir
  59. list_of_shrs | xargs cp -vrt $shrdir
  60. list_of_installed_bins | xargs chmod 755
  61. test -f .autoclean && clean || :
  62. }
  63. manpages() {
  64. ronn -r doc/*.[1-9].md
  65. ls doc/*.[1-9] >> built.list
  66. }
  67. install_manpages() {
  68. cp -vr doc/*.1 $mandir/man1
  69. cp -vr doc/*.3 $mandir/man3
  70. test -f .autoclean && clean || :
  71. }
  72. ffoo() {
  73. local srcpath dstpath
  74. find -type f -name '*.in' \
  75. | while read srcpath;
  76. do
  77. dstpath=${srcpath%.in}
  78. perl -pe "s|__FFOO_DIR__|$shrdir|;
  79. s|__VERSION__|$VERSION|;" < $srcpath > $dstpath
  80. echo $dstpath >> built.list
  81. done
  82. }
  83. run_test() {
  84. pushd test
  85. find -maxdepth 1 -type f \! -name '*.in' | while read test;
  86. do
  87. chmod 0755 $test
  88. $test || exit $?
  89. done
  90. popd
  91. }
  92. uninstall() {
  93. list_of_installed_bins | xargs rm -f
  94. rm -rf $shrdir/ffoo
  95. rm -rf $docdir/ffoo
  96. rm -f $mandir/man1/fff.1
  97. rm -f $mandir/man3/ffoo.3
  98. }
  99. case $1 in
  100. clean|dist|install|install_manpages|manpages|ffoo|uninstall)
  101. $1
  102. ;;
  103. test)
  104. run_test
  105. ;;
  106. *)
  107. echo "usage: $(basename $0) clean|dist|install|ffoo|test|uninstall" >&2
  108. esac