mirror of https://github.com/bohanyang/debi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.7 KiB
3.7 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Debi is a Debian Network Reinstall Script that allows reinstalling any VPS or physical machine to minimal Debian via network boot. It's a single POSIX-compliant shell script that automates the entire Debian installation process.
Commands
Running the Script
# Basic execution (requires root)
sudo ./debi.sh
# With options
sudo ./debi.sh --user debian --timezone UTC --cloudflare
# Dry run (generate config without installing)
sudo ./debi.sh --dry-run
# With cloud-init configuration
sudo ./debi.sh --cidata ./cidata-example/
Testing Changes
# Check shell script syntax
sh -n debi.sh
# Run shellcheck for linting (if available)
shellcheck debi.sh
# Test in a VM environment (recommended)
# No automated test suite exists - manual testing required
Architecture
The script operates in distinct phases:
- Configuration Phase: Parses command-line arguments and validates environment
- Download Phase: Fetches Debian installer components to
/boot/debian-$VERSION/ - Preseed Generation: Creates automated installation configuration
- GRUB Modification: Adds installer entry to bootloader menu
- Initramfs Injection: Embeds preseed and network configuration into installer
- Execution: Updates GRUB and prepares for reboot
Key architectural decisions:
- Single-file design for easy distribution
- POSIX compliance for maximum compatibility
- No external dependencies beyond standard Linux utilities
- Modular function design with clear separation of concerns
- Extensive error handling with rollback capabilities
Key Functions and Their Purposes
download(): Handles file downloads with proxy support and multiple backend options (wget/curl/busybox)set_debian_version()/set_suite(): Manages Debian version selection and mirror URLsconfigure_sshd(): Sets up SSH access during installation for remote monitoringin_target(): Executes commands within the target installation environmentprompt_password(): Securely handles password input with validation
Important Configuration Variables
The script uses 80+ configuration options. Key ones include:
$suite: Debian version (bookworm, bullseye, etc.)$mirror_protocol/$mirror_host: APT repository configuration$disk: Target installation disk$authorized_keys_url: SSH key provisioning$cidata: Cloud-init configuration directory
Development Guidelines
- Maintain POSIX compliance - Script must work with dash/sh, not just bash
- Test on real systems - No test suite exists; changes require VM or physical testing
- Preserve backward compatibility - Many users rely on specific option behaviors
- Document all options - Update README.md for any new configuration options
- Handle errors gracefully - Always provide rollback paths for critical operations
Common Development Tasks
Adding New Configuration Options
- Add option to the case statement in the argument parsing section
- Define corresponding variable with sensible default
- Implement logic in appropriate phase function
- Update README.md documentation
Debugging Installation Issues
- Use
--dry-runto generate and inspect preseed configuration - Enable network console with
--sshfor remote debugging - Check
/boot/debian-$VERSION/for downloaded components - Review GRUB configuration changes in
/boot/grub/grub.cfg
Testing Platform Compatibility
Focus areas for testing:
- Network configuration (static IP vs DHCP)
- Disk detection and partitioning
- GRUB installation and boot entries
- Architecture-specific installer components