From 9a297db034996ae1649c1bdad35f310bf4033988 Mon Sep 17 00:00:00 2001 From: pt Date: Sun, 3 May 2020 01:01:25 -0400 Subject: [PATCH] handle dot files that are already dymlinks --- setup.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/setup.sh b/setup.sh index 381fccf..00a819c 100755 --- a/setup.sh +++ b/setup.sh @@ -4,26 +4,29 @@ # setup folder pointers and target files dir=~/linux_user_setup -olddir=~/linux_user_setup_restore +backup=~/linux_user_setup_restore files=".bashrc .vimrc .tmux.conf .psqlrc" # create the resore directory if it doesn't already exist -if [ ! -d $olddir ] +if [ ! -d $backup ] then - mkdir $olddir + mkdir $backup fi # loop through each target file, move it and create a symlink to the replacements for file in $files do - #if the file is already a symlink then do nothing - if [ ! -L "$file"] + #if the file is not a symlink the just _move_ it, otherwise _copy_ the linked file + if [ ! -L $file ]; then - echo "moving $file to $olddir" - mv ~/$file $olddir + echo "moving $file to $backup" + mv ~/$file $backup echo "snapping $file to be a new symlink to version controlled file in $dir" ln -s $dir/$file ~/$file + else + # if the target file is a symlink, copy the linked file + cp $(readlink -f $file) $backup fi done