forked from tfgrid/zosbuilder
- Fix container output visibility with proper TTY handling and debug mode - Fix build order: kernel modules built before initramfs creation - Implement two-stage kernel build to resolve chicken-and-egg dependency - Fix sed command issues in kernel configuration with direct execution - Add diffutils package to container for proper kernel build support - Enhance NIC module/firmware correlation with intelligent selection - Fix module staging logic: all NICs loaded in stage1 before network up - Add smart firmware installation based on module requirements - Create comprehensive function documentation (scripts/functionlist.md) - Add debug container script for troubleshooting Major fixes: * Container builds now show real-time output * Kernel builds work with proper GNU diff support * Module/firmware selection optimized for common hardware * Build process handles dependencies correctly * Documentation provides complete function reference
8.9 KiB
8.9 KiB
Function List - scripts/lib Library
This document provides a comprehensive description of all functions available in the scripts/lib library that are to be sourced by build scripts.
alpine.sh - Alpine Linux Operations
Core Functions
alpine_extract_miniroot()- Downloads and extracts Alpine miniroot to target directoryalpine_setup_chroot()- Sets up chroot environment with essential filesystem mountsalpine_cleanup_chroot()- Unmounts and cleans up chroot environmentalpine_install_packages()- Installs packages from packages.list (excludes OpenRC)alpine_aggressive_cleanup()- Removes documentation, locales, dev files for size optimizationalpine_configure_repos()- Configures Alpine package repositoriesalpine_configure_system()- Sets up basic system configuration (hostname, hosts, timezone)alpine_install_firmware()- Installs firmware packages for hardware support
common.sh - Core Utilities
Logging Functions
log_info()- Log informational messages with timestamp and colorlog_warn()- Log warning messages with timestamp and colorlog_error()- Log error messages with timestamp and colorlog_debug()- Log debug messages (only when DEBUG=1)
Execution and System Functions
safe_execute()- Execute commands with error handling and loggingsection_header()- Creates formatted section headers for outputcommand_exists()- Check if command is available in PATHin_container()- Detect if running inside a containercheck_dependencies()- Verify required tools are installed
File System Operations
safe_mkdir()- Create directories safely with error handlingsafe_rmdir()- Remove directories safely with error handlingsafe_copy()- Copy files/directories safely with error handlingresolve_path()- Convert relative to absolute pathsget_file_size()- Get human-readable file sizewait_for_file()- Wait for file to exist with timeoutcleanup_on_exit()- Cleanup function for exit traps
components.sh - ThreeFold Component Management
Component Processing
components_parse_sources_conf()- Parse and build all components from sources.confcomponents_download_git()- Clone Git repositories with specific versionscomponents_download_release()- Download pre-built release binariescomponents_process_extra_options()- Handle rename/extract options for componentscomponents_build_component()- Build component using specified build function
Build Environment
components_setup_rust_env()- Configure Rust environment for musl builds
Component-Specific Build Functions
build_zinit()- Build zinit init system from source (Rust)build_rfs()- Build rfs (rootfs) from source (Rust)build_mycelium()- Build mycelium networking from source (Rust, subdirectory)install_rfs()- Install pre-built rfs binaryinstall_corex()- Install pre-built corex binary
Verification and Cleanup
components_verify_installation()- Verify all components were installed correctlycomponents_cleanup()- Clean build artifacts
docker.sh - Container Runtime Management
Runtime Detection and Setup
docker_detect_runtime()- Detect available container runtime (Docker/Podman)docker_verify_rootless()- Verify rootless container setup worksdocker_check_capabilities()- Check container runtime capabilitiesdocker_setup_rootless()- Setup rootless environment (subuid/subgid)
Container Image Management
docker_build_container()- Build container image with build toolsdocker_create_dockerfile()- Create optimized Dockerfile for build environmentdocker_commit_builder()- Commit container state for reusedocker_cleanup()- Clean up container images
Container Execution
docker_start_rootless()- Start rootless container for buildingdocker_run_build()- Run build command in container with proper mounts
initramfs.sh - Initramfs Assembly
Core Assembly Functions
initramfs_setup_zinit()- Setup zinit as init system (replaces OpenRC completely)initramfs_install_init_script()- Install critical /init script for initramfs bootinitramfs_setup_modules()- Setup 2-stage module loading with dependencies
Module Management
initramfs_resolve_module_dependencies()- Recursively resolve module dependencies using modinfoinitramfs_create_module_scripts()- Create stage1/stage2 module loading scripts for zinit
Optimization and Packaging
initramfs_strip_and_upx()- Strip debug symbols and UPX compress binaries for size optimizationinitramfs_create_cpio()- Create final compressed initramfs archive (xz/gzip/zstd/uncompressed)
Validation and Testing
initramfs_validate()- Validate initramfs contents and structureinitramfs_test_archive()- Test initramfs archive integrity
kernel.sh - Kernel Building
Source Management
kernel_download_source()- Download Linux kernel source code from kernel.orgkernel_apply_config()- Apply kernel configuration with embedded initramfs pathkernel_modify_config_for_initramfs()- Modify kernel config for embedded initramfs support
Build Functions
kernel_build_with_initramfs()- Build kernel with embedded initramfs (complete process)kernel_build_modules()- Build kernel modules for initramfs inclusion
Cleanup
kernel_cleanup()- Clean kernel build artifacts (with option to keep source)
testing.sh - Virtualization Testing
QEMU Testing
testing_qemu_boot()- Test kernel boot with QEMU (multiple modes: basic/serial/interactive)testing_qemu_basic_boot()- Basic automated QEMU boot test with timeouttesting_qemu_serial_boot()- QEMU serial console test for debuggingtesting_qemu_interactive_boot()- Interactive QEMU session (no timeout)
Cloud Hypervisor Testing
testing_cloud_hypervisor_boot()- Test with cloud-hypervisor VMMtesting_cloud_hypervisor_basic()- Basic cloud-hypervisor test with timeouttesting_cloud_hypervisor_serial()- cloud-hypervisor serial console test
Analysis and Orchestration
testing_analyze_boot_log()- Analyze boot logs for success/failure indicatorstesting_run_all()- Run comprehensive test suite (QEMU + cloud-hypervisor)
Usage Notes
Function Availability
All functions are exported for sourcing and can be called from any script that sources the respective library file. The common pattern is:
# Source the library
source "${SCRIPT_DIR}/lib/common.sh"
source "${SCRIPT_DIR}/lib/alpine.sh"
# ... other libraries as needed
# Use the functions
alpine_extract_miniroot "/path/to/target"
components_parse_sources_conf "/path/to/sources.conf" "/path/to/components"
Error Handling
All functions follow consistent error handling patterns:
- Return non-zero exit codes on failure
- Use
safe_execute()for command execution - Provide detailed logging via
log_*()functions - Clean up resources on failure
Dependencies
Functions have dependencies on:
- External tools (checked via
check_dependencies()) - Other library functions (noted in function descriptions)
- Configuration files and environment variables
- Proper directory structures
Configuration
Most functions respect environment variables for configuration:
DEBUG=1enables debug loggingALPINE_VERSION,KERNEL_VERSIONset versionsRUST_TARGETconfigures Rust builds- Various
*_DIRvariables set paths