imapfilter convenience wrapper

deploy.sh 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. # MKit - simple install helper
  3. # See LICENSE file for copyright and license details.
  4. mkit_import ini
  5. mkit_import build
  6. __deploy__item() {
  7. #
  8. # Deploy item and make it look like wanted
  9. #
  10. # usage: __deploy__item src dst [mode]
  11. #
  12. # Both src and dst must be names of actual items[1],
  13. # whereas dst must not exist. On update, dst is
  14. # usually to be replaced but that is uninstall's
  15. # job!
  16. #
  17. # [1] Ie. src=foo and dst=/foo/bar does *always*
  18. # mean that foo will become 'bar'. This is
  19. # different than traditional `cp` behavior,
  20. # when this depends if 'bar' already exists
  21. # as a directory.
  22. #
  23. # If mode is omitted or empty, MKIT_DEFAULT_MODE is
  24. # used instead.
  25. #
  26. # Directories are copied recursively, and mode is
  27. # applied only to files.
  28. #
  29. local src=$1 # source path
  30. local dst=$2 # destination path
  31. local mode=${3:-$MKIT_DEFAULT_MODE} # mode
  32. local item # each in directory
  33. if test -d "$src"; then
  34. find "$src" -type f \
  35. | while read -r item; do
  36. [[ $item =~ .skel$ ]] \
  37. && grep -qe "${item%.skel}" "$MKIT_LOCAL/built.lst" \
  38. && continue
  39. __deploy__item "$item" "$dst${item#"$src"}" "$mode"
  40. done
  41. else
  42. test "$mode" == "SRC" && mode=$(stat -c "%a" "$src")
  43. __deploy__maybe install -DTvm "$mode" "$src" "$dst"
  44. fi
  45. }
  46. __deploy__dst() {
  47. #
  48. # Find out target path for src file $2 of group $1
  49. #
  50. local grp=$1 # deploy group
  51. local src=$2 # each source
  52. local dst=$3 # alternative destination name
  53. test -n "$dst" || dst=${src##*/}
  54. echo "$(__deploy__root "$grp")/$dst"
  55. }
  56. __deploy__root() {
  57. #
  58. # Find out target root for group $1
  59. #
  60. local grp=$1 # deploy group
  61. local root # root for this group
  62. local destdir # value of DESTDIR
  63. root=$(ini 1value "roots:$grp")
  64. destdir=$(ini 1value ENV:DESTDIR)
  65. destdir=${destdir%/}
  66. case $destdir:$root in
  67. *:) die "missing in config.ini: roots:$grp" ;;
  68. :*) echo "$root" ;;
  69. *:*) echo "$destdir/$root" ;;
  70. esac
  71. }
  72. __deploy__maybe() {
  73. #
  74. # Call the deploy command $1 $@ unless in dry mode
  75. #
  76. debug "$@"
  77. local cmd="$1"; shift
  78. $MKIT_DRY && return
  79. case "$cmd" in
  80. cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
  81. install) command -p install "$@" ;;
  82. *) die "bad command called";;
  83. esac
  84. }
  85. install() {
  86. #
  87. # Install product
  88. #
  89. local group # each deploy group
  90. local mode # mode (group-specific)
  91. local src # each source path
  92. local dst # each (final absolute) destination path
  93. ini lskeys "files" \
  94. | sort \
  95. | uniq \
  96. | while read -r group; do
  97. mode=$(ini 1value "modes:$group")
  98. ini values "files:$group" \
  99. | while read -r src dst; do
  100. dst=$(__deploy__dst "$group" "$src" "$dst")
  101. __deploy__item "$src" "$dst" "$mode"
  102. done
  103. done
  104. test -f "$MKIT_LOCAL/autoclean" && clean
  105. true
  106. }
  107. uninstall() {
  108. #
  109. # Uninstall product
  110. #
  111. local group # each deploy group
  112. local src # each source path
  113. local dst # each (final absolute) destination path
  114. ini lskeys "files" \
  115. | sort \
  116. | uniq \
  117. | while read -r group; do
  118. ini values "files:$group" \
  119. | while read -r src dst; do
  120. dst=$(__deploy__dst "$group" "$src" "$dst")
  121. __deploy__maybe rm -vrf "$dst"
  122. done
  123. done
  124. }