-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·68 lines (54 loc) · 1.44 KB
/
install.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
#!/bin/sh
# -e: exit on error
# -u: exit on unset variables
set -eu
log_color() {
color_code="$1"
shift
printf "\033[${color_code}m%s\033[0m\n" "$*" >&2
}
log_red() {
log_color "0;31" "$@"
}
log_blue() {
log_color "0;34" "$@"
}
log_task() {
log_blue "🔃" "$@"
}
log_error() {
log_red "❌" "$@"
}
error() {
log_error "$@"
exit 1
}
if ! chezmoi="$(command -v chezmoi)"; then
bin_dir="${HOME}/.local/bin"
chezmoi="${bin_dir}/chezmoi"
log_task "Installing chezmoi to '${chezmoi}'"
if command -v curl >/dev/null; then
chezmoi_install_script="$(curl -fsSL https://get.chezmoi.io)"
elif command -v wget >/dev/null; then
chezmoi_install_script="$(wget -qO- https://get.chezmoi.io)"
else
error "To install chezmoi, you must have curl or wget."
fi
sh -c "${chezmoi_install_script}" -- -b "${bin_dir}"
unset chezmoi_install_script bin_dir
fi
# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188
# shellcheck disable=SC2312
script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)"
set -- init --source="${script_dir}" --verbose=false --exclude=encrypted --no-tty
if [ -n "${DOTFILES_ONE_SHOT-}" ]; then
set -- "$@" --one-shot --exclude=encrypted
else
set -- "$@" --apply --exclude=encrypted
fi
if [ -n "${DOTFILES_DEBUG-}" ]; then
set -- "$@" --debug --exclude=encrypted
fi
log_task "Running 'chezmoi $*'"
# replace current process with chezmoi
exec "${chezmoi}" "$@"