Files
debianito-post-install/docs/repos_config.md
T
stornic56 53088aad4b Docs Update
- ZRAM Scaling (docs/QUICKSTART.md): Updated Step 9 with the current fixed-4096MB formula: `≤8 GB → 50%`, `>8 GB → 4096 MB fixed`. Replaced obsolete `ram_gb > 16 ? 25% : 50%` and `/4` vs `/2` logic with the new behavior (`ram_gb <= 8 ? 50% : 4096 MB`). Examples: 4GB → 2048 MB, 8GB → 4096 MB, 16GB → 4096 MB, 32GB → 4096 MB.

- GPU Configuration (docs/gpu.md): Added AMD GCN Migration subsection with duplicate guard (`content_differs-style` check) and sed fix logic. Added Secure Boot warning for NVIDIA DKMS (`mokutil --sb-state` detection). Documented `|| return 1` protection for `/etc/modprobe.d/nvidia-wayland.conf` writing. Renumbered duplicate sections 7 → 8 → 9 to avoid duplicate headings.

- Firmware Installation (docs/firmware.md): Updated Broadcom section with `_run_cmd` wrappers (`|| true`) for `apt install broadcom-sta-dkms` and `modprobe wl`. Added SSH network warning (`WARNING: SSH is not recommended on a router`) before `modprobe -r`. Updated Initramfs step with `_run_cmd` wrapper (`|| true`).

- Repo Configuration (docs/repos_config.md): Removed `REPOS_CONFIGURED=true` from the POST-EXECUTION PHASE diagram and Safety Mechanisms. Added `_write_branch_sources` with its `_restore_backup` rollback and "Branch Migration Rollback" safety note to the diagram.

- System Info & Pre-flight (docs/system_info.md): Added pre-flight init (auto-install whiptail + lsb-release). Added LSPCI_OUTPUT cache with `command -v lspci` guard. Added `_ensure_apt_updated` deduplication helper. Added `STATE_REFRESHED=true` flag mechanism across all menu branches.

- User Home Ownership (docs/user_priv_feed.md): Updated Option 3 (Repair Home Ownership) to use `getent passwd "${SUDO_USER:-$USER}"` instead of the insecure `eval echo "~$USER"` pattern. Added documentation note explaining the security rationale.

- QuickStart ZRAM (docs/QUICKSTART.md): Updated Step 9 ZRAM scaling to "50% of RAM (≤8 GB) or 4096 MB fixed (>8 GB)".
2026-09-12 16:53:10 -05:00

304 lines
17 KiB
Markdown

# Option 4: Repository Configuration
### 1. What Does This Component Do?
The repository configuration module is the foundational engine of Debianito that establishes and maintains a secure, up-to-date package management environment for your Debian system. It performs **idempotent, atomic operations** to configure APT sources with precision while protecting against corruption through automatic rollback mechanisms.
At its core, this component:
- Detects your current repository format (Classic `.list` vs modern DEB822 `.sources`)
- Backs up existing configurations before any modifications
- Enables critical non-free components required for hardware drivers and proprietary software
- Integrates Debian Backports to access newer kernels and firmware packages
- Validates changes through `apt update` with automatic restoration on failure
This is not just about "adding repositories"—it's about **system integrity assurance** that enables all other configuration options (GPU drivers, kernel upgrades, gaming setup) to function correctly.
---
### 2. Supported Injection Formats
The script intelligently adapts to your Debian version and existing repository structure:
#### Classic Format (`/etc/apt/sources.list`)
- **Structure**: Human-readable text with `deb` lines
- **Use Case**: Debian 11 (Bullseye) through Debian 12 (Bookworm) default
- **Characteristics**: Linear, comment-friendly, widely understood by all APT tools
- **Example**:
```bash
deb https://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
```
#### Modern DEB822 Format (`/etc/apt/sources.list.d/debian.sources`)
- **Structure**: Declarative YAML-like format with `Types`, `URIs`, and `Suites` blocks
- **Use Case**: Debian 13 (Trixie) default, future-proofing for newer releases
- **Characteristics**: Machine-parseable, structured, supports complex repository hierarchies
- **Example**:
```yaml
Types: deb
URIs: https://deb.debian.org/debian
Suites: trixie trixie-updates
Components: main contrib non-free non-free-firmware
```
#### Migration Logic
The script automatically detects your current format and offers migration options:
- On Debian 13 (Trixie): Prompts to migrate TO DEB822 or stay with Classic
- Format changes are atomic—backup is created before any modification
- Old files are renamed with `.disabled` extension rather than deleted
---
### 3. Logical Decision Tree (Step-by-Step Execution Flow)
The `configure_repos()` function in `repos.sh` executes the following sequence:
```bash
┌─────────────────────────────────────────────────────────────┐
│ INITIAL DETECTION PHASE │
├─────────────────────────────────────────────────────────────┤
│ 1. Detect Debian Codename (DEBIAN_CODENAME)
│ └── If empty → Abort with error │
│ │
│ 2. Detect Current Format │
│ ├── detect_repo_format()"deb822" | "classic" | "none"
│ └── Display: "Current format: [format]"
│ │
│ 3. Detect Backports Status │
│ ├── detect_backports_status() → enabled/disabled │
│ └── Detect Location: embedded vs standalone │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ USER INTERACTION PHASE │
├─────────────────────────────────────────────────────────────┤
│ 4. Repository Menu Loop (while true)
│ └── _menu: Select action from multiple options │
│ │
│ Options Available: │
│ ├── Debian 13+ (Trixie): │
│ │ ├── 1. Enable Contrib & Non-Free Components │
│ │ ├── 2. Migrate traditional sources.list to DEB822 │
│ │ ├── 3. Setup/Update Backports repositories │
│ │ ├── 4. [ADVANCED] Upgrade system branch (Testing/SID)
│ │ └── 5. Back to main menu │
│ │
│ └── Other Versions: │
│ ├── 1-3 same as above │
│ └── No option 4 (branch upgrade not available)
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ DECISION MATRIX PHASE │
├─────────────────────────────────────────────────────────────┤
│ 5. Determine Action Type (per menu selection)
│ ├── If format changed → "migrate"
│ ├── If nothing changed → "skip" (idempotent)
│ └── Otherwise → "write"
│ │
│ 6. Idempotency Check │
│ └── content_differs() compares generated vs existing │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ EXECUTION PHASE │
├─────────────────────────────────────────────────────────────┤
│ 7. Backup Current Repositories │
│ └── backup_current_repos() → temp directory │
│ │
│ 8. Write Configuration │
│ ├── _write_deb822() OR _write_classic()
│ ├── Creates appropriate file(s)
│ └── Includes main + backports if enabled │
│ │
│ 8b. Branch Migration (if applicable)
│ ├── _write_branch_sources() → writes new branch sources │
│ ├── If failure → _restore_backup() || true
│ └── return 1
│ │
│ 9. Update Package Lists │
│ └── sudo apt update │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ POST-EXECUTION PHASE │
├─────────────────────────────────────────────────────────────┤
│ 10. Success Path │
│ ├── Cleanup disabled files │
│ └── Optional: Upgrade system if packages available │
│ │
│ 11. Failure Path (apt update failed)
│ └── restore_previous_repos() → rollback to backup │
└─────────────────────────────────────────────────────────────┘
```
**Key Safety Mechanisms:**
- **Atomic Operations**: Backup created before any write operation
- **Idempotency Check**: `content_differs()` prevents unnecessary modifications
- **Rollback on Failure**: If `apt update` fails, original configuration is restored via `restore_previous_repos()`
- **Branch Migration Rollback**: `_write_branch_sources()` failure triggers `_restore_backup() || true`
- **Disabled File Extension**: Old formats renamed with `.disabled` rather than deleted
---
### 4. Software Components Activated
The script enables specific APT component branches that are essential for hardware functionality and software availability:
| Component | Purpose | Critical For | Debian Version Notes |
| ----------- | --------- | -------------- | --------------------- |
| **main** | Free, open-source software (Debian official) | All packages | Always enabled |
| **contrib** | Free software that uses non-free components | Proprietary codecs, drivers | Enabled in all versions |
| **non-free** | Non-free firmware and proprietary software | NVIDIA GPU drivers, Wi-Fi firmware | Required for hardware support |
| **non-free-firmware** | Firmware blobs (Wi-Fi, Bluetooth, etc.) | Wireless adapters, embedded chips | **Critical from Debian 12+** |
#### Why `non-free-firmware` is Vital (Debian 12+)
Starting with Debian Bookworm (12.0), the `non-free-firmware` component was separated into its own repository branch:
```bash
# Before Debian 12 (Bookworm)
deb https://deb.debian.org/debian bullseye main contrib non-free
# After Debian 12 (Bookworm+) - SEPARATE COMPONENTS
deb https://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
```
**Impact of Missing `non-free-firmware`:**
- ❌ Wi-Fi adapters won't work without firmware blobs
- ❌ Bluetooth devices may fail to initialize
- ❌ Some GPU drivers require proprietary microcode
- ❌ Embedded hardware (Raspberry Pi, etc.) becomes unusable
The script ensures all four components are present because:
1. **Hardware Compatibility**: Modern Debian kernels depend on these for out-of-the-box functionality
2. **Security Updates**: `non-free-firmware` receives security patches separately
3. **Future-Proofing**: Newer hardware releases firmware in this component exclusively
---
### 5. Support for Debian Backports
The backports integration is a sophisticated feature that enables access to newer, tested packages without compromising system stability:
#### Detection Logic (`detect_backports_status` & `detect_backports_location`)
```bash
# Checks ALL possible locations for backports configuration
├── /etc/apt/sources.list.d/debian-backports.sources (DEB822 standalone)
├── /etc/apt/sources.list.d/debian-backports.list (Classic standalone)
├── /etc/apt/sources.list.d/debian.sources (Embedded in DEB822)
└── /etc/apt/sources.list (Embedded in Classic)
```
**Return Values:**
- `"standalone-deb822"` → Separate `.sources` file (recommended)
- `"standalone-classic"` → Separate `.list` file
- `"embedded-deb822"` → Inside `debian.sources`
- `"embedded-classic"` → Inside `sources.list`
- `"none"` → Not configured
#### Backports Injection Process
```bash
┌─────────────────────────────────────────────────────────────┐
│ 1. User Selects: Enable Backports? │
│ └── whiptail confirm with explanation │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ 2. Determine Format │
│ ├── If DEB822 → _write_deb822_backports()
│ └── If Classic → _write_classic_backports()
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ 3. Create Backports File │
│ ├── Location: /etc/apt/sources.list.d/ │
│ └── Name: debian-backports.sources or .list │
│ │
│ Content Example (DEB822): │
│ Types: deb │
│ URIs: https://deb.debian.org/debian │
│ Suites: bookworm-backports │
│ Components: main contrib non-free non-free-firmware │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ 4. Cleanup Embedded Backports (Safety Net)
│ └── If backports existed in main file, remove them │
└─────────────────────────────────────────────────────────────┘
```
#### Why Enable Backports?
The script includes a detailed explanation because backports enable critical features:
| Feature | Without Backports | With Backports |
| --------- | ------------------- | ---------------- |
| **Linux Kernel** | Stable kernel only (e.g., 6.1-6.12) | Newer kernels (e.g., 6.x/7.x series) |
| **GPU "Drivers"** | Latest Mesa from stable | Latest Mesa from testing |
| **Wi-Fi Firmware** | Older firmware versions | Newest firmware for modern cards |
| **System Stability** | Maximum stability | Tested-but-newer packages |
#### Backports Warning System
The script includes safeguards:
- Only enabled if user explicitly confirms
- Warns about potential compatibility issues
- Can be disabled anytime via Option 3 again
- Automatically detected in other modules (kernel, GPU)
---
### Technical Implementation Notes
**Idempotency Guarantee:**
```bash
# content_differs() ensures no duplicate writes
if [ "$current" = "$generated" ]; then
return 1 # No changes needed
fi
return 0 # Changes required
```
**Atomic Backup Mechanism:**
```bash
backup_current_repos() {
REPO_BACKUP_DIR=$(mktemp -d)
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.sources; do
cp "$f" "$REPO_BACKUP_DIR/" 2>/dev/null || true
done
}
# Rollback on failure:
restore_previous_repos() {
sudo cp "$backup_file" "$original_path" # Restore from temp backup
rm -rf "$REPO_BACKUP_DIR" # Clean up after success/failure
}
```
**Component Activation Pattern:**
All four components are written in a single operation to prevent partial configurations:
```bash
Components: main contrib non-free non-free-firmware # Atomic write
# Not written as separate lines to avoid merge conflicts
```
---