# Dependency checking and validation for Ubuntu uBlue bootupd-alternative Tool check_dependencies() { log_info "Checking dependencies..." "bootupd-alternative" local missing_deps=() # Core dependencies for dep in mount umount lsblk bc; do if ! command -v "$dep" >/dev/null 2>&1; then missing_deps+=("$dep") fi done # Bootloader-specific dependencies local bootloader bootloader=$(detect_bootloader) case "$bootloader" in "uefi") if ! command -v efibootmgr >/dev/null 2>&1; then missing_deps+=("efibootmgr") fi ;; "grub") if ! command -v grub-install >/dev/null 2>&1; then missing_deps+=("grub-install") fi if ! command -v grub-mkconfig >/dev/null 2>&1; then missing_deps+=("grub-mkconfig") fi ;; "lilo") if ! command -v lilo >/dev/null 2>&1; then missing_deps+=("lilo") fi ;; "syslinux") if ! command -v syslinux >/dev/null 2>&1; then missing_deps+=("syslinux") fi ;; esac # Check for kernel modules check_kernel_modules if [ ${#missing_deps[@]} -ne 0 ]; then log_error "Missing dependencies: ${missing_deps[*]}" "bootupd-alternative" log_info "Install missing packages with: sudo apt install -y ${missing_deps[*]}" "bootupd-alternative" exit 1 fi log_success "All dependencies found" "bootupd-alternative" } # Check kernel modules check_kernel_modules() { log_info "Checking kernel modules..." "bootupd-alternative" local missing_modules=() # Check for squashfs module if ! modprobe -n squashfs >/dev/null 2>&1; then missing_modules+=("squashfs") fi # Check for overlay module if ! modprobe -n overlay >/dev/null 2>&1; then missing_modules+=("overlay") fi # Check for loop module if ! modprobe -n loop >/dev/null 2>&1; then missing_modules+=("loop") fi if [ ${#missing_modules[@]} -ne 0 ]; then log_warning "Missing kernel modules: ${missing_modules[*]}" "bootupd-alternative" log_info "Load modules with: sudo modprobe ${missing_modules[*]}" "bootupd-alternative" log_info "Or install with: sudo apt install linux-modules-extra-$(uname -r)" "bootupd-alternative" else log_success "All required kernel modules available" "bootupd-alternative" fi } # Check for bootloader integration script check_bootloader_integration() { local bootloader_script="/usr/local/bin/bootloader-integration.sh" if [[ -f "$bootloader_script" ]] && [[ -x "$bootloader_script" ]]; then log_debug "Bootloader integration script found: $bootloader_script" "bootupd-alternative" return 0 else log_warning "Bootloader integration script not found or not executable: $bootloader_script" "bootupd-alternative" log_info "Advanced bootloader features will not be available" "bootupd-alternative" return 1 fi } # Check for composefs integration script check_composefs_integration() { local composefs_script="/usr/local/bin/composefs-alternative.sh" if [[ -f "$composefs_script" ]] && [[ -x "$composefs_script" ]]; then log_debug "ComposeFS integration script found: $composefs_script" "bootupd-alternative" return 0 else log_warning "ComposeFS integration script not found or not executable: $composefs_script" "bootupd-alternative" log_info "ComposeFS-based boot images will not be available" "bootupd-alternative" return 1 fi } # Validate boot device validate_boot_device() { local device="$1" # Check if device exists if [[ ! -b "$device" ]]; then log_error "Boot device does not exist: $device" "bootupd-alternative" return 1 fi # Check if device is readable if [[ ! -r "$device" ]]; then log_error "Boot device is not readable: $device" "bootupd-alternative" return 1 fi # Check if device has boot partition local has_boot_partition=false while IFS= read -r line; do if [[ "$line" =~ boot ]] || [[ "$line" =~ efi ]]; then has_boot_partition=true break fi done < <(lsblk -o MOUNTPOINT "$device" 2>/dev/null) if [[ "$has_boot_partition" == "false" ]]; then log_warning "No boot partition detected on device: $device" "bootupd-alternative" log_info "This may be expected for some configurations" "bootupd-alternative" fi return 0 } # Check available disk space check_disk_space() { local required_space_mb="$1" local target_dir="${2:-$BOOTUPD_DIR}" local available_space_mb available_space_mb=$(get_available_space "$target_dir") if [[ $available_space_mb -lt $required_space_mb ]]; then log_error "Insufficient disk space: ${available_space_mb}MB available, need ${required_space_mb}MB" "bootupd-alternative" return 1 fi log_debug "Disk space check passed: ${available_space_mb}MB available" "bootupd-alternative" return 0 } # Check if system is bootable check_system_bootability() { log_info "Checking system bootability..." "bootupd-alternative" local bootloader bootloader=$(detect_bootloader) case "$bootloader" in "uefi") # Check for UEFI firmware if [[ ! -d "/sys/firmware/efi" ]]; then log_error "UEFI firmware not detected" "bootupd-alternative" return 1 fi # Check for EFI partition if ! mountpoint -q /boot/efi 2>/dev/null; then log_warning "EFI partition not mounted at /boot/efi" "bootupd-alternative" fi ;; "grub") # Check for GRUB configuration if [[ ! -f "/boot/grub/grub.cfg" ]] && [[ ! -f "/boot/grub2/grub.cfg" ]]; then log_warning "GRUB configuration not found" "bootupd-alternative" fi ;; "lilo") # Check for LILO configuration if [[ ! -f "/etc/lilo.conf" ]]; then log_warning "LILO configuration not found" "bootupd-alternative" fi ;; "syslinux") # Check for syslinux configuration if [[ ! -f "/boot/syslinux/syslinux.cfg" ]]; then log_warning "syslinux configuration not found" "bootupd-alternative" fi ;; "unknown") log_warning "Unknown bootloader type" "bootupd-alternative" ;; esac log_info "System bootability check completed" "bootupd-alternative" return 0 } # Check for required filesystems check_filesystems() { log_info "Checking required filesystems..." "bootupd-alternative" # Check for /boot if [[ ! -d "/boot" ]]; then log_error "/boot directory not found" "bootupd-alternative" return 1 fi # Check for /boot/efi (UEFI systems) if [[ -d "/sys/firmware/efi" ]] && [[ ! -d "/boot/efi" ]]; then log_warning "EFI directory not found at /boot/efi" "bootupd-alternative" fi # Check for /etc/fstab if [[ ! -f "/etc/fstab" ]]; then log_warning "/etc/fstab not found" "bootupd-alternative" fi log_success "Filesystem check completed" "bootupd-alternative" return 0 }