mkit.sh 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. if valid_targets | grep -qwx "^$1";
  82. then
  83. "$1"
  84. else
  85. {
  86. echo "usage: $(basename "$0") TARGET"
  87. echo
  88. echo "valid targets:"
  89. valid_targets | sed 's/^/ /'
  90. } >&2
  91. fi
  92. }
  93. valid_targets() {
  94. #
  95. # List valid routes
  96. #
  97. echo build
  98. echo build_manpages
  99. echo clean
  100. echo debstuff
  101. echo dist
  102. echo install
  103. echo release_x
  104. echo release_y
  105. echo release_z
  106. echo rpmstuff
  107. echo uninstall
  108. echo vbump_x
  109. echo vbump_y
  110. echo vbump_z
  111. }