-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·43 lines (33 loc) · 1.2 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
set -e
# Ensure stow is installed
command -v stow >/dev/null 2>&1 || { echo "stow command not found. Exiting."; exit 1; }
DOT_DIRECTORY="${HOME}/dotfiles"
# Function to handle conflicts
backup_and_remove_conflict() {
local file="$1"
local backup_dir="${HOME}/dotfiles_backup"
mkdir -p "$backup_dir"
if [ -f "$file" ] && [ ! -L "$file" ]; then
echo "Backing up conflicting file: $file"
mv "$file" "$backup_dir"
fi
}
# Iterate over directories and use stow to manage symlinks
for dir in "$DOT_DIRECTORY"/*/; do
dir_base=$(basename "$dir")
case "$dir_base" in
tests|deps|fonts) continue ;; # Skip these directories
*) ;;
esac
echo "~ Installing :: $dir_base"
# Check for potential conflicts before removing
stow --dir "$DOT_DIRECTORY" --target "$HOME" --no 2>/dev/null "$dir_base" | grep "^LINK:" | awk '{print $2}' | while read -r file; do
backup_and_remove_conflict "$HOME/$file"
done
# Remove previous symlinks
stow -D --dir "$DOT_DIRECTORY" --target "$HOME" "$dir_base" 2>/dev/null || true
# Install new symlinks
stow --dir "$DOT_DIRECTORY" --target "$HOME" "$dir_base"
echo "done: $dir_base"
done