-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·104 lines (86 loc) · 2.47 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·104 lines (86 loc) · 2.47 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOTFILES_DIR="$SCRIPT_DIR"
backup_target() {
local target="$1"
if [[ -e "$target" || -L "$target" ]]; then
local backup="$target.bak"
if [[ -e "$backup" || -L "$backup" ]]; then
local suffix
suffix="$(date +%Y%m%d%H%M%S)"
backup="$target.bak.$suffix"
local i=1
while [[ -e "$backup" || -L "$backup" ]]; do
backup="$target.bak.$suffix.$i"
((i++))
done
fi
echo "Backing up $target to $backup"
mv "$target" "$backup"
fi
}
install_symlink() {
local source="$1"
local target="$2"
if [[ -L "$target" && "$(readlink "$target")" == "$source" ]]; then
echo "Already installed $target"
return
fi
backup_target "$target"
ln -s "$source" "$target"
}
install_file() {
local source="$1"
local target="$2"
mkdir -p "$(dirname "$target")"
if [[ -f "$target" ]] && cmp -s "$source" "$target"; then
echo "Already installed $target"
return
fi
backup_target "$target"
cp "$source" "$target"
}
install_gitconfig() {
local source="$1"
local target="$2"
if [[ -f "$target" ]] && git config --file "$target" --get-all include.path 2>/dev/null | grep -Fx -- "$source" >/dev/null; then
echo "Already installed $target"
return
fi
backup_target "$target"
{
echo "# Machine-local git config; tools may write here."
echo "[include]"
printf "\tpath = %s\n" "$source"
} > "$target"
}
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
if [[ "${DOTFILES_SKIP_OH_MY_ZSH:-0}" == "1" ]]; then
echo "Skipping Oh My Zsh install (DOTFILES_SKIP_OH_MY_ZSH=1)"
else
RUNZSH=no CHSH=no KEEP_ZSHRC=yes sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
fi
fi
install_file "$DOTFILES_DIR/.vscode.settings.json" "$HOME/Library/Application Support/Code/User/settings.json"
if [[ -d "$DOTFILES_DIR/dotfiles" ]]; then
for file in "$DOTFILES_DIR"/dotfiles/*; do
base="$(basename "$file")"
if [[ "$base" == "gitconfig" ]]; then
target="$HOME/.gitconfig"
echo "Installing $target..."
install_gitconfig "$file" "$target"
continue
elif [[ "$base" == Brewfile* ]]; then
target="$HOME/$base"
else
target="$HOME/.$base"
fi
echo "Installing $target..."
install_symlink "$file" "$target"
done
else
echo "Could not find dotfiles directory: $DOTFILES_DIR/dotfiles" >&2
exit 1
fi
"$DOTFILES_DIR/install/mac.sh"