-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathbootstrap.sh
executable file
·226 lines (194 loc) · 6.11 KB
/
bootstrap.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env bash
# shellcheck disable=SC2016
DOTFILES=$(dirname "$0")
info() {
printf "\033[00;34m%s\033[0m\n" "$@"
}
doUpdate() {
info "Updating"
git pull origin main
}
doGitConfig() {
info "Configuring Git"
# The .gitconfig will be overwritten; reconfigure it.
echo "Configuring global .gitignore"
git config --global core.excludesfile "$HOME/.gitignore_global"
# Use Araxis Merge as diff and merge tool when available.
if [ -d "/Applications/Araxis Merge.app/Contents/Utilities/" ]; then
echo "Configuring Araxis Merge"
git config --global diff.guitool araxis
git config --global merge.guitool araxis
git config --global mergetool.araxis.path /Applications/Araxis\ Merge.app/Contents/Utilities/compare
fi
# Use Sublime Merge as diff and merge tool when available.
if [ -d "/Applications/Sublime Merge.app/Contents/SharedSupport/bin/" ]; then
echo "Configuring Sublime Merge"
git config --global mergetool.smerge.cmd '/Applications/Sublime\ Merge.app/Contents/SharedSupport/bin/smerge mergetool "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"'
git config --global mergetool.smerge.trustExitCode true
git config --global merge.tool smerge
fi
delta=$(type -P "delta")
if [ -x "$delta" ]; then
echo "Configuring delta"
git config --global core.pager "delta"
git config --global interactive.diffFilter "delta --color-only"
fi
}
doToolConfig() {
info "Configuring Tools"
fish=$(type -P "fish")
if [ -x "$fish" ]; then
echo "Configuring fish theme"
"$fish" "$DOTFILES/.config/fish/solarized.fish"
fi
pinentry=$(which pinentry-mac)
if [ -x "$pinentry" ]; then
echo "Configuring pinentry-mac"
echo "pinentry-program $pinentry" >> "$HOME/.gnupg/gpg-agent.conf"
killall gpg-agent 2> /dev/null
fi
}
doSync() {
info "Syncing"
rsync \
--exclude ".git/" \
--exclude ".gitignore" \
--exclude "Preferences.sublime-settings" \
--exclude "README.md" \
--exclude "bootstrap.sh" \
--exclude "installers/" \
--exclude "os/" \
--exclude "scripts/" \
--exclude "sublime/" \
--exclude "tmux.terminfo" \
--filter=':- .gitignore' \
--no-perms \
-avh \
"$DOTFILES/" \
"$HOME"
# Touch .localrc so fish can source it.
touch "$HOME/.localrc"
# Copy Sublime configurations.
if [ -d "$HOME/Library/Application Support/Sublime Merge/" ]; then
cp -f "$DOTFILES/sublime/merge/Preferences.sublime-settings" \
"$HOME/Library/Application Support/Sublime Merge/Packages/User/Preferences.sublime-settings"
fi
if [ -d "$HOME/Library/Application Support/Sublime Text/" ]; then
cp -f "$DOTFILES/sublime/text/Preferences.sublime-settings" \
"$HOME/Library/Application Support/Sublime Text/Packages/User/Preferences.sublime-settings"
fi
}
doDirectories() {
mkdir -p "$HOME/vim/undo"
mkdir -p "$HOME/.ssh"
mkdir -p "$HOME/.gnupg"
}
doInstall() {
info "Installing (neo)vim plugins"
if command -v nvim &> /dev/null; then
nvim --headless "+Lazy! sync" +qa
if command -v pip3 &> /dev/null; then
pip3 install neovim
fi
if command -v npm &> /dev/null; then
npm install neovim
fi
else
curl -fLo "$HOME/.vim/autoload/plug.vim" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
vim +PlugInstall +PlugUpdate +qa!
fi
if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then
info "Installing tmux plugins"
git clone https://github.com/tmux-plugins/tpm "$HOME/.tmux/plugins/tpm"
else
info "Updating tmux plugins"
"$HOME/.tmux/plugins/tpm/bin/install_plugins"
"$HOME/.tmux/plugins/tpm/bin/update_plugins" all
fi
if command -v rustup &> /dev/null; then
info "Updating Rust"
rustup update
else
info "Installing Rust"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o /tmp/rustup-init.sh
chmod +x /tmp/rustup-init.sh
/tmp/rustup-init.sh -y
fi
if command -v brew &> /dev/null; then
info "Updating Homebrew"
brew update
brew upgrade
fi
}
doPermissions() {
info "Fixing Permissions "
chown -R "$(whoami)" "$HOME/.ssh/"
find "$HOME/.ssh" -type d -exec chmod 700 {} \;
find "$HOME/.ssh" -type f -name 'id_rsa*' -exec chmod 600 {} \;
find "$HOME/.ssh" -type f -name '*.pub' -exec chmod 644 {} \;
chown -R "$(whoami)" "$HOME/.gnupg/"
find "$HOME/.gnupg" -type f -exec chmod 600 {} \;
find "$HOME/.gnupg" -type d -exec chmod 700 {} \;
}
doOSConfig() {
info "Configuring OS"
if [ "$(uname)" == "Darwin" ]; then
echo "Configuring macOS"
"$DOTFILES/os/macos.sh"
elif [ "$(uname)" == "Linux" ]; then
echo "Configuring Linux"
"$DOTFILES/os/linux.sh"
fi
}
doAll() {
doUpdate
doSync
doGitConfig
doDirectories
doPermissions
doInstall
doOSConfig
}
doHelp() {
echo "Usage: $(basename "$0") [options]" >&2
echo
echo " -s, --sync Synchronizes dotfiles to home directory"
echo " -l, --link Create symbolic links"
echo " -i, --install Install (extra) software"
echo " -c, --config Configures your system"
echo " -a, --all Does all of the above"
echo
exit 1
}
if [ $# -eq 0 ]; then
doHelp
else
for i in "$@"
do
case $i in
-s|--sync)
doSync
doGitConfig
doToolConfig
doDirectories
doPermissions
shift
;;
-i|--install)
doInstall
shift
;;
-c|--config)
doOSConfig
shift
;;
-a|--all)
doAll
shift
;;
*)
doHelp
;;
esac
done
fi