bootstrap.sh script is a one-shot installation script that prepares a fresh Ubuntu system for dotfiles management. It installs all necessary dependencies and sets up the encryption keys.
Overview
The bootstrap script performs the following operations:- Safety check (prevents running as root)
- System package installation
- Tool installation (Ansible, Bitwarden CLI, chezmoi)
- Bitwarden authentication
- Age encryption key setup
Usage
Script Breakdown
Step 0: Root Check
Step 1: System Dependencies
| Package | Purpose |
|---|---|
curl | Download files from the internet |
git | Version control for dotfiles repository |
age | File encryption/decryption |
gnupg | GPG key management for apt repositories |
software-properties-common | Manage PPAs and apt repositories |
snapd | Snap package manager daemon |
Step 2: Install Ansible
ansible command exists before attempting installation.
Why Ansible: Used to configure system packages, GNOME settings, and ensure consistent environment setup across machines.
Step 3: Install Bitwarden CLI
- Preferred: Snap (if available)
- Fallback: npm global install
bw command is not found.
Step 4: Install chezmoi
- Preferred: Snap with
--classicconfinement (full system access) - Fallback: Official install script to
~/.local/bin
~/.local/bin to PATH for the current session.
Step 5: Bitwarden Login & Unlock
- Check if unauthenticated → prompt for login credentials
- Check if vault is locked → unlock and export session token
- Sync vault data after unlock
BW_SESSION environment variable allows subsequent bw commands to access the unlocked vault without re-entering the password.
Step 6: Age Key Setup
- Create chezmoi config directory
- Try to retrieve existing key from Bitwarden Secure Note named
chezmoi-age-key - If not found, generate a new key and display it for backup
- Fix ownership and permissions
- Key file has
600permissions (owner read/write only) - Ownership explicitly set to current user (not root)
chezmoi-age-key for future machines.
Next Steps
After bootstrap completes, initialize your dotfiles:- Clone the dotfiles repository
- Prompt for configuration (name, email, machine type)
- Decrypt encrypted files using your age key
- Apply dotfiles to your home directory
- Run the Ansible playbook to configure system packages and settings
Environment Variables
| Variable | Set By | Purpose |
|---|---|---|
BW_SESSION | Step 5 | Bitwarden session token for vault access |
PATH | Step 4 | Includes ~/.local/bin if chezmoi installed via script |
Error Handling
The script usesset -euo pipefail to:
- Exit on any command failure (
-e) - Treat unset variables as errors (
-u) - Propagate pipe failures (
-o pipefail)