Files
dotfiles/scripts/config-sync
2025-10-23 22:08:33 +02:00

35 lines
865 B
Bash
Executable File

#!/bin/sh
path="$(dirname "$(readlink -f "$0")")"
backupDir="$HOME/.config/config-backup/$(date +%Y%m%d-%H%M%S)"
backupDirCreated=0
sources=""
if [ -z "$1" ]; then
sources=$(find "$path/../config/" -maxdepth 1 -not -path "$path/../config")
else
for arg in "$@"; do
src="$path/../config/$arg"
if [ ! -e "$src" ]; then
echo "Error: Config '$arg' does not exist." >&2
exit 1
fi
sources="$sources $path/../config/$arg"
done
fi
for src in $sources; do
name="$(basename "$src")"
dest="$HOME/.config/$name"
if [ -e "$dest" ] || [ -L "$dest" ]; then
[ "$backupDirCreated" -eq 0 ] && {
mkdir -pv "$backupDir"
backupDirCreated=1
}
mv -vf "$dest" "$backupDir/"
fi
ln -sv "$(realpath --relative-to="$HOME/.config" "$src")" "$dest"
done