deploy.sh 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. check_env() {
  3. #
  4. # Check that environment variables have been set properly
  5. #
  6. PREFIX="$(readlink -m "$PREFIX")"
  7. test -d "$PREFIX" || die "PREFIX points to non-existent directory: $PREFIX"
  8. }
  9. deploy_item() {
  10. #
  11. # Deploy item and make it look like wanted
  12. #
  13. # usage: deploy_item src dst [mode]
  14. #
  15. # Both src and dst must be names of actual items[1],
  16. # whereas dst must not exist. On update, dst is
  17. # usually to be replaced but that is uninstall's
  18. # job!
  19. #
  20. # [1] Ie. src=foo and dst=/foo/bar does *always*
  21. # mean that foo will become 'bar'. This is
  22. # different than traditional `cp` behavior,
  23. # when this depends if 'bar' already exists
  24. # as a directory.
  25. #
  26. # If mode is omitted or empty, MKIT_DEFAULT_MODE is
  27. # used instead.
  28. #
  29. # Directories are copied recursively, and mode is
  30. # applied only to files.
  31. #
  32. local src="$1"
  33. local dst="$2"
  34. local mode="${3:-$MKIT_DEFAULT_MODE}"
  35. if test -d "$src";
  36. then
  37. cp -Tvr "$src" "$dst"
  38. find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
  39. else
  40. command -p install -DTvm "$mode" "$src" "$dst"
  41. fi
  42. }
  43. get_dst() {
  44. #
  45. # Find out target path for src file $2 of group $1
  46. #
  47. local grp=$1
  48. local src=$2
  49. echo "$(get_root "$grp")/$(ini 1value "files:$grp:$src")"
  50. }
  51. get_root() {
  52. #
  53. # Find out target rooot for group $1
  54. #
  55. local grp="$1"
  56. local root=$(ini 1value "roots:$grp")
  57. test -n "$root" || die "missing in config.ini: roots:$grp"
  58. echo "$root"
  59. }
  60. install() {
  61. #
  62. # Install product
  63. #
  64. check_env
  65. local dst group mode src
  66. ini values "lists:group" \
  67. | while read group;
  68. do
  69. mode=$(ini 1value "modes:$group")
  70. ini lskeys "files:$group" \
  71. | while read src;
  72. do
  73. dst=$(get_dst "$group" "$src")
  74. deploy_item "$src" "$dst" "$mode"
  75. done
  76. done
  77. test -f "$MKIT_LOCAL/autoclean" && clean
  78. true
  79. }
  80. uninstall() {
  81. #
  82. # Uninstall product
  83. #
  84. check_env
  85. local dst group src
  86. ini values "lists:group" \
  87. | while read group;
  88. do
  89. ini lskeys "files:$group" \
  90. | while read src;
  91. do
  92. dst=$(get_dst "$group" "$src")
  93. rm -vrf "$dst"
  94. done
  95. done
  96. }