123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. # eecc - Eclectic Engineer's Control Center
  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. list_of_bins() {
  10. echo bin/eeabrt
  11. echo bin/eedmenu
  12. echo bin/eeget
  13. echo bin/eeiam
  14. echo bin/eeini
  15. echo bin/eeip
  16. echo bin/eeln
  17. echo bin/eepush
  18. echo bin/eerevert
  19. echo bin/eewatch
  20. echo bin/eewww
  21. }
  22. list_of_installed_bins() {
  23. list_of_bins | sed -e "s/bin/$(sed -e 's/\//\\\//g' <<<$bindir)/"
  24. }
  25. die() {
  26. for l in "$@"; do echo "$l" >&2; done
  27. exit 9
  28. }
  29. build1() {
  30. local srcpath dstpath
  31. srcpath=$1
  32. dstpath=${srcpath%.skel}
  33. perl -pe "
  34. s|__EECC_INI_PATH__|$EECC_INI_PATH_GLOBAL:\\\$HOME/$EECC_INI_PATH_USER|;
  35. s|__VERSION__|$(get_version)|;
  36. " < $srcpath > $dstpath
  37. echo $dstpath >> built.list
  38. }
  39. build() {
  40. local srcpath
  41. find -type f -name '*.skel' \
  42. | while read srcpath;
  43. do
  44. build1 "$srcpath"
  45. done
  46. }
  47. clean() {
  48. test -f built.list && {
  49. cat built.list | xargs rm -f
  50. rm -f built.list
  51. } || :
  52. }
  53. dist() {
  54. local version=$(get_version)
  55. local dirname=eecc-$version
  56. mkdir -p $dirname
  57. cp -R bin \
  58. config.mk \
  59. Makefile \
  60. README \
  61. LICENSE \
  62. setup \
  63. utils \
  64. $dirname
  65. sed -ie "s/^VERSION = .*/VERSION = $version/" $dirname/config.mk
  66. tar -cf $dirname.tar $dirname
  67. gzip $dirname.tar
  68. rm -rf $dirname
  69. }
  70. install() {
  71. mkdir -vp $bindir
  72. list_of_bins | xargs cp -vrt $bindir
  73. list_of_installed_bins | xargs chmod -v 755
  74. test -f .autoclean && clean || :
  75. }
  76. get_version() {
  77. local version=$VERSION
  78. local stage=$STAGE
  79. if git rev-parse HEAD >&/dev/null;
  80. then # we are in git repo... so we can get smart
  81. local lasttag=$(git tag | grep ^v | tail -n1)
  82. if ! git describe --tags --exact-match HEAD >&/dev/null;
  83. then # we are not at later commit than the last tag
  84. local sha=g$(git describe --always HEAD)
  85. fi
  86. if test "$(git diff --shortstat 2>/dev/null)" != "";
  87. then # thr tree is "dirty", i.e. has been edited
  88. local dirty=dirty
  89. fi
  90. version=${lasttag:1}
  91. case $stage:$sha:$dirty in
  92. ::) suffix="" ;;
  93. ::dirty) suffix="+$dirty" ;;
  94. :g*:) suffix="+$sha" ;;
  95. :g*:dirty) suffix="+$sha.dirty" ;;
  96. *::) suffix="-$stage" ;;
  97. *::dirty) suffix="-$stage+$dirty" ;;
  98. *:g*:) suffix="-$stage+$sha" ;;
  99. *:g*:dirty) suffix="-$stage+$sha.$dirty" ;;
  100. esac
  101. version=$version$suffix
  102. fi
  103. echo $version
  104. }
  105. run_test() {
  106. pushd test
  107. find -maxdepth 1 -type f \! -name '*.skel' | while read test;
  108. do
  109. chmod 0755 $test
  110. $test || exit $?
  111. done
  112. popd
  113. }
  114. uninstall() {
  115. list_of_installed_bins | xargs rm -vf
  116. }
  117. case $1 in
  118. build|clean|dist|install|install_manpages|manpages|uninstall)
  119. $1
  120. ;;
  121. test)
  122. run_test
  123. ;;
  124. *)
  125. echo "usage: $(basename $0) build|clean|dist|install|test|uninstall" >&2
  126. esac