just a dummy repo for a dummy package

mkit.sh 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #!/bin/bash
  2. # MKit - simple install helper
  3. # See LICENSE file for copyright and license details.
  4. die() {
  5. #
  6. # Exit with message and non-zero exit status
  7. #
  8. echo "fatal: $*" >&2
  9. exit 4
  10. }
  11. mkit_import() {
  12. #
  13. # Import mkit module $1.sh
  14. #
  15. # Check for module, source it and die with reasonable message if needed.
  16. #
  17. local modname=$1
  18. local modpath
  19. modpath="$MKIT_DIR/include/$modname.sh"
  20. test -f "$modpath" || die "no such module: $modpath"
  21. bash -n "$modpath" || die "bad syntax: $modpath"
  22. #shellcheck disable=SC1090
  23. . "$modpath" || die "failed to import: $modname"
  24. }
  25. mkit_import build
  26. mkit_import deploy
  27. mkit_import release
  28. mkit_import ini
  29. __valid_targets() {
  30. #
  31. # List valid routes
  32. #
  33. echo _mkit_builddata
  34. echo _mkit_data
  35. echo _mkit_inidata
  36. echo _mkit_metadata
  37. echo _mkit_show_builddata
  38. echo _mkit_show_metadata
  39. echo build
  40. echo build_pystuff
  41. echo clean
  42. echo debstuff
  43. echo dist
  44. echo install
  45. echo release
  46. echo release_x
  47. echo release_y
  48. echo release_z
  49. echo rpmstuff
  50. echo uninstall
  51. echo vbump
  52. echo vbump_x
  53. echo vbump_y
  54. echo vbump_z
  55. }
  56. debug() {
  57. #
  58. # Print debug message
  59. #
  60. $MKIT_DEBUG || return 0
  61. echo "MKIT_DEBUG: ${FUNCNAME[1]}()" "$@" >&2
  62. }
  63. debug_var() {
  64. #
  65. # Print debug message
  66. #
  67. $MKIT_DEBUG || return 0
  68. local __mkit_debug_var_name__ # variable name to debug
  69. local decl # declare string
  70. for __mkit_debug_var_name__ in "$@"; do
  71. {
  72. decl=$(declare -p "$__mkit_debug_var_name__")
  73. decl=${decl#declare ?? }
  74. echo "MKIT_DEBUG: ${FUNCNAME[1]}(): $decl"
  75. } >&2
  76. done
  77. }
  78. __compver() {
  79. #
  80. # True if version $1 matches our version
  81. #
  82. # We're following a particular convention described in SemVer
  83. # issue #363:
  84. #
  85. # https://github.com/semver/semver/issues/363
  86. #
  87. # In short: If our X is 0, check first two fragments, otherwise
  88. # check just the x. Fragments must equal.
  89. #
  90. local their_ver=$1 # their version
  91. local our_x # our X
  92. local our_y # our Y
  93. local our_z # our z
  94. local their_x # their X
  95. local their_y # their Y
  96. local their_z # their Z
  97. local diff_x='=' # difference in X: '=' for equal, 'o' for different
  98. local diff_y='=' # ^^ ...... in Y
  99. local diff_z='=' # ^^ ...... in Z
  100. read -r their_x their_y their_z <<<"$(__parse_ver_xyz "$their_ver")" || die
  101. read -r our_x our_y our_z <<<"$(__parse_ver_xyz "$MKIT_VERSION")" || die
  102. test "$their_x" -eq "$our_x" || diff_x=o
  103. test "$their_y" -eq "$our_y" || diff_y=o
  104. test "$their_z" -eq "$our_z" || diff_z=o
  105. debug_var MKIT_VERSION our_x our_y our_z their_ver their_x their_y their_z diff_x diff_y diff_z
  106. case $our_x.$our_y:$diff_x.$diff_y.$diff_z in
  107. *.*:=.=.=) return 0 ;;
  108. *.*:o.?.?) return 1 ;;
  109. 0.0:=.=.o) __compver_hint_async ;;
  110. 0.*:=.=.?) __compver_hint_async ;;
  111. 0.*:=.o.?) return 1 ;;
  112. *.*:=.=.o) __compver_hint_async ;;
  113. *) warn "MKit bug while comparing versions!"
  114. warn " .. MKit could not handle version difference; here's dump:"
  115. warn " ...... MKIT_VERSION=$MKIT_VERSION"
  116. warn " ...... their_ver=$their_ver"
  117. warn " ...... our_x=$our_x our_y=$our_y our_z=$our_z"
  118. warn " ...... their_x=$their_x their_y=$their_y their_z=$their_z"
  119. warn " ...... diff_x=$diff_x diff_y=$diff_y diff_z=$diff_z"
  120. return 1 ;;
  121. esac
  122. }
  123. __parse_ver_xyz() {
  124. #
  125. # Print space-separated X, Y and Z from version $1
  126. #
  127. local ver=$1
  128. local xyz
  129. xyz=$(grep -oE '^[0-9]+[.][0-9]+[.][0-9]+' <<<"$ver")
  130. test -n "$xyz" || {
  131. warn "could not parse version: $ver"
  132. }
  133. echo "${xyz//./ }"
  134. }
  135. __compver_hint_async() {
  136. #
  137. # Warn about the version being async
  138. #
  139. # Versions where later fragments are different are considered
  140. # compatible, but when MKit is updated, the best practice is
  141. # to consult the changelog and see if fixes or new features
  142. # enable optimizing or removing workarounds from the mkit.ini
  143. # file.
  144. #
  145. # For that reason we will inform the maintainer about this
  146. # fact.
  147. #
  148. # Because in typical MKit usage the MKit itself is embedded
  149. # in the same git repository as the file, it should be easy
  150. # to maintain the synchronicity.
  151. #
  152. warn "hint: mkit.ini version is out of sync: MKit: $MKIT_VERSION, mkit.ini: $their_ver"
  153. warn "hint: .. To hide this hint, consider updating mkit.ini based"
  154. warn "hint: .. on changes between these versions and update version"
  155. warn "hint: .. directive (\`#mkit version=..\`) to match MKit."
  156. }
  157. __chkiniversion() {
  158. #
  159. # Check if ini version is supported
  160. #
  161. # Look for "#mkit version=0.0.0" or similar in first or last
  162. # 3 lines of the file; then check if the version is supported.
  163. #
  164. local ver_line # line declaring version
  165. local their_ver # the declared version
  166. ver_line=$(
  167. {
  168. head -3 "$MKIT_INI"
  169. tail -3 "$MKIT_INI"
  170. } | grep -m 1 -E '^#mkit +version *= *v?[0-9]+\.[0-9]+\.[0-9]+'
  171. )
  172. test -n "$ver_line" \
  173. || die "version directive ('#mkit version=x.y.z') not found in: $MKIT_INI"
  174. their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
  175. __compver "$their_ver" \
  176. || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
  177. }
  178. mkit_init() {
  179. #
  180. # Do basic initialization
  181. #
  182. # Check for ini file and some variables
  183. #
  184. $MKIT_DRY && MKIT_DEBUG=true
  185. #shellcheck disable=SC2034
  186. MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
  187. test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
  188. __chkiniversion
  189. }
  190. route() {
  191. #
  192. # Call correct function based on $1
  193. #
  194. if __valid_targets | grep -qwx "^$1"; then
  195. "$1"
  196. else
  197. {
  198. echo "usage: $(basename "$0") TARGET"
  199. echo
  200. echo "valid targets:"
  201. __valid_targets | sed 's/^/ /'
  202. } >&2
  203. fi
  204. }
  205. warn() {
  206. #
  207. # Print warning message
  208. #
  209. echo "$@" >&2
  210. }