summaryrefslogtreecommitdiff
path: root/src/lib/config.sync.source.sh
blob: 1707fe6b61332ff4dd04e9350702ff39959116ae (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
resolve_sync_destinations() {
    # destinations_ref is a nameref output filled by resolve_config_array.
    # shellcheck disable=SC2034
    local -n destinations_ref="$1"; shift

    # Parse SYNC_DESTINATIONS (array or scalar) via the shared config-array
    # helper. Unlike TAR_OPTS there is no default: an unset or empty value
    # simply yields an empty destinations array for callers to validate.
    resolve_config_array SYNC_DESTINATIONS destinations_ref
}

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
}