Initial commit: Red Pill backup & restore for Omarchy

Unified backup system using rsync hardlink snapshots to external drives.
Includes TUI, CLI, auto-backup on shutdown, integrity verification,
new machine restore, and clean uninstaller.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
28allday 2026-03-26 21:22:35 +00:00
commit 20e0e77e72
3 changed files with 2598 additions and 0 deletions

283
README.md Normal file
View file

@ -0,0 +1,283 @@
# Red Pill - Backup & Restore for Omarchy
*"You take the red pill, you stay in Hyprland and I show you how deep the rabbit-hole goes..."*
A unified backup and restore system for [Omarchy](https://omarchy.com). Backs up configs and user data to external drives using rsync hardlink snapshots - each backup is a full browseable directory tree, but unchanged files are deduplicated via hardlinks so they use no extra disk space.
## Features
- **Three backup modes**: configs only, user data only, or everything
- **Rsync hardlink snapshots**: space-efficient incremental backups on external drives
- **TUI interface**: whiptail-based menu with full CLI fallback
- **Auto-backup on shutdown**: systemd service runs a full backup every shutdown/reboot
- **Backup verification**: checksum manifests (xxh128 or sha256) with integrity checking
- **New machine restore**: standalone `restore.sh` written to the backup drive - works without Red Pill installed
- **Username migration**: automatically fixes paths when restoring to a different username/home directory
- **Theme restoration**: reapplies Omarchy theme after restore
- **Login notifications**: reminds you if no backup in 7+ days
- **Walker integration**: searchable from the Omarchy launcher
- **Hyprland keybind**: `Super+Alt+B` opens a floating TUI window
## Requirements
- **OS**: [Omarchy](https://omarchy.com) (Arch Linux)
- **Dependencies**: `rsync`, `libnewt` (whiptail), `zstd`, `alacritty`, `desktop-file-utils` (all ship with Omarchy)
- **Backup destination**: any external drive (ext4, NTFS, btrfs, exFAT, etc.)
## Quick Start
```bash
git clone https://github.com/28allday/Red-Pill-Omarchy.git
cd Red-Pill-Omarchy
bash Redpill_update.sh
```
Then:
1. Press `Super+Alt+B` (or run `redpill`)
2. Set your backup destination (option 10)
3. Run your first backup
4. Optionally enable auto-backup on shutdown (option 11)
## Usage
### Keybindings
| Action | Keybind |
|--------|---------|
| Open Red Pill TUI | `Super + Alt + B` |
| Search in launcher | `Super + Space` → type "RED PILL" |
### TUI Menu
The interactive menu provides:
| Option | Description |
|--------|-------------|
| 1 | Backup configs only (~/.config, ~/.ssh, ~/.gnupg, etc.) |
| 2 | Backup user data only (Documents, Pictures, Music, etc.) |
| 3 | Backup everything (configs + user data) |
| 4 | Restore (choose from snapshots or local backups) |
| 5 | List all backups (drive snapshots + local tarballs) |
| 6 | Delete backups (multi-select with confirmation) |
| 7 | Verify backup integrity (checksum validation) |
| 8 | Edit include list |
| 9 | Edit exclude list |
| 10 | Set backup destination (drive selection or manual path) |
| 11 | Toggle auto-backup on shutdown |
| 12 | Show paths and configuration |
### CLI Commands
```bash
redpill # Open TUI
redpill backup [configs|data|all] # Run backup
redpill estimate [configs|data|all] # Dry-run estimate
redpill restore [SNAPSHOT|FILE] # Restore from snapshot or tarball
redpill verify # Verify backup checksums
redpill list # List all backups
redpill config-backup # Local config tarball (no drive needed)
redpill includes # Edit include list
redpill excludes # Edit exclude list
redpill destination # Set backup destination
redpill where # Show all paths
```
### Quick Restore (TTY)
```bash
bluepill
```
Shows the Matrix quote, then restores from the latest snapshot on your external drive (falls back to local backup if no drive found). Works from a TTY if your desktop is broken.
## What Gets Installed
`Redpill_update.sh` installs the following:
### Binaries
| Path | Purpose |
|------|---------|
| `/usr/local/bin/redpill` | Main TUI and CLI backup/restore tool |
| `/usr/local/bin/bluepill` | Quick restore shortcut (TTY-friendly) |
| `/usr/local/bin/redpill-autobackup` | Shutdown auto-backup wrapper |
| `/usr/local/bin/redpill-notify` | Login notification checker |
### Desktop Integration
| Path | Purpose |
|------|---------|
| `~/.local/share/applications/redpill.desktop` | User application menu entry |
| `/usr/share/applications/redpill.desktop` | System application menu entry |
| `~/.config/walker/config.toml` | Walker launcher custom command entry |
| `~/.config/hypr/bindings.conf` | Hyprland keybind (`Super+Alt+B`) + window rules |
| `~/.config/hypr/autostart.conf` | Login notification autostart |
### Systemd Service
| Path | Purpose |
|------|---------|
| `/etc/systemd/system/redpill-autobackup.service` | Runs full backup on shutdown/reboot |
### Config & State
| Path | Purpose |
|------|---------|
| `~/.config/redpill/includes.conf` | Paths to back up |
| `~/.config/redpill/excludes.conf` | Exclusion patterns |
| `~/.config/redpill/destination.conf` | Backup destination path |
| `~/.config/redpill/RECOVERY.txt` | Recovery guide |
| `~/.local/state/redpill/backups/` | Local config tarballs |
| `~/.local/state/redpill/last_backup` | Timestamp of last backup |
## How It Works
### Backup Process
1. **Estimate** - dry-run rsync calculates total size, changed files, and new data to transfer
2. **Snapshot** - rsync copies files to a timestamped directory, hardlinking unchanged files to the previous snapshot
3. **Checksums** - xxh128 (or sha256) manifest generated in background for integrity verification
4. **Latest symlink** - atomically updated to point to the new snapshot
5. **Standalone restore script** - written to the drive root for new machine recovery
### Snapshot Structure on External Drive
```
<drive>/redpill/
├── restore.sh # Standalone restore (no install needed)
├── latest -> snapshots/2026-02-08_14-30-00
└── snapshots/
├── 2026-02-08_14-30-00/ # Full directory tree
│ ├── .config/ # All backed-up files
│ ├── Documents/
│ ├── backup.log # Backup metadata and report
│ └── checksums.xxh128 # Integrity manifest
└── 2026-02-07_10-00-00/ # Previous snapshot (hardlinked)
└── ...
```
Each snapshot is a complete, browseable copy. You can open any snapshot in a file manager and copy files manually if needed.
### Hardlink Deduplication
If a file hasn't changed between backups, rsync creates a hardlink to the previous snapshot's copy instead of duplicating it. This means:
- Each snapshot looks like a full backup
- Only changed/new files consume additional disk space
- Deleting old snapshots is safe - files are only freed when all hardlinks are removed
### Backup Modes
| Mode | What's included |
|------|----------------|
| **configs** | `~/.config`, `~/.bashrc`, `~/.bash_profile`, `~/.ssh`, `~/.gnupg`, `~/.local/share/fonts`, `~/.local/share/applications` |
| **data** | `~/Documents`, `~/Pictures`, `~/Music`, `~/Videos`, `~/Desktop`, `~/Downloads`, `~/Templates` |
| **all** | Everything above combined |
### Default Exclusions
```
.cache/
.local/state/
node_modules/
__pycache__/
.Trash*/
*.tmp
*.swp
.thumbnails/
```
### Auto-Backup on Shutdown
When enabled, a systemd service runs a full backup every time you shut down or reboot:
- Silently skips if no backup destination is configured
- Silently skips if the backup drive isn't mounted
- Silently skips if no first manual backup has been done
- 10-minute timeout to prevent hanging shutdown
- Kills rsync cleanly on SIGTERM
### New Machine Restore
The standalone `restore.sh` on the backup drive works without Red Pill installed:
1. Install Omarchy on the new machine
2. Mount the backup drive
3. Run: `bash /run/media/$USER/<drive>/redpill/restore.sh`
4. Select a snapshot to restore
5. Reboot
The script handles username changes automatically by fixing symlinks and hardcoded paths in config files.
### Login Notifications
`redpill-notify` runs on each Hyprland login and sends a desktop notification if:
- Auto-backup is enabled but no backup has ever been done
- The last backup was more than 7 days ago
## Uninstalling
```bash
bash Redpill_uninstall.sh
```
The uninstaller removes:
- All binaries from `/usr/local/bin/`
- Desktop entries (user + system)
- Hyprland keybinding and window rules
- Hyprland autostart entry
- Walker custom command entry
- Systemd auto-backup service
- Optionally: config and state directories
Backup snapshots on external drives are **never** touched.
## Troubleshooting
### Backup destination not found
```bash
# Check if drive is mounted
lsblk
# Mount via udisks
udisksctl mount -b /dev/sda1
# Set destination manually
redpill destination
```
### Auto-backup not running
```bash
# Check service status
systemctl status redpill-autobackup
# View last shutdown backup log
journalctl -u redpill-autobackup -b -1
# Ensure it's enabled
sudo systemctl enable redpill-autobackup
```
### Verify backup integrity
```bash
redpill verify
```
Select a snapshot and the tool will check every file against its stored checksum.
### Restore to different username
Both the TUI restore and standalone `restore.sh` automatically detect username changes and fix:
- Absolute symlinks pointing to the old home directory
- Hardcoded paths in config files under `~/.config/`
## Credits
- [Omarchy](https://omarchy.com) - The Arch Linux distribution this was built for
- [rsync](https://rsync.samba.org/) - The engine behind hardlink snapshot backups
## License
This project is provided as-is for the Omarchy community.

202
Redpill_uninstall.sh Executable file
View file

@ -0,0 +1,202 @@
#!/usr/bin/env bash
set -euo pipefail
# ===== RED PILL — Uninstaller =====
# Reverses everything done by Redpill_update.sh
_c_green=$'\033[38;2;158;206;106m'
_c_red=$'\033[38;2;247;118;142m'
_c_yellow=$'\033[38;2;224;175;104m'
_c_dim=$'\033[2m'
_c_bold=$'\033[1m'
_c_reset=$'\033[0m'
_hr(){
printf '%s────────────────────────────────────────────────────────%s\n' "$_c_dim" "$_c_reset"
}
_ok(){
printf ' %s✓%s %s\n' "$_c_green" "$_c_reset" "$1"
}
_skip(){
printf ' %s-%s %s %s(not found)%s\n' "$_c_dim" "$_c_reset" "$1" "$_c_dim" "$_c_reset"
}
_warn(){
printf ' %s⚠%s %s\n' "$_c_yellow" "$_c_reset" "$1"
}
echo
_hr
printf ' %s%sRED PILL — Uninstaller%s\n' "$_c_bold" "$_c_red" "$_c_reset"
_hr
echo
printf ' This will remove all Red Pill components:\n'
printf ' - /usr/local/bin/redpill, bluepill, redpill-autobackup, redpill-notify\n'
printf ' - Desktop entries (user + system)\n'
printf ' - Hyprland keybinding (Super+Alt+B) and window rules\n'
printf ' - Hyprland autostart entry (redpill-notify)\n'
printf ' - Walker custom command entry\n'
printf ' - Systemd auto-backup service\n'
echo
printf ' %sYour backup data (snapshots on external drives) will NOT be touched.%s\n' "$_c_dim" "$_c_reset"
echo
read -r -p " Proceed with uninstall? [y/N] " confirm || confirm=""
[[ "${confirm,,}" == "y" ]] || { echo " Cancelled."; exit 0; }
echo
# 1) Disable and remove systemd service
SVC="redpill-autobackup"
SVC_FILE="/etc/systemd/system/${SVC}.service"
if systemctl is-enabled "$SVC" &>/dev/null; then
sudo systemctl disable "$SVC" 2>/dev/null || true
_ok "Disabled systemd service: $SVC"
fi
if systemctl is-active "$SVC" &>/dev/null; then
sudo systemctl stop "$SVC" 2>/dev/null || true
fi
if [[ -f "$SVC_FILE" ]]; then
sudo rm -f "$SVC_FILE"
sudo systemctl daemon-reload
_ok "Removed $SVC_FILE"
else
_skip "$SVC_FILE"
fi
# 2) Remove binaries from /usr/local/bin
for bin in redpill bluepill redpill-autobackup redpill-notify; do
if [[ -f "/usr/local/bin/$bin" ]]; then
sudo rm -f "/usr/local/bin/$bin"
_ok "Removed /usr/local/bin/$bin"
else
_skip "/usr/local/bin/$bin"
fi
done
# 3) Remove desktop entries
USER_DESK="$HOME/.local/share/applications/redpill.desktop"
SYS_DESK="/usr/share/applications/redpill.desktop"
if [[ -f "$USER_DESK" ]]; then
rm -f "$USER_DESK"
_ok "Removed $USER_DESK"
else
_skip "$USER_DESK"
fi
if [[ -f "$SYS_DESK" ]]; then
sudo rm -f "$SYS_DESK"
_ok "Removed $SYS_DESK"
else
_skip "$SYS_DESK"
fi
update-desktop-database "$HOME/.local/share/applications" >/dev/null 2>&1 || true
sudo update-desktop-database /usr/share/applications >/dev/null 2>&1 || true
# 4) Remove Hyprland keybinding block from bindings.conf
BINDINGS_FILE="$HOME/.config/hypr/bindings.conf"
if [[ -f "$BINDINGS_FILE" ]] && grep -q '# Red Pill Backup TUI' "$BINDINGS_FILE"; then
# Remove the block between "# Red Pill Backup TUI" and "# End Red Pill Backup TUI" (inclusive)
sed -i '/# Red Pill Backup TUI/,/# End Red Pill Backup TUI/d' "$BINDINGS_FILE"
# Clean up any resulting double blank lines
sed -i '/^$/N;/^\n$/d' "$BINDINGS_FILE"
_ok "Removed Red Pill keybinding and window rules from $BINDINGS_FILE"
# Remove live Hyprland bindings if running
if command -v hyprctl >/dev/null 2>&1 && hyprctl monitors -j &>/dev/null; then
hyprctl keyword unbind "SUPER ALT, B" >/dev/null 2>&1 || true
_ok "Removed live Hyprland keybinding"
fi
else
_skip "Hyprland keybinding in bindings.conf"
fi
# 5) Remove redpill-notify from Hyprland autostart
AUTOSTART_FILE="$HOME/.config/hypr/autostart.conf"
if [[ -f "$AUTOSTART_FILE" ]] && grep -q 'redpill-notify' "$AUTOSTART_FILE"; then
sed -i '/# Red Pill backup reminder on login/d' "$AUTOSTART_FILE"
sed -i '/exec-once = redpill-notify/d' "$AUTOSTART_FILE"
# Clean up any resulting double blank lines
sed -i '/^$/N;/^\n$/d' "$AUTOSTART_FILE"
_ok "Removed redpill-notify from $AUTOSTART_FILE"
else
_skip "redpill-notify in autostart.conf"
fi
# 6) Remove Walker custom command entry for RED PILL
WCONF="$HOME/.config/walker/config.toml"
if [[ -f "$WCONF" ]] && grep -q 'label = "RED PILL"' "$WCONF"; then
# Remove the [[builtins.custom_commands.entries]] block for RED PILL
if python3 -c "
import re, sys
wconf = sys.argv[1]
with open(wconf, 'r') as f:
content = f.read()
content = re.sub(
r'\n*\[\[builtins\.custom_commands\.entries\]\]\s*\n'
r'label = \"RED PILL\"\s*\n'
r'command = .*redpill.*\n'
r'keywords = .*\n'
r'icon = .*\n?',
'', content)
with open(wconf, 'w') as f:
f.write(content)
" "$WCONF" 2>/dev/null && ! grep -q 'label = "RED PILL"' "$WCONF"; then
_ok "Removed RED PILL entry from Walker config"
else
# Fallback: use sed to remove the lines
sed -i '/\[\[builtins\.custom_commands\.entries\]\]/{
N;N;N;N
/RED PILL/d
}' "$WCONF"
_ok "Removed RED PILL entry from Walker config (sed fallback)"
fi
else
_skip "RED PILL in Walker config"
fi
# 7) Kill walker to refresh
pkill -x walker >/dev/null 2>&1 || true
# 8) Ask about config and state directories
echo
_hr
echo
CONF_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/redpill"
STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/redpill"
printf ' %sOptional cleanup:%s\n' "$_c_bold" "$_c_reset"
printf ' Config: %s\n' "$CONF_DIR"
printf ' (includes.conf, excludes.conf, destination.conf, RECOVERY.txt)\n'
printf ' State: %s\n' "$STATE_DIR"
printf ' (local backup tarballs, last_backup timestamp)\n'
echo
read -r -p " Remove config and state directories? [y/N] " rm_data || rm_data=""
if [[ "${rm_data,,}" == "y" ]]; then
if [[ -d "$CONF_DIR" ]]; then
rm -rf "$CONF_DIR"
_ok "Removed $CONF_DIR"
else
_skip "$CONF_DIR"
fi
if [[ -d "$STATE_DIR" ]]; then
rm -rf "$STATE_DIR"
_ok "Removed $STATE_DIR"
else
_skip "$STATE_DIR"
fi
else
printf ' %sKept config and state directories.%s\n' "$_c_dim" "$_c_reset"
fi
echo
_hr
printf ' %s%sRed Pill has been uninstalled.%s\n' "$_c_bold" "$_c_green" "$_c_reset"
printf ' %sBackup snapshots on external drives were not modified.%s\n' "$_c_dim" "$_c_reset"
_hr
echo

2113
Redpill_update.sh Executable file

File diff suppressed because it is too large Load diff