123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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__ # variable name to debug
  38. for __mkit_debug_var_name__ in "$@"; do
  39. {
  40. echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
  41. echo -n " $__mkit_debug_var_name__"
  42. echo -n "='${!__mkit_debug_var_name__}'"
  43. echo
  44. } >&2
  45. done
  46. }
  47. die() {
  48. #
  49. # Exit with message and non-zero exit status
  50. #
  51. echo "fatal: $*" >&2
  52. exit 4
  53. }
  54. _compver() {
  55. #
  56. # True if version $1 matches our version
  57. #
  58. # If our x is 0, check first two fragments, otherwise check just
  59. # the x. Fragments must equal.
  60. #
  61. local their_ver=$1 # their version
  62. local our_x # our X
  63. local our_y # our Y
  64. local their_x # their X
  65. local their_y # their Y
  66. their_x=${their_ver%%.*}
  67. their_y=${their_ver##$their_x.}
  68. their_y=${their_y%%.*}
  69. our_x=${MKIT_VERSION%%.*}
  70. our_y=${MKIT_VERSION##$our_x.}
  71. our_y=${our_y%%.*}
  72. debug_var MKIT_VERSION our_x our_y their_ver their_x their_y
  73. test "$their_x" -eq "$our_x" || return 1
  74. test "$our_x" -eq 0 && {
  75. test "$their_y" = "$our_y"
  76. return $?
  77. }
  78. return 0
  79. }
  80. _chkiniversion() {
  81. #
  82. # Check if ini version is supported
  83. #
  84. # Look for "#mkit version=0.0.0" or similar in first or last
  85. # 3 lines of the file; then check if the version is supported.
  86. #
  87. local ver_line # line declaring version
  88. local their_ver # the declared version
  89. ver_line=$(
  90. {
  91. head -3 "$MKIT_INI"
  92. tac "$MKIT_INI" | tail -3
  93. } | grep -m 1 -E '^# *mkit +version *= *v?[0-9]+\.[0-9]+\.[0-9]+'
  94. )
  95. test -n "$ver_line" \
  96. || die "version mark ('#mkit version=x.y.z') not found in: $MKIT_INI"
  97. their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
  98. _compver "$their_ver" \
  99. || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
  100. }
  101. mkit_init() {
  102. #
  103. # Do basic initialization
  104. #
  105. # Check for ini file and some variables
  106. #
  107. $MKIT_DRY && MKIT_DEBUG=true
  108. MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
  109. test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
  110. _chkiniversion
  111. test -n "$(tr -d '[:space:]' <<<"$MKIT_LOCAL")" \
  112. || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
  113. }
  114. route() {
  115. #
  116. # Call correct function based on $1
  117. #
  118. if _valid_targets | grep -qwx "^$1"; then
  119. "$1"
  120. else
  121. {
  122. echo "usage: $(basename "$0") TARGET"
  123. echo
  124. echo "valid targets:"
  125. _valid_targets | sed 's/^/ /'
  126. } >&2
  127. fi
  128. }
  129. warn() {
  130. #
  131. # Print warning message
  132. #
  133. echo "$@" >&2
  134. }