Просмотр исходного кода

screen setup: only create sym link if not already existing or if target paths differ

Fabian Peter Hammerle 9 лет назад
Родитель
Сommit
1108a39660
1 измененных файлов с 11 добавлено и 2 удалено
  1. 11 2
      setup

+ 11 - 2
setup

@@ -10,7 +10,16 @@ script_dir="$( dirname "${BASH_SOURCE[0]}" )"
 target_path="$( relpath "${script_dir}/${target_name}" "$(dirname "${link_path}")" )"
 
 if [ -e "${link_path}" ]; then
-    mv --backup=numbered "$link_path" "${link_path}.old"
+    # empty of link_path is not a link
+    current_target="$(readlink "${link_path}")"
+    if [ "$current_target" != "$target_path" ]; then
+        mv --backup=numbered "$link_path" "${link_path}.old"
+    fi
 fi
 
-ln -s "$target_path" "$link_path"
+if [ -e "${link_path}" ]; then
+    echo "sym link to '$target_path' already installed at '$link_path'"
+else
+    ln -s "$target_path" "$link_path"
+    echo "installed sym link to '$target_path' at '$link_path'"
+fi