-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·53 lines (40 loc) · 1.06 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·53 lines (40 loc) · 1.06 KB
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
#!/usr/bin/env sh
# shellcheck disable=SC3043 # `local` is supported by every real /bin/sh.
set -eu
ensure_chezmoi() {
local chezmoi
if chezmoi="$(command -v chezmoi)"; then
printf '%s\n' "${chezmoi}"
return 0
fi
local bin_dir="${HOME}/.local/bin"
chezmoi="${bin_dir}/chezmoi"
printf 'Installing chezmoi to %s\n' "${chezmoi}" >&2
if ! command -v curl >/dev/null; then
printf 'To install chezmoi, you must have curl installed.\n' >&2
exit 1
fi
local chezmoi_install_script
chezmoi_install_script="$(
curl \
--fail \
--silent \
--show-error \
--location \
--proto '=https' \
https://get.chezmoi.io
)"
sh -c "${chezmoi_install_script}" -- -b "${bin_dir}" >&2
printf '%s\n' "${chezmoi}"
}
main() {
local chezmoi
chezmoi="$(ensure_chezmoi)"
# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188
local script_dir
script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)"
set -- init --apply --source="${script_dir}"
printf "Running 'chezmoi %s'\n" "$*" >&2
exec "${chezmoi}" "$@"
}
main "$@"