Skip to content

Commit 1d625ad

Browse files
committed
add chezmoi install script
1 parent 2fb41bc commit 1d625ad

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

install.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
# -e: exit on error
4+
# -u: exit on unset variables
5+
set -eu
6+
7+
if ! chezmoi="$(command -v chezmoi)"; then
8+
bin_dir="${HOME}/.local/bin"
9+
chezmoi="${bin_dir}/chezmoi"
10+
echo "Installing chezmoi to '${chezmoi}'" >&2
11+
if command -v curl >/dev/null; then
12+
chezmoi_install_script="$(curl -fsSL get.chezmoi.io)"
13+
elif command -v wget >/dev/null; then
14+
chezmoi_install_script="$(wget -qO- get.chezmoi.io)"
15+
else
16+
echo "To install chezmoi, you must have curl or wget installed." >&2
17+
exit 1
18+
fi
19+
sh -c "${chezmoi_install_script}" -- -b "${bin_dir}"
20+
unset chezmoi_install_script bin_dir
21+
fi
22+
23+
# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188
24+
script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)"
25+
26+
set -- init --apply --source="${script_dir}"
27+
28+
echo "Running 'chezmoi $*'" >&2
29+
# exec: replace current process with chezmoi
30+
exec "$chezmoi" "$@"

0 commit comments

Comments
 (0)