mk.sh 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. case $dstpath in
  36. *.md) cat $srcpath \
  37. | expand_includes \
  38. | expand_variables \
  39. > $dstpath ;;
  40. *) cat $srcpath \
  41. | expand_variables \
  42. > $dstpath ;;
  43. esac
  44. echo $dstpath >> built.list
  45. }
  46. build() {
  47. local srcpath
  48. find -type f -name '*.skel' \
  49. | while read srcpath;
  50. do
  51. build1 "$srcpath"
  52. done
  53. }
  54. clean() {
  55. test -f built.list && {
  56. cat built.list | xargs rm -f
  57. rm -f built.list
  58. } || :
  59. }
  60. dist() {
  61. local version=$(get_version)
  62. local dirname=saturnin-$version
  63. mkdir -p $dirname
  64. cp -R bin \
  65. config.mk \
  66. Makefile \
  67. README \
  68. LICENSE \
  69. setup \
  70. utils \
  71. $dirname
  72. sed -ie "s/^VERSION = .*/VERSION = $version/" $dirname/config.mk
  73. tar -cf $dirname.tar $dirname
  74. gzip $dirname.tar
  75. rm -rf $dirname
  76. }
  77. expand_includes() {
  78. #
  79. # Expand include directives
  80. #
  81. # Expand e.g. `<!-- include4: foo.sh -->` to include code of foo.sh
  82. #
  83. perl -we '
  84. use strict;
  85. my $text;
  86. while (<>) {
  87. chomp;
  88. if (m/<!-- include4: (\S+) -->/) {
  89. open my $fh, $1 or warn "cannot find: $1";
  90. my $text = do { local($/); <$fh> };
  91. close $fh;
  92. $text =~ s/^(.)/ $1/gm;
  93. chomp $text;
  94. print "$text\n";
  95. } else {
  96. print "$_\n";
  97. }
  98. }
  99. '
  100. }
  101. expand_variables() {
  102. #
  103. # Expand variable values
  104. #
  105. perl -pe "
  106. s|__SATURNIN_INI_PATH__|$SATURNIN_INI_PATH_GLOBAL:\\\$HOME/$SATURNIN_INI_PATH_USER|;
  107. s|__VERSION__|$(get_version)|;
  108. "
  109. }
  110. install() {
  111. mkdir -vp $bindir
  112. list_of_bins | xargs cp -vrt $bindir
  113. list_of_installed_bins | xargs chmod -v 755
  114. test -f .autoclean && clean || :
  115. }
  116. get_version() {
  117. local version=$VERSION
  118. local stage=$STAGE
  119. if git rev-parse HEAD >&/dev/null;
  120. then # we are in git repo... so we can get smart
  121. local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
  122. if ! git describe --tags --exact-match HEAD >&/dev/null;
  123. then # we are not at later commit than the last tag
  124. local sha=g$(git describe --always HEAD)
  125. fi
  126. if test "$(git diff --shortstat 2>/dev/null)" != "";
  127. then # thr tree is "dirty", i.e. has been edited
  128. local dirty=dirty
  129. fi
  130. version=${lasttag:1}
  131. local suffix=""
  132. case $stage:$sha:$dirty in
  133. ::) suffix="" ;;
  134. ::dirty) suffix="+$dirty" ;;
  135. :g*:) suffix="+$sha" ;;
  136. :g*:dirty) suffix="+$sha.dirty" ;;
  137. *::) suffix="-$stage" ;;
  138. *::dirty) suffix="-$stage+$dirty" ;;
  139. *:g*:) suffix="-$stage+$sha" ;;
  140. *:g*:dirty) suffix="-$stage+$sha.$dirty" ;;
  141. esac
  142. version=$version$suffix
  143. fi
  144. echo $version
  145. }
  146. uninstall() {
  147. list_of_installed_bins | xargs rm -vf
  148. }
  149. case $1 in
  150. build|clean|dist|install|install_manpages|manpages|uninstall)
  151. $1
  152. ;;
  153. *)
  154. echo "usage: $(basename $0) build|clean|dist|install|uninstall" >&2
  155. esac