123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #!/bin/bash
-
- _deploy_item() {
- #
- # Deploy item and make it look like wanted
- #
- # usage: _deploy_item src dst [mode]
- #
- # Both src and dst must be names of actual items[1],
- # whereas dst must not exist. On update, dst is
- # usually to be replaced but that is uninstall's
- # job!
- #
- # [1] Ie. src=foo and dst=/foo/bar does *always*
- # mean that foo will become 'bar'. This is
- # different than traditional `cp` behavior,
- # when this depends if 'bar' already exists
- # as a directory.
- #
- # If mode is omitted or empty, MKIT_DEFAULT_MODE is
- # used instead.
- #
- # Directories are copied recursively, and mode is
- # applied only to files.
- #
- local src=$1 # source path
- local dst=$2 # destination path
- local mode=${3:-$MKIT_DEFAULT_MODE} # mode
- local chmod_item # each file to chmod in directory
- if test -d "$src"; then
- _maybe mkdir -vp "$(dirname "$dst")"
- _maybe cp -Tvr "$src" "$dst"
- find "$dst" -type f \
- | while read -r chmod_item; do
- _maybe chmod "$mode" "$chmod_item"
- done
- else
- _maybe install -DTvm "$mode" "$src" "$dst"
- fi
- }
-
- _get_dst() {
- #
- # Find out target path for src file $2 of group $1
- #
- local grp=$1 # deploy group
- local src=$2 # each source
- local dst=$3 # alternative destination name
- test -n "$dst" || dst=${src##*/}
- echo "$(_get_root "$grp")/$dst"
- }
-
- _get_root() {
- #
- # Find out target root for group $1
- #
- local grp=$1 # deploy group
- local root # root for this group
- local destdir # value of DESTDIR
- root=$(ini 1value "roots:$grp")
- destdir=$(ini 1value ENV:DESTDIR)
- destdir=${destdir%/}
- case $destdir:$root in
- *:) die "missing in config.ini: roots:$grp" ;;
- :*) echo "$root" ;;
- *:*) echo "$destdir/$root" ;;
- esac
- }
-
- _maybe() {
- #
- # Call the deploy command $1 $@ unless in dry mode
- #
- debug "$@"
- local cmd="$1"; shift
- $MKIT_DRY && return
- case "$cmd" in
- cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
- install) command -p install "$@" ;;
- *) die "bad command called";;
- esac
- }
-
- install() {
- #
- # Install product
- #
- local group # each deploy group
- local mode # mode (group-specific)
- local src # each source path
- local dst # each (final absolute) destination path
- ini lskeys "files" \
- | sort \
- | uniq \
- | while read -r group; do
- mode=$(ini 1value "modes:$group")
- ini values "files:$group" \
- | while read -r src dst; do
- dst=$(_get_dst "$group" "$src" "$dst")
- _deploy_item "$src" "$dst" "$mode"
- done
- done
- test -f "$MKIT_LOCAL/autoclean" && clean
- true
- }
-
- uninstall() {
- #
- # Uninstall product
- #
- local group # each deploy group
- local src # each source path
- local dst # each (final absolute) destination path
- ini lskeys "files" \
- | sort \
- | uniq \
- | while read -r group; do
- ini values "files:$group" \
- | while read -r src dst; do
- dst=$(_get_dst "$group" "$src" "$dst")
- _maybe rm -vrf "$dst"
- done
- done
- }
|