diff --git a/.chezmoiignore b/.chezmoiignore index 5757f4d..da770a2 100644 --- a/.chezmoiignore +++ b/.chezmoiignore @@ -4,6 +4,7 @@ README.md CLAUDE.md CLAUDE.local.md key.txt.age +install.sh {{- if ne .machineClass "private" }} .ssh/config.d/home diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..74f0c89 --- /dev/null +++ b/install.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# -e: exit on error +# -u: exit on unset variables +set -eu + +if ! chezmoi="$(command -v chezmoi)"; then + bin_dir="${HOME}/.local/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 + +# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188 +script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)" + +set -- init --apply --source="${script_dir}" + +echo "Running 'chezmoi $*'" >&2 +# exec: replace current process with chezmoi +exec "$chezmoi" "$@"