From 830cdc5244ddf1097109c417c4a9d5627dce463b Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 3 Feb 2014 13:03:05 +0100 Subject: [PATCH] sync: add support for symlinks Signed-off-by: Alejandro Mery --- sync2.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sync2.sh b/sync2.sh index 09627c3..1bd3a8e 100755 --- a/sync2.sh +++ b/sync2.sh @@ -5,13 +5,13 @@ err() { echo "E: $$: $*" >&2; } FILES="$(pwd -P)" for x; do - if [ -L "$x" ]; then - err "$x: symlinks not supported" - elif [ -d "$x" ]; then + if [ -d "$x" ]; then true # skip dirs elif [ -L "$HOME/$x" ]; then d0="$(readlink "$HOME/$x")" d1="$(echo "$FILES/$x" | sed -e 's,/\./,/,g')" + d1="$(readlink -f "$d1")" + if [ "$d0" != "$d1" ]; then err "$x: relinking, was [$d0]" ln -snf "$d1" "$HOME/$x" @@ -26,9 +26,11 @@ for x; do d="$(echo "$FILES/$x" | sed -e 's,/\./,/,g')" if [ -e "$HOME/$x" ]; then info "$x: importing changes and linking" + rm "$d" cp -a "$HOME/$x" "$d" else info "$x: linking" + d="$(readlink -f "$d")" fi ln -snf "$d" "$HOME/$x" fi