-
-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathinstall
executable file
·466 lines (350 loc) · 14.5 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#!/usr/bin/env bash
# Usage:
# ./install # Clone my dotfiles
# DEBUG=1 ./install # Copy the local dotfiles directory instead of cloning
#
# # Customize which dotfiles URL to clone from
# DOTFILES_URL="https://github.com/example/dotfiles" ./install
set -o errexit
SKIP_SYSTEM_PACKAGES="${1:-}"
APT_PACKAGES="curl fd-find git iproute2 python3-pip ripgrep tmux wl-clipboard zsh xz-utils"
APT_PACKAGES_OPTIONAL="gnupg htop inotify-tools jq pass pwgen rsync unzip"
BREW_PACKAGES="diffutils fd git nvim python ripgrep shellcheck shfmt tmux zsh xz"
BREW_PACKAGES_OPTIONAL="gnupg htop jq pass pwgen rsync"
INSTALL_NVIM_VERSION="v0.10.4"
INSTALL_SHELLCHECK_VERSION="v0.10.0"
INSTALL_SHFMT_VERSION="v3.11.0"
INSTALL_ASDF_VERSION="v0.11.0"
INSTALL_NODE_VERSION="18.17.0"
CPU_ARCH="$(uname -m)"
OS_TYPE="$(uname | tr "[:upper:]" "[:lower:]")"
DOTFILES_URL="${DOTFILES_URL:-https://github.com/nickjj/dotfiles}"
DOTFILES_PATH="${DOTFILES_PATH:-}"
# -----------------------------------------------------------------------------
# Helper functions
# -----------------------------------------------------------------------------
_error() {
local message="${1:-}"
printf "\e[31;1mERROR:\e[0m %s\n\n" "${message}" >&2
exit 1
}
_info() {
local message="${1:-}"
printf "\n\n\e[36;1m%s:\e[0m\n\n" "${message}"
}
_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
}
_install_packages_apt() {
# shellcheck disable=SC2086
sudo apt-get update && sudo apt-get install -y ${APT_PACKAGES} ${APT_PACKAGES_OPTIONAL}
# Allow using fd with fd instead of fdfind.
ln -fs "$(which fdfind)" "${HOME}/.local/bin/fd"
local original_cpu_arch="${CPU_ARCH}"
# ShellCheck uses a different file name than what uname -m may output. I have
# no idea if this will work since I have no arm64 Linux device to test on.
[[ "${CPU_ARCH}" =~ ^arm ]] && CPU_ARCH="aarch64"
# We're only doing this on Linux because macOS has the latest versions
# available with brew and we want the latest releases of each of these tools.
local shellcheck_install_path="/tmp/shellcheck"
local shellcheck_xz_path="/tmp/shellcheck.tar.xz"
rm -rf "${shellcheck_xz_path}" "${shellcheck_install_path}"
curl -s -o "${shellcheck_xz_path}" -L "https://github.com/koalaman/shellcheck/releases/download/${INSTALL_SHELLCHECK_VERSION}/shellcheck-${INSTALL_SHELLCHECK_VERSION}.${OS_TYPE}.${CPU_ARCH}.tar.xz"
mkdir -p "${shellcheck_install_path}"
tar -xJf "${shellcheck_xz_path}" -C "${shellcheck_install_path}" --strip-components=1
chmod +x "${shellcheck_install_path}/shellcheck"
sudo mv "${_}" /usr/local/bin
CPU_ARCH="${original_cpu_arch}"
# shfmt uses a different file name than what uname -m will output.
[[ "${CPU_ARCH}" == "x86_64" ]] && CPU_ARCH="amd64"
curl -s -o /tmp/shfmt -L "https://github.com/mvdan/sh/releases/download/${INSTALL_SHFMT_VERSION}/shfmt_${INSTALL_SHFMT_VERSION}_${OS_TYPE}_${CPU_ARCH}"
chmod +x /tmp/shfmt
sudo mv "${_}" /usr/local/bin
CPU_ARCH="${original_cpu_arch}"
local nvim_gz_path="/tmp/nvim.tar.gz"
rm -rf "${nvim_gz_path}"
curl -s -o "${nvim_gz_path}" -L "https://github.com/neovim/neovim/releases/download/${INSTALL_NVIM_VERSION}/nvim-${OS_TYPE}-${CPU_ARCH}.tar.gz"
tar -xzf "${nvim_gz_path}" -C "${HOME}/.local" --strip-components=1
}
_install_packages_brew() {
# Install brew itself.
[ -x "$(command -v brew >/dev/null 2>&1)" ] &&
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Ensure brew's paths are available for this script
eval "$(/opt/homebrew/bin/brew shellenv)"
# shellcheck disable=SC2086
brew install ${BREW_PACKAGES} ${BREW_PACKAGES_OPTIONAL}
}
_display_packages() {
if [ "${OS_TYPE}" == "linux" ]; then
echo "${APT_PACKAGES} ${APT_PACKAGES_OPTIONAL}"
else
echo "${BREW_PACKAGES} ${BREW_PACKAGES_OPTIONAL}"
fi
}
# -----------------------------------------------------------------------------
# Main functions
# -----------------------------------------------------------------------------
detect_env() {
case "${OS_TYPE}" in
linux)
if [ ! -f "/etc/debian_version" ]; then
[ -z "${SKIP_SYSTEM_PACKAGES}" ] && _no_system_packages
fi
;;
darwin) ;;
*)
_error "'${OS_TYPE}' is not supported"
;;
esac
}
create_initial_dirs() {
mkdir -p "${HOME}/.config/tmux/plugins" "${HOME}/.config/zsh" "${HOME}/.cache/zsh" \
"${HOME}/.local/bin" "${HOME}/.local/share"
}
install_packages() {
_info "INSTALL PACKAGES"
if [ -n "${SKIP_SYSTEM_PACKAGES}" ]; then
echo "Skipping, you've chosen not to or your OS is unsupported"
return
fi
cat <<EOF
If you choose y, 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 xz are technically optional but are quite useful.
Certain aliases depend on these optional packages being installed.
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
_install_packages_apt
else
_install_packages_brew
fi
break
;;
[Nn]*) exit ;;
*) printf "Please answer y or n\n\n" ;;
esac
done
}
clone_or_update_dotfiles() {
_info "CLONE OR UPDATE DOTFILES"
local local_zprofile="${HOME}/.config/zsh/.zprofile.local"
if [ -f "${local_zprofile}" ]; then
# shellcheck disable=SC1090
. "${local_zprofile}"
fi
local default_dotfiles_path="${DOTFILES_PATH:-"${HOME}/dotfiles"}"
read -rep "Where do you want to clone these dotfiles to [${default_dotfiles_path}]? " dotfiles_path
echo
[[ -z "${dotfiles_path}" ]] && dotfiles_path="${default_dotfiles_path}"
DOTFILES_PATH="${dotfiles_path//\~/"${HOME}"}"
# This is used to locally develop the install script.
if [ "${DEBUG}" == "1" ]; then
if [ "${PWD}" != "${DOTFILES_PATH}" ]; then
cp -R "${PWD}/." "${DOTFILES_PATH}"
fi
printf "They've been copied to '%s'\n" "${DOTFILES_PATH}"
return
fi
if [ -e "${DOTFILES_PATH}" ]; then
# Let's get the latest updates.
git -C "${DOTFILES_PATH}" pull
else
mkdir -p "$(dirname "${DOTFILES_PATH}")"
git clone "${DOTFILES_URL}" "${DOTFILES_PATH}"
fi
}
configure_brew() {
if [ "${OS_TYPE}" == "darwin" ]; then
_info "CONFIGURE BREW"
local zsh_profile="${HOME}/.config/zsh/.zprofile"
if ! grep -q "eval.*homebrew.*shellenv" "${zsh_profile}" 2>/dev/null; then
# shellcheck disable=SC2016
printf '\neval "$(/opt/homebrew/bin/brew shellenv)"\n' >>"${zsh_profile}"
fi
echo "It's been configured in '${zsh_profile}'"
fi
}
install_zsh_plugins() {
_info "INSTALL ZSH PLUGINS"
"${DOTFILES_PATH}/.local/bin/update-zsh-plugins"
}
install_fzf() {
_info "INSTALL FZF"
local fzf_path="${HOME}/.local/share/fzf"
rm -rf "${fzf_path}"
git clone --depth 1 https://github.com/junegunn/fzf.git "${fzf_path}" &&
yes | "${fzf_path}/install" --bin --no-update-rc
}
create_symlinks() {
_info "CREATE SYMLINKS"
cat <<EOF
-------------------------------------------------------------------------------
ln -fs "${DOTFILES_PATH}/.zshenv" "${HOME}/.zshenv"
ln -fs "${DOTFILES_PATH}/.config/zsh/.zshrc" "${HOME}/.config/zsh/.zshrc"
ln -fs "${DOTFILES_PATH}/.config/zsh/.zshrc.local" "${HOME}/.config/zsh/.zshrc.local"
ln -fs "${DOTFILES_PATH}/.config/zsh/.zprofile" "${HOME}/.config/zsh/.zprofile"
ln -fs "${DOTFILES_PATH}/.config/zsh/.zprofile.local" "${HOME}/.config/zsh/.zprofile.local"
ln -fs "${DOTFILES_PATH}/.config/zsh/.aliases" "${HOME}/.config/zsh/.aliases"
ln -fs "${DOTFILES_PATH}/.config/zsh/.aliases.local" "${HOME}/.config/zsh/.aliases.local"
ln -fs "${DOTFILES_PATH}/.config/tmux/tmux.conf" "${HOME}/.config/tmux/tmux.conf"
ln -fs "${DOTFILES_PATH}/.config/zsh/themes" "${HOME}/.config/zsh/themes"
ln -fs "${DOTFILES_PATH}/.config/tmux/themes" "${HOME}/.config/tmux/themes"
ln -fs "${DOTFILES_PATH}/.config/gitui" "${HOME}/.config/gitui"
ln -fs "${DOTFILES_PATH}/.config/nvim" "${HOME}/.config/nvim"
ln -fs "${DOTFILES_PATH}/.gitconfig" "${HOME}/.gitconfig"
ln -fs "${DOTFILES_PATH}/.local/lib/css" "${HOME}/.local/lib/css"
ln -fs "${DOTFILES_PATH}/.local/bin/"* "${HOME}/.local/bin/"
# And if you happen to be using WSL:
sudo ln -fs "${DOTFILES_PATH}/etc/wsl.conf" /etc/wsl.conf
-------------------------------------------------------------------------------
A potentially dangerous action is about to happen. The above directories and
files are going to get forcefully symlinked if you type y in the prompt below.
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 these dotfiles (left side).
Without these symlinks, these dotfiles will not work. If you plan to type y
and have existing files now would be a good time to back them up.
EOF
while true; do
read -rep "Ready to continue? Enter y to apply them all or n to skip (y/n) " yn
case "${yn}" in
[Yy]*)
# Avoid using ln -T flag since it doesn't exist on macOS. We're being
# extra careful here to only delete symlinks if they exist. Technically
# rm -f would work but that could delete real files potentially.
[ -L "${HOME}/.config/zsh/themes" ] && rm "${HOME}/.config/zsh/themes"
[ -L "${HOME}/.config/tmux/themes" ] && rm "${HOME}/.config/tmux/themes"
[ -L "${HOME}/.config/gitui" ] && rm "${HOME}/.config/gitui"
[ -L "${HOME}/.config/nvim" ] && rm "${HOME}/.config/nvim"
[ -L "${HOME}/.local/lib/css" ] && rm "${HOME}/.local/lib/css"
ln -fs "${DOTFILES_PATH}/.zshenv" "${HOME}/.zshenv" &&
ln -fs "${DOTFILES_PATH}/.config/zsh/.zshrc" "${HOME}/.config/zsh/.zshrc" &&
ln -fs "${DOTFILES_PATH}/.config/zsh/.zshrc.local" "${HOME}/.config/zsh/.zshrc.local" &&
ln -fs "${DOTFILES_PATH}/.config/zsh/.zprofile" "${HOME}/.config/zsh/.zprofile" &&
ln -fs "${DOTFILES_PATH}/.config/zsh/.zprofile.local" "${HOME}/.config/zsh/.zprofile.local" &&
ln -fs "${DOTFILES_PATH}/.config/zsh/.aliases" "${HOME}/.config/zsh/.aliases" &&
ln -fs "${DOTFILES_PATH}/.config/zsh/.aliases.local" "${HOME}/.config/zsh/.aliases.local" &&
ln -fs "${DOTFILES_PATH}/.config/tmux/tmux.conf" "${HOME}/.config/tmux/tmux.conf" &&
ln -fs "${DOTFILES_PATH}/.config/zsh/themes" "${HOME}/.config/zsh/themes" &&
ln -fs "${DOTFILES_PATH}/.config/tmux/themes" "${HOME}/.config/tmux/themes" &&
ln -fs "${DOTFILES_PATH}/.config/gitui" "${HOME}/.config/gitui" &&
ln -fs "${DOTFILES_PATH}/.config/nvim" "${HOME}/.config/nvim" &&
ln -fs "${DOTFILES_PATH}/.gitconfig" "${HOME}/.gitconfig" &&
ln -fs "${DOTFILES_PATH}/.local/lib/css" "${HOME}/.local/lib/css" &&
ln -fs "${DOTFILES_PATH}/.local/bin/"* "${HOME}/.local/bin/"
if grep -qE "(Microsoft|microsoft|WSL)" /proc/version &>/dev/null; then
sudo ln -fs "${DOTFILES_PATH}/etc/wsl.conf" /etc/wsl.conf
fi
break
;;
[Nn]*)
break
;;
*) echo "Please answer y or n" ;;
esac
done
}
configure_shell() {
_info "CONFIGURE SHELL"
local_files=(".zshrc.local" ".zprofile.local" ".aliases.local")
for file in "${local_files[@]}"; do
local file_path="${HOME}/.config/zsh/${file}"
if [ ! -f "${file_path}" ]; then
printf "# shellcheck shell=bash\n\n# Any settings defined here are gitignored\n" >"${file_path}"
fi
done
local zprofile_path="${HOME}/.config/zsh/.zprofile.local"
if ! grep -q "^export DOTFILES_PATH=.*$" "${zprofile_path}" 2>/dev/null; then
printf '\nexport DOTFILES_PATH="%s"\n' "${DOTFILES_PATH}" >>"${zprofile_path}"
fi
if [ "${OS_TYPE}" != "darwin" ]; then
[ "${SHELL}" != "$(command -v zsh)" ] && chsh -s "$(command -v zsh)"
fi
# shellcheck disable=SC1091
. "${HOME}/.config/zsh/.zprofile"
echo "It has been configured in '${HOME}/.config.zsh/'"
}
configure_git() {
_info "CONFIGURE GIT"
local git_local_path="${HOME}/.gitconfig.local"
cp -n "${DOTFILES_PATH}/.gitconfig.local" "${git_local_path}" 2>/dev/null || true
echo "It has been configured in '${git_local_path}'"
}
install_asdf() {
_info "INSTALL ASDF (${INSTALL_ASDF_VERSION})"
local asdf_path="${HOME}/.local/share/asdf"
rm -rf "${asdf_path}"
git clone --depth 1 https://github.com/asdf-vm/asdf.git --branch "${INSTALL_ASDF_VERSION}" \
"${asdf_path}"
# shellcheck disable=SC1091
. "${asdf_path}/asdf.sh"
if ! node --version >/dev/null 2>&1; then
printf "Installing Node %s...\n\n" "${INSTALL_NODE_VERSION}"
"${asdf_path}/bin/asdf" plugin add nodejs || true
"${asdf_path}/bin/asdf" install nodejs "${INSTALL_NODE_VERSION}"
"${asdf_path}/bin/asdf" global nodejs "${INSTALL_NODE_VERSION}"
fi
if ! yarn --version >/dev/null 2>&1; then
npm install --unsafe-perm=true --allow-root --global yarn
fi
}
install_tmux_plugins() {
_info "INSTALL TMUX PLUGINS"
local plugin_path="${HOME}/.config/tmux/plugins"
local tpm_path="${plugin_path}/tpm"
rm -rf "${tpm_path}"
git clone --depth 1 https://github.com/tmux-plugins/tpm "${tpm_path}"
"${tpm_path}/bin/install_plugins"
}
install_nvim_plugins() {
_info "INSTALL NEOVIM PLUGINS"
nvim +q
echo "They've been installed"
}
completed_message() {
_info "EVERYTHING WORKED"
cat <<EOF
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 everything will be ready to go!
EOF
if [ "${OS_TYPE}" == "darwin" ]; then
cat <<EOF
P.S., it looks like you're on macOS.
If you're using iTerm2 as your terminal you'll want to goto Settings ->
Profiles -> Keys (tab) and then change your ALT keys to use "Esc+" instead of
"Normal", otherwise ALT+x keymaps in Neovim may not work.
If you're not using iTerm2 you may still need to do similar steps.
EOF
fi
}
detect_env
create_initial_dirs
install_packages
clone_or_update_dotfiles
configure_brew
install_zsh_plugins
install_fzf
create_symlinks
configure_shell
configure_git
install_asdf
install_tmux_plugins
install_nvim_plugins
completed_message