Rollback and Uninstall Guide
Rollback and Uninstall Guide
Section titled “Rollback and Uninstall Guide”This guide explains how the dotfiles system tracks operations and enables safe uninstallation and rollback of modules.
Overview
Section titled “Overview”Starting with version 1.1.0, the dotfiles system records all operations performed during module installation. This operation history enables:
- Uninstalling modules and reversing their changes
- Automatic rollback when installation fails mid-way
- Audit trail of what files and directories were modified
Operation Recording
Section titled “Operation Recording”During installation, the system tracks:
File Deployments
Section titled “File Deployments”- Created: New files or symlinks
- Modified: Existing files that were changed
- Backed up: Original files that were backed up before modification
Directory Creation
Section titled “Directory Creation”- Created: New directories that were made
- Includes empty directory tracking for safe cleanup
Script Execution
Section titled “Script Execution”- Executed: Install scripts that ran
- Note: Scripts cannot be automatically rolled back
Package Installation
Section titled “Package Installation”- Installed: Packages added via system package manager
- Note: Packages are not automatically removed during rollback
Viewing Rollback Plan
Section titled “Viewing Rollback Plan”Before uninstalling, you can see what operations will be reversed:
# Show rollback plan for a moduledotfiles uninstall git --dry-runOutput example:
Rollback plan (5 operations): 1. Remove: /home/user/.gitconfig 2. Restore /home/user/.bashrc from /home/user/.bashrc.backup 3. Remove directory: /home/user/.config/git 4. Package was installed: git (manual removal may be needed) 5. Script was executed: install.sh (manual cleanup may be needed)Uninstalling Modules
Section titled “Uninstalling Modules”Basic Uninstall
Section titled “Basic Uninstall”dotfiles uninstall <module>The command will:
- Show the rollback plan
- Ask for confirmation
- Execute rollback operations in reverse order
- Remove the module from state
Force Uninstall
Section titled “Force Uninstall”Skip confirmation prompts:
dotfiles uninstall <module> --forceUse this when:
- Running in scripts or CI/CD
- You’re confident about the uninstall
- Continuing despite errors
Dry-run Mode
Section titled “Dry-run Mode”Preview what would be uninstalled without making changes:
dotfiles uninstall <module> --dry-runMultiple Modules
Section titled “Multiple Modules”Uninstall several modules at once:
dotfiles uninstall git zsh tmuxRollback Operations
Section titled “Rollback Operations”File Operations
Section titled “File Operations”Created files/symlinks: Removed completely
Remove: /home/user/.gitconfigModified files: Restored from backup (if available)
Restore /home/user/.bashrc from /home/user/.bashrc.backupNo backup: Warning shown, file left as-is
File was modified: /home/user/.zshrc (no backup available)Directory Operations
Section titled “Directory Operations”Created directories: Removed if empty
Remove directory: /home/user/.config/moduleNon-empty directories: Left in place with warning
Directory not empty, keeping: /home/user/.config (3 files)Script Operations
Section titled “Script Operations”Scripts cannot be automatically rolled back:
Script was executed: install.sh (manual cleanup may be needed)You may need to manually:
- Remove configuration added by scripts
- Undo system-level changes
- Clean up artifacts
Package Operations
Section titled “Package Operations”Packages are not automatically removed:
Package was installed: git (manual removal may be needed)To remove packages manually:
# macOSbrew uninstall <package>
# Ubuntu/Debiansudo apt remove <package>
# Arch Linuxsudo pacman -R <package>Automatic Rollback on Failure
Section titled “Automatic Rollback on Failure”If a module installation fails mid-way, you’ll see an interactive prompt:
[ERROR] Failed to install module: script execution failed
Options: [S]kip - Leave partial installation as-is [U]ndo - Rollback changes and clean up
What would you like to do?Skip Option
Section titled “Skip Option”Leaves the partial installation:
- Files that were deployed remain
- State is marked as “failed”
- You can retry installation later
- Useful for debugging
Undo Option
Section titled “Undo Option”Rolls back all operations:
- Removes deployed files
- Restores backed-up files
- Removes created directories (if empty)
- Cleans up module state
- Returns system to pre-installation state
Unattended Mode
Section titled “Unattended Mode”In --unattended mode:
- No prompt is shown
- Failed state is recorded
- Partial installation is left as-is
- Use
dotfiles uninstallto clean up later
State Management
Section titled “State Management”Viewing Module State
Section titled “Viewing Module State”# Show all installed modulesdotfiles status
# List available modulesdotfiles listState Location
Section titled “State Location”Module state is stored at:
$DOTFILES_DIR/.state/<module>.jsonEach state file contains:
- Module name and version
- Installation timestamp
- Installation status
- Operating system
- Complete operation history
Manual State Inspection
Section titled “Manual State Inspection”# View state for a specific modulecat $DOTFILES_DIR/.state/git.json | jq .Example state file:
{ "name": "git", "version": "1.0.0", "status": "installed", "installed_at": "2026-02-10T12:00:00Z", "updated_at": "2026-02-10T12:00:05Z", "os": "ubuntu", "operations": [ { "type": "file_deploy", "action": "created", "path": "/home/user/.gitconfig", "timestamp": "2026-02-10T12:00:01Z", "metadata": { "source": "/path/to/dotfiles/modules/git/gitconfig", "type": "symlink" } } ]}Best Practices
Section titled “Best Practices”Before Uninstalling
Section titled “Before Uninstalling”- Check dependencies: Verify no other modules depend on this one
- Review rollback plan: Use
--dry-runto see what will change - Backup important files: If you’ve customized module files
- Check for manual changes: Review files that can’t be auto-removed
After Uninstalling
Section titled “After Uninstalling”- Verify removal: Check that files were actually removed
- Clean up packages: Manually remove packages if desired
- Remove custom configs: Check for files you added after installation
Module Development
Section titled “Module Development”When creating modules:
- Use file deployments: Prefer declarative file deployments over scripts
- Minimize script logic: Keep install scripts simple
- Document manual steps: Note any manual cleanup needed
- Test rollback: Verify uninstall works correctly
Troubleshooting
Section titled “Troubleshooting”Uninstall fails with errors
Section titled “Uninstall fails with errors”# Continue uninstalling despite errorsdotfiles uninstall <module> --forceState file exists but module “not installed”
Section titled “State file exists but module “not installed””# Check state filecat $DOTFILES_DIR/.state/<module>.json
# Manually remove staterm $DOTFILES_DIR/.state/<module>.jsonFiles not removed during uninstall
Section titled “Files not removed during uninstall”Possible causes:
- Files were modified after installation
- Files are owned by root
- Permissions prevent deletion
Manual cleanup:
# Check file ownershipls -la <path>
# Remove with sudo if neededsudo rm <path>Directory not removed
Section titled “Directory not removed”Directories are only removed if empty:
# Check directory contentsls -la <directory>
# Remove manually if desiredrm -rf <directory>No operations recorded
Section titled “No operations recorded”Modules installed before operation recording was implemented have empty operation lists. To uninstall:
- Review module files manually
- Use
--forceto remove state anyway - Manually clean up deployed files
Advanced Topics
Section titled “Advanced Topics”Partial Rollback
Section titled “Partial Rollback”Currently not supported. You can:
- Manually remove specific files
- Edit state JSON to remove specific operations
- Reinstall the module
Rollback Hooks
Section titled “Rollback Hooks”Future enhancement. Currently:
- No pre/post rollback hooks
- No custom rollback scripts
- Use module install scripts for setup; uninstall for teardown
Cross-Machine Rollback
Section titled “Cross-Machine Rollback”Operation paths are absolute and machine-specific. When syncing across machines:
- State files are not portable
- Reinstall modules on each machine
- Use profiles for machine-specific configuration
Related Documentation
Section titled “Related Documentation”- Architecture Guide - System design and operation recording
- Creating Modules - Creating rollback-friendly modules
- CLI Reference - Full uninstall command documentation
- Troubleshooting - Common issues and solutions