forked from skwp/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·45 lines (40 loc) · 1.28 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
#!/bin/sh
# -e: exit on error
# -u: exit on unset variables
set -eu
# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188
script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)"
if ! chezmoi="$(command -v chezmoi)"; then
bin_dir="${script_dir}/root/bin"
chezmoi="${bin_dir}/chezmoi"
echo "Installing chezmoi to '${chezmoi}'" >&2
if command -v curl >/dev/null; then
chezmoi_install_script="$(curl -fsSL https://chezmoi.io/get)"
elif command -v wget >/dev/null; then
chezmoi_install_script="$(wget -qO- https://chezmoi.io/get)"
else
echo "To install chezmoi, you must have curl or wget installed." >&2
exit 1
fi
sh -c "${chezmoi_install_script}" -- -b "${bin_dir}"
unset chezmoi_install_script bin_dir
fi
if [ -z "${ACT:+false}${CODESPACES:+false}${DEBIAN_FRONTEND:+false}" ]; then
echo "Running interactive"
"${chezmoi}" init "--source=${script_dir}"
"${chezmoi}" diff --verbose
read -p 'Apply modifications? (y/n) ' r
case "${r}" in
y|Y|s|S)
set -- apply --verbose "--source=${script_dir}"
;;
*)
set -- diff
;;
esac
else
set -- init --apply --verbose --source="${script_dir}"
fi
echo "Running 'chezmoi $*'" >&2
# exec: replace current process with chezmoi
exec "$chezmoi" "$@"