From adc1f3ce611d813560b708bba17ad0516bbfda77 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Tue, 27 Dec 2022 22:02:48 -0500 Subject: [PATCH] Copy symlinks instead of contents --- install.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index f37dce3..2b7277b 100755 --- a/install.sh +++ b/install.sh @@ -3,16 +3,25 @@ root="root" all_files() { - find $root -type f,l + find $root -type f,l } for f in $(all_files) do - install_path="${f#"$root"}" - mkdir -p "$(dirname "$install_path")" - # ln -snf "$PWD/$f" "$install_path" - read -ra perm_options < <(stat -c '-m %a -g %g -o %u' "$PWD/$f") - install -C "${perm_options[@]}" "$PWD/$f" "$install_path" + install_path="${f#"$root"}" + mkdir -p "$(dirname "$install_path")" + + # Sometimes it is simpler to just link instead of copy + # ln -snf "$PWD/$f" "$install_path" + + # install -C only copies if destination has changed. + # However for symlinks, it always copies and it copies the *contents* and not the symlinks. + if [[ -L "$PWD/$f" ]]; then + cp -P "$PWD/$f" "$install_path" + else + read -ra perm_options < <(stat -c '-m %a -g %g -o %u' "$PWD/$f") + install -C "${perm_options[@]}" "$PWD/$f" "$install_path" + fi done # vim: set filetype=bash: