diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-11-01 21:25:17 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-11-01 21:25:17 -0400 |
| commit | fe351483777c8d053d9f8b584278a4c2b162db0e (patch) | |
| tree | 15af9419e315bfad090c940be4a61625bf785876 /shlib | |
| parent | Move /usr/local/bin farther up the path (diff) | |
| download | dotfiles-fe351483777c8d053d9f8b584278a4c2b162db0e.zip | |
Update install scripts for macos and linux and use sh
Diffstat (limited to 'shlib')
| -rw-r--r-- | shlib/bootstrap.sh | 29 | ||||
| -rw-r--r-- | shlib/homebrew.sh | 20 | ||||
| -rw-r--r-- | shlib/log.sh | 47 | ||||
| -rw-r--r-- | shlib/os.sh | 15 | ||||
| -rw-r--r-- | shlib/prompt.sh | 23 | ||||
| -rw-r--r-- | shlib/tmux.sh | 30 |
6 files changed, 164 insertions, 0 deletions
diff --git a/shlib/bootstrap.sh b/shlib/bootstrap.sh new file mode 100644 index 0000000..b2d6bb9 --- /dev/null +++ b/shlib/bootstrap.sh @@ -0,0 +1,29 @@ +# shellcheck shell=sh +[ -n "${DOTFILES_BOOTSTRAP_LOADED}" ] && return +readonly DOTFILES_BOOTSTRAP_LOADED=1 + +. "$(dirname "$0")/shlib/homebrew.sh" +. "$(dirname "$0")/shlib/log.sh" +. "$(dirname "$0")/shlib/prompt.sh" + +bootstrap_macos() { + if ! homebrew_is_installed; then + if prompt_for_confirmation "Homebrew not found. Would you like to install Homebrew?"; then + homebrew_install + else + log_error "Cannot continue without homebrew installed." + return 1 + fi + fi + + log_info "Found homebrew installation. Installing Brewfile.." + (cd homebrew && brew bundle) + log_info "Brewfile successfully installed. Moving to linking dotfiles.." + + sudo ln -sf "$HOME/bin/get-password" /usr/local/bin/get-password + sudo ln -sf "$(which op)" /usr/local/bin/op +} + +bootstrap_linux() { + return 0 +} diff --git a/shlib/homebrew.sh b/shlib/homebrew.sh new file mode 100644 index 0000000..a00ad73 --- /dev/null +++ b/shlib/homebrew.sh @@ -0,0 +1,20 @@ +# shellcheck shell=sh +[ -n "${DOTFILES_HOMEBREW_LOADED}" ] && return +readonly DOTFILES_HOMEBREW_LOADED=1 + +homebrew_is_installed() { + command -v brew >/dev/null 2>&1 +} + +# Installs homebrew and verifies the installation. +# +# If the install was not successful, exits with a +# 1 status code. +homebrew_install() { + /usr/bin/env bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + eval "$(/opt/homebrew/bin/brew shellenv)" + if ! command -v brew >/dev/null 2>&1; then + echo "Failed to install homebrew" + return 1 + fi +} diff --git a/shlib/log.sh b/shlib/log.sh new file mode 100644 index 0000000..3fcf758 --- /dev/null +++ b/shlib/log.sh @@ -0,0 +1,47 @@ +# shellcheck shell=bash +[[ -n "${DOTFILES_LOG_LOADED:-}" ]] && return +readonly DOTFILES_LOG_LOADED=1 + +log_info() { + echo "[INFO] $*" >&2 +} + +log_error() { + echo "[ERROR] $*" >&2 +} + +log_warn() { + echo "[WARN] $*" >&2 +} + +log_success() { + echo "[SUCCESS] $*" >&2 +} + +log_debug() { + [[ "${DEBUG:-}" == "true" ]] && echo "[DEBUG] $*" >&2 +} + +log_newline() { + echo "" >&2 +} + +log_header() { + echo "=== $* ===" >&2 +} + +log_step() { + echo "→ $*" >&2 +} + +log_substep() { + echo " • $*" >&2 +} + +log_progress() { + printf "." >&2 +} + +log_progress_end() { + echo "" >&2 +} diff --git a/shlib/os.sh b/shlib/os.sh new file mode 100644 index 0000000..1ac4f04 --- /dev/null +++ b/shlib/os.sh @@ -0,0 +1,15 @@ +# shellcheck shell=sh +[ -n "${DOTFILES_OS_LOADED}" ] && return +readonly DOTFILES_OS_LOADED=1 + +os_print() { + uname +} + +os_is_macos() { + [ "$(os_print)" = "Darwin" ] +} + +os_is_linux() { + [ "$(os_print)" = "Linux" ] +} diff --git a/shlib/prompt.sh b/shlib/prompt.sh new file mode 100644 index 0000000..6a63db0 --- /dev/null +++ b/shlib/prompt.sh @@ -0,0 +1,23 @@ +# shellcheck shell=sh +[ -n "${DOTFILES_PROMPT_LOADED}" ] && return +readonly DOTFILES_PROMPT_LOADED=1 + +# Prompt the user for confirmation on an action. +# +# Args: +# $1: The question to prompt for. Answer choices +# will be added onto the end. +# +# Returns: +# 0 on yes. 1 on no. +prompt_for_confirmation() { + ( + printf "%s [y/n]: " "$1" + read -r answer + if [ "$answer" != "${answer#[Yy]}" ]; then + return 0 + else + return 1 + fi + ) +} diff --git a/shlib/tmux.sh b/shlib/tmux.sh new file mode 100644 index 0000000..c8870f5 --- /dev/null +++ b/shlib/tmux.sh @@ -0,0 +1,30 @@ +# shellcheck shell=sh +[ -n "${DOTFILES_TMUX_LOADED}" ] && return +readonly DOTFILES_TMUX_LOADED=1 + +. "$(dirname "$0")/shlib/log.sh" + +tmux_setup_tpm() { + ( + tpm_dir="$HOME/.config/tpm/plugins/tpm" + if [ ! -d "$tpm_dir" ]; then + log_info "Cloning TPM..." + if ! git clone https://github.com/tmux-plugins/tpm "$tpm_dir"; then + log_error "Failed to clone tpm to $tpm_dir" + return 1 + fi + else + log_info "TPM already exists, updating..." + (cd "$tpm_dir" && git pull) + fi + + if command -v tmux >/dev/null 2>&1; then + log_info "Installing tmux plugins..." + "$tpm_dir/scripts/install_plugins.sh" + log_info "TPM plugins installed successfully." + else + log_warn "tmux not found. TPM cloned but plugins not installed." + log_warn "Run 'tmux' and then press 'prefix + I' to install plugins manually." + fi + ) +} |