dots/restore

36 lines
765 B
Bash
Executable File

#!/bin/bash
declare -A to_copy to_rsync
repo="$(pwd)"
# files to copy
to_copy["${HOME}/.bashrc"]='shell/bashrc'
# directories to copy
to_rsync["${HOME}/.config/aliases"]='aliases'
# directories to copy
to_rsync["${HOME}/bin"]='bin'
for dst in "${to_copy[@]}"; do
src="${to_copy[$dst]}"
dir="$(dirname "$src")"
file="$(basename "$src")"
if [[ ! -d "${dir}" ]]; then
mkdir -p "${dir}"
fi
(cd "$dir" && rsync -a "$file" "${dir}"
if [[ $? != 0 ]]; then
printf 'Copying "%s" to "%s" had an error.\n' "$src" "$dst" >&2
fi
done
for dst in "${to_rsync[@]}"; do
src="${to_rsync[$dst]}"
if [[ ! -d "$dst" ]]; then
printf '"%s" does not exist. Can not copy.\n' "$src" >&2
else
(cd "$src" && rsync -a * "${repo}/${dst}/")
fi
done