imapfilter convenience wrapper

deploy.sh 3.6KB

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