Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189#!/usr/bin/env zsh
set -e
OS="$(uname -s)"
apply_dotfiles() { echo "==> Applying dotfiles" mise exec chezmoi -- chezmoi init aaronmallen --apply}
install_1password_debian() { command -v op >/dev/null 2>&1 && return 0
echo "==> Installing 1Password CLI" curl -sS https://downloads.1password.com/linux/keys/1password.asc | \ sudo gpg --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/1password-archive-keyring.gpg] https://downloads.1password.com/linux/debian/$(dpkg --print-architecture) stable main" | \ sudo tee /etc/apt/sources.list.d/1password.list sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/ curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | \ sudo tee /etc/debsig/policies/AC2D62742012EA22/1password.pol sudo mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22 curl -sS https://downloads.1password.com/linux/keys/1password.asc | \ sudo gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg sudo apt-get update && sudo apt-get install -y 1password 1password-cli prompt_1password_configuration}
install_chezmoi() { if ! command -v chezmoi >/dev/null 2>&1; then echo "==> Installing chezmoi" mise install chezmoi fi}
install_mise() { if ! command -v mise >/dev/null 2>&1; then echo "==> Installing mise" curl -fsSL https://mise.run | sh export PATH="${HOME}/.local/bin:${PATH}" fi}
login_atuin() { [ "$(chezmoi execute-template '{{ .email }}')" = "hello@aaronmallen.me" ] || return 0 command -v atuin > /dev/null || return 0 command -v op > /dev/null || return 0 echo "==> Logging in to Atuin" atuin login --username "$(op read 'op://Private/bspumr7wtvze6nbooz7gt7krlu/username')" \ --password "$(op read 'op://Private/bspumr7wtvze6nbooz7gt7krlu/password')" \ --key "$(op read 'op://Private/bspumr7wtvze6nbooz7gt7krlu/key')" \ || echo "==> Atuin login failed. Please try again later with 'atuin login'."}
minimally_source_zsh() { eval "$(mise activate zsh)" eval "$(atuin init zsh)"}
set_chezmoi_remotes() { [ "$(chezmoi execute-template '{{ .email }}')" = "hello@aaronmallen.me" ] || return 0
echo "==> Setting chezmoi source"
# `chezmoi init` clones over https as `origin`; replace it with the ssh # remote so pushes work without a token, and repoint main at it so # chezmoi's autoPush has a valid upstream. cd "${HOME}/.local/share/chezmoi" || return 1 mise trust git remote remove origin 2>/dev/null || true git remote remove github 2>/dev/null || true git remote add github git@github.com:aaronmallen/dotfiles.git git fetch github git branch --set-upstream-to=github/main main}
prompt_1password_configuration() { echo "" echo "==> Please complete the following steps:" echo " 1. Open 1Password" echo " 2. Sign in to 1Password CLI if prompted" echo " 3. Go to Settings > Developer" echo " 4. Enable 'Connect with 1Password CLI'" echo "" printf "Press Enter once you have completed these steps..." read -r < /dev/tty}
case "$OS" inDarwin) if ! command -v brew >/dev/null 2>&1; then echo "==> Installing Homebrew" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" fi
if ! brew list --cask 1password >/dev/null 2>&1; then echo "==> Installing 1Password" brew install --cask 1password fi
if ! command -v op >/dev/null 2>&1; then echo "==> Installing 1Password CLI" brew install --cask 1password-CLI prompt_1password_configuration fi
install_mise install_chezmoi apply_dotfiles minimally_source_zsh login_atuin set_chezmoi_remotes
echo "==> Setup Complete" ;;Linux) if [ -f /etc/os-release ]; then . /etc/os-release case "$ID" in arch|cachyos|manjaro) if ! command -v op >/dev/null 2>&1; then if command -v paru >/dev/null 2>&1; then echo "==> Installing 1password" paru -S --noconfirm 1password 1password-cli elif command -v yay >/dev/null 2>&1; then echo "==> Installing 1password" yay -S --noconfirm 1password 1password-cli else echo "Error: AUR helper (paru or yay) not found" exit 1 fi prompt_1password_configuration fi
install_mise install_chezmoi apply_dotfiles minimally_source_zsh login_atuin set_chezmoi_remotes
echo "==> Setup Complete" ;; debian|ubuntu|pop|linuxmint|elementary|neon|zorin) install_1password_debian
install_mise install_chezmoi apply_dotfiles minimally_source_zsh login_atuin set_chezmoi_remotes
echo "==> Setup Complete" ;; *) case "$ID_LIKE" in *debian*|*ubuntu*) install_1password_debian
install_mise install_chezmoi apply_dotfiles minimally_source_zsh login_atuin set_chezmoi_remotes
echo "==> Setup Complete" ;; *) echo "Unsupported Linux distribution: $ID" exit 1 ;; esac ;; esac else echo "Error: /etc/os-release not found" exit 1 fi ;;*) echo "Unsupported operating system: $OS" exit 1 ;;esac