-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·58 lines (47 loc) · 1.62 KB
/
install.sh
File metadata and controls
executable file
·58 lines (47 loc) · 1.62 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
set -euo pipefail
DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKUP_DIR="$HOME/.dotfiles_backup/$(date +%Y%m%d_%H%M%S)"
# Files to install: "repo-relative-source:absolute-target"
FILES=(
"dots/zshrc:$HOME/.zshrc"
"dots/vimrc:$HOME/.vimrc"
"dots/tmux.conf:$HOME/.tmux.conf"
"dots/gitconfig:$HOME/.gitconfig"
"dots/gitconfig.d/personal:$HOME/.gitconfig.d/personal"
"dots/gitconfig.d/synechron:$HOME/.gitconfig.d/synechron"
"dots/ssh/config:$HOME/.ssh/config"
)
backed_up=0
linked=0
skipped=0
for entry in "${FILES[@]}"; do
src="$DOTFILES_DIR/${entry%%:*}"
target="${entry##*:}"
# Already correctly linked
if [[ -L "$target" && "$(readlink "$target")" == "$src" ]]; then
echo "skip $target (already linked)"
((skipped++))
continue
fi
# Ensure parent directory exists
mkdir -p "$(dirname "$target")"
# Back up existing file or stale symlink
if [[ -e "$target" || -L "$target" ]]; then
mkdir -p "$BACKUP_DIR"
mv "$target" "$BACKUP_DIR/$(basename "$target")"
echo "backup $target -> $BACKUP_DIR/$(basename "$target")"
((backed_up++))
fi
ln -s "$src" "$target"
echo "link $target -> $src"
((linked++))
done
# SSH directory (required before config symlink is used)
mkdir -p "$HOME/.ssh" && chmod 700 "$HOME/.ssh"
mkdir -p "$HOME/.config/ssh_config.d"
# Vim runtime directories
mkdir -p "$HOME/.vim/undo" "$HOME/.vim/backup" "$HOME/.vim/swap"
echo ""
echo "Done: $linked linked, $backed_up backed up, $skipped already current."
[[ $backed_up -gt 0 ]] && echo "Backups saved to $BACKUP_DIR"