-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·118 lines (102 loc) · 2.68 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·118 lines (102 loc) · 2.68 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# Idempotent dotfiles installer: symlinks the tracked dotfiles into $HOME.
# Safe to re-run. Pass --dry-run (or -n) to preview without changing anything.
set -eu
DOTFILES="$(cd "$(dirname "$0")" && pwd)"
BACKUP_DIR="$HOME/.dotfiles-backup/$(date +%Y%m%d-%H%M%S)"
OLD_DOTFILES="$HOME/Dropbox/wtsang/dotfiles"
DRY_RUN=0
if [ "${1:-}" = "--dry-run" ] || [ "${1:-}" = "-n" ]; then
DRY_RUN=1
fi
FILES="
.profile
.bash_profile
.bashrc
.zprofile
.zshrc
.inputrc
.editrc
.umich_aliases
.tmux.conf
.gitconfig
.gitignore_global
.gemrc
.ruby-version
.vimrc
.gvimrc
"
linked=0
skipped=0
backed_up=0
pruned=0
run() {
if [ "$DRY_RUN" -eq 1 ]; then
echo " would: $*"
else
"$@"
fi
}
# link_file <repo path> <home path>
link_file() {
src=$1
dst=$2
if [ -L "$dst" ] && [ "$(readlink "$dst")" = "$src" ]; then
skipped=$((skipped + 1))
return 0
fi
if [ -e "$dst" ] && [ ! -L "$dst" ]; then
echo "backing up: $dst -> $BACKUP_DIR/"
run mkdir -p "$BACKUP_DIR"
run mv "$dst" "$BACKUP_DIR/"
backed_up=$((backed_up + 1))
fi
echo "linking: $dst -> $src"
run ln -sfn "$src" "$dst"
linked=$((linked + 1))
}
# Remove top-level $HOME symlinks that point into this repo (or its old
# Dropbox location) but whose target no longer exists — leftovers from
# files this repo used to ship (.rvmrc, .screenrc, .bash, ...).
prune_dead_links() {
for link in "$HOME"/.[!.]* "$HOME"/*; do
[ -L "$link" ] || continue
target="$(readlink "$link")"
case "$target" in
"$DOTFILES"/*|"$OLD_DOTFILES"/*)
if [ ! -e "$link" ]; then
echo "pruning dead link: $link -> $target"
run rm "$link"
pruned=$((pruned + 1))
fi
;;
esac
done
}
for name in $FILES; do
link_file "$DOTFILES/$name" "$HOME/$name"
done
link_file "$DOTFILES/shell" "$HOME/.shell"
prune_dead_links
if [ ! -f "$DOTFILES/shell/secret-export.sh" ]; then
echo "note: shell/secret-export.sh is missing (machine-local secrets; create it by hand)"
fi
if [ ! -d "$HOME/.oh-my-zsh" ]; then
echo "bootstrapping oh-my-zsh"
run git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git "$HOME/.oh-my-zsh"
# zsh compaudit rejects group-writable completion dirs
run chmod -R g-w,o-w "$HOME/.oh-my-zsh"
fi
if [ ! -f "$HOME/.vim/autoload/plug.vim" ]; then
echo "bootstrapping vim-plug"
run curl -fLo "$HOME/.vim/autoload/plug.vim" --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
echo
echo "done: $linked linked, $skipped already correct, $backed_up backed up, $pruned pruned"
if [ "$backed_up" -gt 0 ]; then
echo "backups in: $BACKUP_DIR"
fi
if [ "$DRY_RUN" -eq 1 ]; then
echo "(dry run: nothing was changed)"
fi