summaryrefslogtreecommitdiff
path: root/src/lib/config.sync.source.sh
blob: 68bb75996e55dbf9b7f343ea32fd6d3534335da4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
resolve_sync_destinations() {
    local -n destinations_ref="$1"; shift
    local destinations_decl

    destinations_ref=()

    if ! destinations_decl=$(declare -p SYNC_DESTINATIONS 2>/dev/null); then
        return
    fi

    case "$destinations_decl" in
        declare\ -a*\ SYNC_DESTINATIONS=*)
            destinations_ref=("${SYNC_DESTINATIONS[@]}")
            ;;
        *)
            if [ -n "${SYNC_DESTINATIONS:-}" ]; then
                # shellcheck disable=SC2034
                read -r -a destinations_ref <<< "$SYNC_DESTINATIONS"
            fi
            ;;
    esac
}

sync_dist() {
    local destination
    local -a rsync_args=(-av)
    local -a sync_destinations=()

    resolve_sync_destinations sync_destinations

    if [ "$SYNC_DELETE" = yes ]; then
        rsync_args+=(--delete)
    fi

    for destination in "${sync_destinations[@]}"; do
        log_info "Syncing $DIST_DIR/ to $destination"
        rsync "${rsync_args[@]}" "$DIST_DIR/" "$destination"
    done
}