From 2f86773d7c59f983c04fb39eba93ea7e33b4b3dd Mon Sep 17 00:00:00 2001 From: Gal Date: Wed, 3 Jan 2024 23:44:46 +0700 Subject: [PATCH] :sparkles: Add install.sh script Add install.sh script --- install.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..03ff276 --- /dev/null +++ b/install.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# Set options to exit on error and unset variables +set -eu + +# Check if chezmoi is installed, if not, install it +if ! chezmoi="$(command -v chezmoi)"; then + bin_dir="${HOME}/.local/bin" + chezmoi="${bin_dir}/chezmoi" + echo "🚀 Installing chezmoi to '${chezmoi}'" >&2 + + # Check if curl or wget is available to download chezmoi + if command -v curl >/dev/null; then + chezmoi_install_script="$(curl -fsSL get.chezmoi.io)" + elif command -v wget >/dev/null; then + chezmoi_install_script="$(wget -qO- get.chezmoi.io)" + else + echo "❌ To install chezmoi, you must have curl or wget installed." >&2 + exit 1 + fi + + # Run the installation script to install chezmoi + sh -c "${chezmoi_install_script}" -- -b "${bin_dir}" + unset chezmoi_install_script bin_dir +fi + +# Determine the directory where this script is located +script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)" + +# Set arguments to initialize and apply chezmoi configurations +set -- init --apply --source="${script_dir}" + +echo "🛠️ Running 'chezmoi $*'" >&2 +# Execute chezmoi with the specified arguments +exec "$chezmoi" "$@" +