forked from nickjj/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·312 lines (226 loc) · 10.6 KB
/
install
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/bin/env bash
set -e
skip_system_packages="${1}"
os_type="$(uname -s)"
apt_packages="curl git iproute2 python3-pip ripgrep tmux vim-gtk zsh"
apt_packages_optional="gnupg htop jq pass pwgen rsync shellcheck unzip"
brew_packages="diffutils git python ripgrep tmux vim zsh"
brew_packages_optional="gnupg htop jq pass pwgen rsync shellcheck"
install_asdf_version="v0.8.1"
install_node_version="14.17.3"
###############################################################################
# Detect OS and distro type
###############################################################################
function no_system_packages() {
cat << EOF
System package installation isn't supported with your OS / distro.
Please install any dependent packages on your own. You can view the list at:
https://github.com/nickjj/dotfiles/blob/master/install
Then re-run the script and explicitly skip installing system packages:
bash <(curl -sS https://raw.githubusercontent.com/nickjj/dotfiles/master/install) --skip-system-packages
EOF
exit 1
}
case "${os_type}" in
Linux*)
os_type="Linux"
if [ ! -f "/etc/debian_version" ]; then
[ -z "${skip_system_packages}" ] && no_system_packages
fi
;;
Darwin*) os_type="macOS";;
*)
os_type="Other"
[ -z "${skip_system_packages}" ] && no_system_packages
;;
esac
###############################################################################
# Install packages using your OS' package manager
###############################################################################
function apt_install_packages {
# shellcheck disable=SC2086
sudo apt-get update && sudo apt-get install -y ${apt_packages} ${apt_packages_optional}
}
function brew_install_self {
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
function brew_install_packages {
[ -x "$(command -v brew > /dev/null 2>&1)" ] && brew_install_self
# shellcheck disable=SC2086
brew install ${brew_packages} ${brew_packages_optional}
}
function display_packages {
if [ "${os_type}" == "Linux" ]; then
echo "${apt_packages} ${apt_packages_optional}"
else
echo "${brew_packages} ${brew_packages_optional}"
fi
}
if [ -z "${skip_system_packages}" ]; then
cat << EOF
If you choose yes, all of the system packages below will be installed:
$(display_packages)
If you choose no, the above packages will not be installed and this script
will exit. This gives you a chance to edit the list of packages if you don't
agree with any of the decisions.
The packages listed after zsh are technically optional but are quite useful.
Keep in mind if you don't install pwgen you won't be able to generate random
passwords using a custom alias that's included in these dotfiles.
EOF
while true; do
read -rp "Do you want to install the above packages? (y/n) " yn
case "${yn}" in
[Yy]*)
if [ "${os_type}" == "Linux" ]; then
apt_install_packages
else
brew_install_packages
fi
break;;
[Nn]*) exit 0;;
*) echo "Please answer y or n";;
esac
done
else
echo "System package installation was skipped!"
fi
###############################################################################
# Clone dotfiles
###############################################################################
read -rep $'\nWhere do you want to clone these dotfiles to [~/dotfiles]? ' clone_path
clone_path="${clone_path:-"${HOME}/dotfiles"}"
# Ensure path doesn't exist.
while [ -e "${clone_path}" ]; do
read -rep $'\nPath exists, try again? (y) ' y
case "${y}" in
[Yy]*)
break;;
*) echo "Please answer y or CTRL+c the script to abort everything";;
esac
done
echo
# This is used to locally develop the install script.
if [ "${DEBUG}" == "1" ]; then
cp -R "${PWD}/." "${clone_path}"
else
git clone https://github.com/nickjj/dotfiles "${clone_path}"
fi
###############################################################################
# Create initial directories
###############################################################################
mkdir -p "${HOME}/.config/zsh" "${HOME}/.cache/zsh" \
"${HOME}/.local/bin" "${HOME}/.local/share" \
"${HOME}/.local/state" "${HOME}/.vim/spell"
###############################################################################
# Personalize git user
###############################################################################
cp "${clone_path}/.gitconfig.user" "${HOME}/.gitconfig.user"
###############################################################################
# Install zsh plugins
###############################################################################
"${clone_path}/.local/bin/update-zsh-plugins"
###############################################################################
# Install Plug (Vim plugin manager)
###############################################################################
curl -fLo "${HOME}/.vim/autoload/plug.vim" --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
###############################################################################
# Install tpm (tmux plugin manager)
###############################################################################
rm -rf "${HOME}/.tmux/plugins/tpm"
git clone --depth 1 https://github.com/tmux-plugins/tpm "${HOME}/.tmux/plugins/tpm"
###############################################################################
# Install fzf (fuzzy finder on the terminal and used by a Vim plugin)
###############################################################################
rm -rf "${HOME}/.local/share/fzf"
git clone --depth 1 https://github.com/junegunn/fzf.git "${HOME}/.local/share/fzf" \
&& yes | "${HOME}/.local/share/fzf/install" --bin --no-update-rc
###############################################################################
# Carefully create symlinks
###############################################################################
cat << EOF
-------------------------------------------------------------------------------
ln -fs "${clone_path}/.zshenv" "${HOME}/.zshenv"
ln -fs "${clone_path}/.config/zsh/.zshrc" "${HOME}/.config/zsh/.zshrc"
ln -fs "${clone_path}/.config/zsh/.zprofile" "${HOME}/.config/zsh/.zprofile"
ln -fs "${clone_path}/.config/zsh/.aliases" "${HOME}/.config/zsh/.aliases"
ln -fs "${clone_path}/.gitconfig" "${HOME}/.gitconfig"
ln -fs "${clone_path}/.vimrc" "${HOME}/.vimrc"
ln -fs "${clone_path}/.vim/spell/en.utf-8.add" "${HOME}/.vim/spell/en.utf-8.add"
ln -fs "${clone_path}/.tmux.conf" "${HOME}/.tmux.conf"
ln -fs "${clone_path}/.local/bin/update-zsh-plugins" "${HOME}/.local/bin/update-zsh-plugins"
ln -fs "${clone_path}/.local/bin/set-theme" "${HOME}/.local/bin/set-theme"
# And if you happen to be using WSL:
sudo ln -fs "${clone_path}/etc/wsl.conf" /etc/wsl.conf
-------------------------------------------------------------------------------
A potentially dangerous action is about to happen. The above files are going to
get forcefully symlinked.
What does that mean?
Any config files you have on the right hand side of the paths are going to get
overwritten with the files that come with my dotfiles (left side).
If you care about your original config files now would be the time to back
them up. They will ALL be overwritten if you say yes to the prompt below.
EOF
while true; do
read -rep $'\nReady to continue and apply the symlinks? (y) ' y
case "${y}" in
[Yy]*)
break;;
*) echo "Please answer y or CTRL+c the script to abort everything";;
esac
done
ln -fs "${clone_path}/.zshenv" "${HOME}/.zshenv" \
&& ln -fs "${clone_path}/.config/zsh/.zshrc" "${HOME}/.config/zsh/.zshrc" \
&& ln -fs "${clone_path}/.config/zsh/.zprofile" "${HOME}/.config/zsh/.zprofile" \
&& ln -fs "${clone_path}/.config/zsh/.aliases" "${HOME}/.config/zsh/.aliases" \
&& ln -fs "${clone_path}/.gitconfig" "${HOME}/.gitconfig" \
&& ln -fs "${clone_path}/.vimrc" "${HOME}/.vimrc" \
&& ln -fs "${clone_path}/.vim/spell/en.utf-8.add" "${HOME}/.vim/spell/en.utf-8.add" \
&& ln -fs "${clone_path}/.tmux.conf" "${HOME}/.tmux.conf" \
&& ln -fs "${clone_path}/.local/bin/update-zsh-plugins" "${HOME}/.local/bin/update-zsh-plugins" \
&& ln -fs "${clone_path}/.local/bin/set-theme" "${HOME}/.local/bin/set-theme"
if grep -qE "(Microsoft|microsoft|WSL)" /proc/version &>/dev/null; then
sudo ln -fs "${clone_path}/etc/wsl.conf" /etc/wsl.conf
fi
###############################################################################
# Change default shell to zsh
###############################################################################
[ "${os_type}" != "macOS" ] && chsh -s "$(command -v zsh)"
# shellcheck disable=SC1090
. "${HOME}/.config/zsh/.zprofile"
###############################################################################
# Install asdf and Node (Node is used for 1 Vim plugin)
###############################################################################
printf "\n\nInstalling asdf %s...\n" "${install_asdf_version}"
rm -rf "${HOME}/.local/share/asdf"
git clone --depth 1 https://github.com/asdf-vm/asdf.git --branch "${install_asdf_version}" \
"${HOME}/.local/share/asdf"
# shellcheck disable=SC1090
. "${HOME}/.local/share/asdf/asdf.sh"
printf "\n\nInstalling node %s...\n" "${install_node_version}"
"${HOME}/.local/share/asdf/bin/asdf" plugin add nodejs || true
"${HOME}/.local/share/asdf/bin/asdf" install nodejs "${install_node_version}"
"${HOME}/.local/share/asdf/bin/asdf" global nodejs "${install_node_version}"
npm install --unsafe-perm=true --allow-root --global yarn
###############################################################################
# Install tmux plugins
###############################################################################
printf "\n\nInstalling tmux plugins...\n"
export TMUX_PLUGIN_MANAGER_PATH="${HOME}/.tmux/plugins"
"${HOME}/.tmux/plugins/tpm/bin/install_plugins"
###############################################################################
# Install Vim plugins
###############################################################################
printf "\n\nInstalling Vim plugins...\n"
vim -E +PlugInstall +qall || true
###############################################################################
# Done!
###############################################################################
cat << EOF
Everything was installed successfully!
Check out the README file on GitHub to do 1 quick thing manually:
https://github.com/nickjj/dotfiles#did-you-install-everything-successfully
You can safely close this terminal.
The next time you open your terminal zsh will be ready to go!
EOF
exit 0