Files
provision/scripts/user-setup.sh
2025-12-30 16:51:16 -08:00

69 lines
1.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../lib/common.sh"
log_info "Setting up user account"
ACCT=$(whoami)
# Create workspace directory
if [ ! -d "$HOME/.workspace" ]; then
log_info "Creating workspace directory"
mkdir -p "$HOME/.workspace"
log_success "Workspace directory created at $HOME/.workspace"
else
log_success "Workspace directory already exists"
fi
# Change default shell to bash
CURRENT_SHELL=$(basename "$SHELL")
if [ "$CURRENT_SHELL" != "bash" ]; then
log_info "Changing default shell to bash"
chsh -s /bin/bash "$ACCT"
log_success "Default shell changed to bash"
else
log_success "Default shell is already bash"
fi
# Setup 1Password SSH agent
SSH_CONFIG="$HOME/.ssh/config"
ensure_dir "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
if [ -f "$SSH_CONFIG" ] && grep -q "IdentityAgent.*1Password" "$SSH_CONFIG" 2>/dev/null; then
log_success "1Password SSH agent already configured"
else
log_info "Configuring 1Password SSH agent"
# Determine 1Password SSH agent socket path based on OS
case "$OS_TYPE" in
macos)
AGENT_SOCK="~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
;;
debian|arch)
AGENT_SOCK="~/.1password/agent.sock"
;;
esac
# Create or update SSH config
cat >> "$SSH_CONFIG" << EOF
# 1Password SSH Agent
Host *
IdentityAgent "$AGENT_SOCK"
EOF
chmod 600 "$SSH_CONFIG"
log_success "1Password SSH agent configured"
log_info ""
log_info "To use 1Password SSH agent:"
log_info "1. Enable SSH agent in 1Password settings"
log_info "2. Add your SSH keys to 1Password"
log_info "3. The agent will automatically provide keys for SSH connections"
log_info ""
fi
log_success "User setup complete"