#!/usr/bin/python3 """ Debian Runner Setup Tool Automatically sets up the appropriate runner for the current system Creates symbolic links like Fedora does """ import os import sys import subprocess from pathlib import Path def detect_system(): """Detect the current system and determine appropriate runner""" system_info = { 'distribution': 'unknown', 'version': 'unknown', 'codename': 'unknown', 'recommended_runner': 'org.osbuild.linux' } if os.path.exists('/etc/os-release'): with open('/etc/os-release', 'r') as f: content = f.read() # Extract distribution info if 'debian' in content.lower(): system_info['distribution'] = 'debian' # Extract codename import re codename_match = re.search(r'VERSION_CODENAME="?([^"\n]+)"?', content) if codename_match: codename = codename_match.group(1).lower() system_info['codename'] = codename # Map codename to runner if codename == 'trixie': system_info['recommended_runner'] = 'org.osbuild.debian13' elif codename == 'forky': system_info['recommended_runner'] = 'org.osbuild.debian14' elif codename == 'sid': system_info['recommended_runner'] = 'org.osbuild.debian-sid' else: system_info['recommended_runner'] = 'org.osbuild.debian' elif 'ubuntu' in content.lower(): system_info['distribution'] = 'ubuntu' # Extract version version_match = re.search(r'VERSION_ID="?([^"\n]+)"?', content) if version_match: version = version_match.group(1) system_info['version'] = version # Map version to runner if version == '25.04': system_info['recommended_runner'] = 'org.osbuild.ubuntu2504' elif version == '24.04': system_info['recommended_runner'] = 'org.osbuild.ubuntu2404' else: system_info['recommended_runner'] = 'org.osbuild.ubuntu1804' elif any(x in content.lower() for x in ['mint', 'pop', 'elementary', 'zorin', 'kali', 'parrot']): system_info['distribution'] = 'debian-based' system_info['recommended_runner'] = 'org.osbuild.debian-based' return system_info def setup_runner(system_info): """Setup the appropriate runner for the current system""" project_root = Path(__file__).parent.parent runners_dir = project_root / 'runners' # Get current system name (hostname or distribution) current_system = os.uname().nodename.lower() # Create runner name for current system runner_name = f"org.osbuild.{current_system}" runner_path = runners_dir / runner_name # Get recommended runner path recommended_runner = runners_dir / system_info['recommended_runner'] if not recommended_runner.exists(): print(f"āŒ Recommended runner {system_info['recommended_runner']} not found!") print(f" Available runners:") for runner in sorted(runners_dir.glob('org.osbuild.*')): if runner.is_file(): print(f" - {runner.name}") return False # Remove existing runner if it exists if runner_path.exists() or runner_path.is_symlink(): if runner_path.is_symlink(): runner_path.unlink() else: runner_path.unlink() # Create symbolic link try: runner_path.symlink_to(recommended_runner.name) print(f"āœ… Created runner: {runner_name} -> {system_info['recommended_runner']}") return True except Exception as e: print(f"āŒ Failed to create runner: {e}") return False def list_runners(): """List all available runners""" project_root = Path(__file__).parent.parent runners_dir = project_root / 'runners' print("Available Debian/Ubuntu Runners:") print("=" * 40) # Group runners by type debian_runners = [] ubuntu_runners = [] other_runners = [] for runner in sorted(runners_dir.glob('org.osbuild.*')): if runner.is_file(): name = runner.name if 'debian' in name and 'ubuntu' not in name: debian_runners.append(name) elif 'ubuntu' in name: ubuntu_runners.append(name) else: other_runners.append(name) print("🐧 Debian Runners:") for runner in debian_runners: print(f" {runner}") print("\n🦊 Ubuntu Runners:") for runner in ubuntu_runners: print(f" {runner}") print("\nšŸ”§ Other Runners:") for runner in other_runners: print(f" {runner}") print(f"\nTotal: {len(debian_runners) + len(ubuntu_runners) + len(other_runners)} runners") def main(): """Main function""" if len(sys.argv) > 1 and sys.argv[1] == 'list': list_runners() return print("šŸ” Debian Runner Setup Tool") print("=" * 40) # Detect system system_info = detect_system() print(f"Distribution: {system_info['distribution']}") print(f"Version: {system_info['version']}") print(f"Codename: {system_info['codename']}") print(f"Recommended runner: {system_info['recommended_runner']}") print() # Setup runner if setup_runner(system_info): print(f"\nšŸŽÆ Runner setup complete!") print(f" Your system '{os.uname().nodename}' now uses {system_info['recommended_runner']}") print(f" OSBuild will automatically use the appropriate runner for your system") else: print(f"\nāŒ Runner setup failed!") print(f" Use './tools/debian-runner-setup list' to see available runners") if __name__ == '__main__': main()