mk.sh 3.4KB

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