mkit.sh 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/bash
  2. . "$MKIT_DIR/include/build.sh" || die "cannot import build.sh"
  3. . "$MKIT_DIR/include/deploy.sh" || die "cannot import deploy.sh"
  4. . "$MKIT_DIR/include/release.sh" || die "cannot import release.sh"
  5. . "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
  6. _valid_targets() {
  7. #
  8. # List valid routes
  9. #
  10. echo build
  11. echo build_manpages
  12. echo clean
  13. echo debstuff
  14. echo dist
  15. echo install
  16. echo release_x
  17. echo release_y
  18. echo release_z
  19. echo rpmstuff
  20. echo uninstall
  21. echo vbump_x
  22. echo vbump_y
  23. echo vbump_z
  24. }
  25. debug() {
  26. #
  27. # Print debug message
  28. #
  29. $MKIT_DEBUG || return 0
  30. echo "MKIT_DEBUG: ${FUNCNAME[1]}()" "$@" >&2
  31. }
  32. debug_var() {
  33. #
  34. # Print debug message
  35. #
  36. $MKIT_DEBUG || return 0
  37. local __mkit_debug_var_name__
  38. for __mkit_debug_var_name__ in "$@";
  39. do
  40. {
  41. echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
  42. echo -n " $__mkit_debug_var_name__"
  43. echo -n "='${!__mkit_debug_var_name__}'"
  44. echo
  45. } >&2
  46. done
  47. }
  48. die() {
  49. #
  50. # Exit with message and non-zero exit status
  51. #
  52. echo "fatal: $*" >&2
  53. exit 4
  54. }
  55. _compver() {
  56. #
  57. # True if version $1 matches our version
  58. #
  59. # If our x is 0, check first two fragments, otherwise check just
  60. # the x. Fragments must equal.
  61. #
  62. local their_ver our_x our_y their_x their_y
  63. their_ver="$1"
  64. their_x=${their_ver%%.*}
  65. their_y=${their_ver##$their_x.}
  66. their_y=${their_y%%.*}
  67. our_x=${MKIT_VERSION%%.*}
  68. our_y=${MKIT_VERSION##$our_x.}
  69. our_y=${our_y%%.*}
  70. debug_var MKIT_VERSION our_x our_y their_ver their_x their_y
  71. test "$their_x" -eq "$our_x" || return 1
  72. test "$our_x" -eq 0 && {
  73. test "$their_y" = "$our_y"
  74. return $?
  75. }
  76. return 0
  77. }
  78. _chkiniversion() {
  79. #
  80. # Check if ini version is supported
  81. #
  82. # Look for "#mkit version=0.0.0" or similar in first or last
  83. # 3 lines of the file; then check if the version is supported.
  84. #
  85. local ver_line
  86. local their_ver
  87. ver_line=$(
  88. {
  89. head -3 "$MKIT_INI"
  90. tac "$MKIT_INI" | tail -3
  91. } | grep -m 1 -E '^# *mkit +version *= *v?[0-9]+\.[0-9]+\.[0-9]+'
  92. )
  93. test -n "$ver_line" \
  94. || die "version mark ('#mkit version=x.y.z') not found in: $MKIT_INI"
  95. their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
  96. _compver "$their_ver" \
  97. || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
  98. }
  99. mkit_init() {
  100. #
  101. # Do basic initialization
  102. #
  103. # Check for ini file and some variables
  104. #
  105. $MKIT_DRY && MKIT_DEBUG=true
  106. MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
  107. test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
  108. _chkiniversion
  109. test -n "$(tr -d '[:space:]' <<<"$MKIT_LOCAL")" \
  110. || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
  111. }
  112. route() {
  113. #
  114. # Call correct function based on $1
  115. #
  116. if _valid_targets | grep -qwx "^$1";
  117. then
  118. "$1"
  119. else
  120. {
  121. echo "usage: $(basename "$0") TARGET"
  122. echo
  123. echo "valid targets:"
  124. _valid_targets | sed 's/^/ /'
  125. } >&2
  126. fi
  127. }
  128. warn() {
  129. #
  130. # Print warning message
  131. #
  132. echo "$@" >&2
  133. }