#!/usr/bin/bash

[[ -z "${XNHOME}" ]] && echo "Should be run from ncad-prep script" && exit 1;

src_path="/opt/nanosoft/ncad_26.0/user_x64/drive_c/ProgramData/Nanosoft/nanoCAD x64 26.0/NanoSPDS"
dst_path="${XNHOME}/drive_c/ProgramData/Nanosoft/nanoCAD x64 26.0/NanoSPDS"

sync_directories() {
    local src="$1"
    local dst="$2"

    if [[ ! -d "${dst}" ]]; then
        mkdir -p "${dst}"
    fi

    for src_item in "${src}"/*; do
        local dst_item
        dst_item="${dst}/$(basename "${src_item}")"

        if [[ -d "${src_item}" ]]; then
            sync_directories "${src_item}" "${dst_item}"
        elif [[ -f "${src_item}" ]]; then
            if [[ ! -e "${dst_item}" || "${src_item}" -nt "${dst_item}" ]]; then
                cp "${src_item}" "${dst_item}"
            fi
        fi
    done
}

sync_directories "${src_path}" "${dst_path}"
