Some checks failed
particle-os CI / Test particle-os (push) Failing after 1s
particle-os CI / Integration Test (push) Has been skipped
particle-os CI / Security & Quality (push) Failing after 1s
Test particle-os Basic Functionality / test-basic (push) Failing after 1s
particle-os CI / Build and Release (push) Has been skipped
276 lines
8.2 KiB
Bash
Executable file
276 lines
8.2 KiB
Bash
Executable file
#!/bin/bash
|
||
# Integration script using the working alternative solution
|
||
# Creates complete Debian Atomic pipeline: treefile → debootstrap + ostree → bootable image
|
||
|
||
set -euo pipefail
|
||
|
||
# Colors for output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m' # No Color
|
||
|
||
# Configuration
|
||
WORKSPACE_PATH="/home/rob/Documents/Projects/overseer"
|
||
DEB_BOOTC_PATH="$WORKSPACE_PATH/deb-bootc-image-builder"
|
||
ATOMIC_CONFIGS_PATH="$WORKSPACE_PATH/debian-atomic-configs"
|
||
TEMP_DIR=$(mktemp -d /tmp/debian-atomic-alt-XXXXXX)
|
||
|
||
# Functions
|
||
log_info() {
|
||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||
}
|
||
|
||
log_success() {
|
||
echo -e "${GREEN}✅ $1${NC}"
|
||
}
|
||
|
||
log_warning() {
|
||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||
}
|
||
|
||
log_error() {
|
||
echo -e "${RED}❌ $1${NC}"
|
||
}
|
||
|
||
cleanup() {
|
||
log_info "Cleaning up temporary files..."
|
||
if [[ -d "$TEMP_DIR" ]]; then
|
||
rm -rf "$TEMP_DIR"
|
||
fi
|
||
}
|
||
|
||
# Set up cleanup on exit
|
||
trap cleanup EXIT
|
||
|
||
# Validate paths
|
||
validate_paths() {
|
||
log_info "Validating required components..."
|
||
|
||
local missing_paths=()
|
||
|
||
[[ ! -d "$DEB_BOOTC_PATH" ]] && missing_paths+=("deb-bootc-image-builder")
|
||
[[ ! -d "$ATOMIC_CONFIGS_PATH" ]] && missing_paths+=("debian-atomic-configs")
|
||
|
||
if [[ ${#missing_paths[@]} -gt 0 ]]; then
|
||
log_error "Missing required components: ${missing_paths[*]}"
|
||
exit 1
|
||
fi
|
||
|
||
log_success "All required components found"
|
||
}
|
||
|
||
# Build deb-bootc-image-builder if needed
|
||
build_deb_bootc() {
|
||
local bib_bin="$DEB_BOOTC_PATH/bib/create-ostree-bootable-image"
|
||
|
||
if [[ ! -f "$bib_bin" ]]; then
|
||
log_info "Building deb-bootc-image-builder..."
|
||
cd "$DEB_BOOTC_PATH"
|
||
|
||
if ! go build -o bib/create-ostree-bootable-image ./bib/create-ostree-bootable-image.go; then
|
||
log_error "Failed to build deb-bootc-image-builder"
|
||
exit 1
|
||
fi
|
||
|
||
log_success "deb-bootc-image-builder built successfully"
|
||
else
|
||
log_info "deb-bootc-image-builder binary found, skipping build"
|
||
fi
|
||
}
|
||
|
||
# Step 1: Create OSTree commit using alternative solution (debootstrap + ostree)
|
||
create_ostree_commit() {
|
||
local variant="$1"
|
||
|
||
log_info "Step 1: Creating OSTree commit using alternative solution (debootstrap + ostree)"
|
||
|
||
cd "$TEMP_DIR"
|
||
|
||
# Run the alternative solution script
|
||
log_info "Running create-debian-atomic.py for variant: $variant"
|
||
|
||
if ! distrobox-enter debian-trixie -- bash -c "cd '$TEMP_DIR' && sudo python3 '$ATOMIC_CONFIGS_PATH/create-debian-atomic.py' '$variant'"; then
|
||
log_error "Failed to create OSTree commit using alternative solution"
|
||
return 1
|
||
fi
|
||
|
||
log_success "OSTree commit created successfully using alternative solution"
|
||
|
||
# The script cleans up automatically, so we need to run it again to keep the repository
|
||
# Let's run it with a persistent work directory
|
||
local persistent_dir="$TEMP_DIR/persistent-build"
|
||
log_info "Creating persistent build in: $persistent_dir"
|
||
|
||
if ! distrobox-enter debian-trixie -- bash -c "cd '$TEMP_DIR' && sudo python3 '$ATOMIC_CONFIGS_PATH/create-debian-atomic.py' '$variant' '$persistent_dir'"; then
|
||
log_error "Failed to create persistent OSTree commit"
|
||
return 1
|
||
fi
|
||
|
||
# Verify the repository was created
|
||
local repo_path="$persistent_dir/repo"
|
||
if [[ ! -d "$repo_path" ]]; then
|
||
log_error "OSTree repository not found at $repo_path"
|
||
return 1
|
||
fi
|
||
|
||
# Get commit information
|
||
local refs_dir="$repo_path/refs"
|
||
if [[ ! -d "$refs_dir" ]]; then
|
||
log_error "No refs directory found"
|
||
return 1
|
||
fi
|
||
|
||
# Find the reference file
|
||
local ref_file
|
||
ref_file=$(find "$refs_dir" -type f -name "*$variant*" | head -1)
|
||
if [[ -z "$ref_file" ]]; then
|
||
log_error "No reference found for variant $variant"
|
||
return 1
|
||
fi
|
||
|
||
local commit_id
|
||
commit_id=$(cat "$ref_file")
|
||
log_info "Found commit: $commit_id"
|
||
|
||
# Verify the commit exists
|
||
local objects_dir="$repo_path/objects"
|
||
local commit_path="$objects_dir/${commit_id:0:2}/${commit_id:2}"
|
||
if [[ ! -d "$commit_path" ]]; then
|
||
log_error "Commit object not found at $commit_path"
|
||
return 1
|
||
fi
|
||
|
||
log_success "Successfully created commit: $commit_id"
|
||
echo "$commit_id"
|
||
}
|
||
|
||
# Step 2: Extract rootfs from OSTree commit and create bootable image
|
||
create_bootable_image() {
|
||
local commit_id="$1"
|
||
local repo_path="$TEMP_DIR/persistent-build/repo"
|
||
|
||
log_info "Step 2: Creating bootable image from OSTree commit"
|
||
|
||
cd "$TEMP_DIR"
|
||
|
||
# Extract the rootfs from the OSTree commit
|
||
local rootfs_path="$TEMP_DIR/rootfs"
|
||
log_info "Extracting rootfs from OSTree commit..."
|
||
|
||
# Use ostree to checkout the commit to a directory
|
||
if ! ostree checkout --repo="$repo_path" --subpath=/ "$commit_id" "$rootfs_path"; then
|
||
log_error "Failed to extract rootfs from OSTree commit"
|
||
return 1
|
||
fi
|
||
|
||
log_success "Rootfs extracted to: $rootfs_path"
|
||
|
||
# Verify rootfs structure
|
||
if [[ ! -d "$rootfs_path/usr" ]] || [[ ! -d "$rootfs_path/etc" ]]; then
|
||
log_error "Invalid rootfs structure"
|
||
return 1
|
||
fi
|
||
|
||
# Create bootable image using deb-bootc-image-builder
|
||
local bib_bin="$DEB_BOOTC_PATH/bib/create-ostree-bootable-image"
|
||
local output_image="$TEMP_DIR/debian-atomic.img"
|
||
|
||
log_info "Creating bootable image from rootfs..."
|
||
if ! "$bib_bin" "$rootfs_path" "$output_image"; then
|
||
log_error "Failed to create bootable image"
|
||
return 1
|
||
fi
|
||
|
||
log_success "Bootable image created successfully"
|
||
|
||
# Check if image was created
|
||
if [[ ! -f "$output_image" ]]; then
|
||
log_error "Output image not found: $output_image"
|
||
return 1
|
||
fi
|
||
|
||
# Show image information
|
||
local image_size=$(du -h "$output_image" | cut -f1)
|
||
log_info "Image created: $output_image ($image_size)"
|
||
|
||
echo "$output_image"
|
||
}
|
||
|
||
# Main pipeline function
|
||
run_pipeline() {
|
||
local variant="$1"
|
||
|
||
log_info "🚀 Starting Debian Atomic pipeline (Alternative Solution)"
|
||
log_info "Variant: $variant"
|
||
log_info "Working directory: $TEMP_DIR"
|
||
|
||
# Step 1: Create OSTree commit using alternative solution
|
||
log_info "Executing Step 1: Create OSTree commit using alternative solution..."
|
||
local commit_id
|
||
if ! commit_id=$(create_ostree_commit "$variant"); then
|
||
log_error "Step 1 failed: Could not create OSTree commit"
|
||
return 1
|
||
fi
|
||
|
||
log_success "Step 1 completed: OSTree commit $commit_id created"
|
||
|
||
# Step 2: Create bootable image
|
||
log_info "Executing Step 2: Create bootable image..."
|
||
local output_image
|
||
if ! output_image=$(create_bootable_image "$commit_id"); then
|
||
log_error "Step 2 failed: Could not create bootable image"
|
||
return 1
|
||
fi
|
||
|
||
log_success "Step 2 completed: Bootable image created"
|
||
|
||
log_success "🎉 Pipeline completed successfully!"
|
||
log_info "Output image: $output_image"
|
||
|
||
# Copy image to workspace for easy access
|
||
local final_image="$WORKSPACE_PATH/debian-atomic-$variant-alternative.img"
|
||
cp "$output_image" "$final_image"
|
||
log_info "Image copied to: $final_image"
|
||
|
||
# Show testing instructions
|
||
echo
|
||
log_info "🧪 To test the image:"
|
||
echo "qemu-system-x86_64 -m 2G -drive file=$final_image,format=raw -nographic"
|
||
echo
|
||
log_info "📋 Summary:"
|
||
log_success "✅ OSTree commit created using alternative solution (debootstrap + ostree)"
|
||
log_success "✅ Bootable image created: $final_image"
|
||
log_success "✅ Debian Atomic pipeline completed successfully using alternative solution!"
|
||
|
||
return 0
|
||
}
|
||
|
||
# Main function
|
||
main() {
|
||
if [[ $# -lt 1 ]]; then
|
||
echo "Usage: $0 <variant>"
|
||
echo "Example: $0 minimal"
|
||
echo
|
||
echo "Available variants: minimal, gnome, plasma, cosmic, sway, budgie"
|
||
exit 1
|
||
fi
|
||
|
||
local variant="$1"
|
||
|
||
# Validate and build components
|
||
validate_paths
|
||
build_deb_bootc
|
||
|
||
# Run the pipeline
|
||
if ! run_pipeline "$variant"; then
|
||
log_error "Pipeline failed"
|
||
exit 1
|
||
fi
|
||
|
||
log_success "Pipeline completed successfully"
|
||
}
|
||
|
||
# Run main function
|
||
main "$@"
|