mkit.sh 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. debug() {
  7. #
  8. # Print debug message
  9. #
  10. $MKIT_DEBUG || return 0
  11. echo "MKIT_DEBUG: ${FUNCNAME[1]}()" "$@" >&2
  12. }
  13. debug_var() {
  14. #
  15. # Print debug message
  16. #
  17. $MKIT_DEBUG || return 0
  18. local __mkit_debug_var_name__
  19. for __mkit_debug_var_name__ in "$@";
  20. do
  21. {
  22. echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
  23. echo -n " $__mkit_debug_var_name__"
  24. echo -n "='${!__mkit_debug_var_name__}'"
  25. echo
  26. } >&2
  27. done
  28. }
  29. MKIT_INI=${MKIT_INI:-mkit.ini}
  30. MKIT_INI_EXPAND=2
  31. MKIT_PROJ_NAME=$(ini 1value "project:name")
  32. MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
  33. MKIT_DEFAULT_MODE="644"
  34. mkit_init() {
  35. #
  36. # Do basic initialization
  37. #
  38. # Check for ini file and some variables
  39. #
  40. test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
  41. test -n "$(tr -d '[:space:]' <<<"$MKIT_LOCAL")" \
  42. || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
  43. }
  44. die() {
  45. #
  46. # Exit with message and non-zero exit status
  47. #
  48. echo "fatal: $*" >&2
  49. exit 4
  50. }
  51. warn() {
  52. #
  53. # Print warning message
  54. #
  55. echo "$@" >&2
  56. }
  57. update_version() {
  58. #
  59. # Change project.version in mkit.ini at path $2 to version $1
  60. #
  61. local version="$1"
  62. local inifile="$2"
  63. local tmp=$(mktemp -t mkit.update_version.XXXXXXXX)
  64. <"$inifile" perl -e '
  65. my $hit = 0;
  66. my $done = 0;
  67. foreach (<STDIN>) {
  68. if ($done) { print; next; }
  69. elsif (m/\[project\]/) { $hit++; print; next; }
  70. elsif (m/\[/) { $hit = 0; print; next; }
  71. elsif ($hit) { s/\bversion\b *=.*/version = $ARGV[0]/ and $done++; print; }
  72. else { print; next; }
  73. }
  74. ' "$version" >"$tmp" || die "failed to update version in mkit.ini"
  75. mv "$tmp" "$inifile"
  76. }
  77. route() {
  78. #
  79. # Call correct function based on $1
  80. #
  81. case $1 in
  82. build|build_manpages|clean|dist|rpmstuff|install|release_?|uninstall|vbump_?)
  83. $1
  84. ;;
  85. *)
  86. echo "usage: $(basename "$0") build|clean|dist|rpmstuff|install|uninstall" >&2
  87. esac
  88. }