Lots of fixes
details details details
This commit is contained in:
@@ -33,6 +33,7 @@ RUN apk add --no-cache \
|
||||
grep \
|
||||
findutils \
|
||||
jq \
|
||||
diffutils \
|
||||
# Go for source compilation
|
||||
go \
|
||||
# Rustup for proper Rust musl builds
|
||||
|
||||
@@ -15,6 +15,7 @@ findutils
|
||||
grep
|
||||
sed
|
||||
coreutils
|
||||
diffutils
|
||||
|
||||
# Crypto and certificates
|
||||
openssl
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
BOOT_ROOT="/build/boot"
|
||||
@@ -72,7 +72,7 @@ chmod 600 "$BOOT_ROOT/dev/console"
|
||||
echo "[+] Creating boot init script..."
|
||||
# Create minimal init script for mounting Alpine runtime
|
||||
cat > "$BOOT_ROOT/init" << 'EOF'
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# Minimal boot init - establish network and mount Alpine runtime
|
||||
|
||||
echo "[BOOT] Zero-OS minimal boot starting..."
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "====================================="
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
KERNEL_DIR="/build/kernel"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
CACHE_DIR="/build/cache"
|
||||
|
||||
180
scripts/cleanup.sh
Executable file
180
scripts/cleanup.sh
Executable file
@@ -0,0 +1,180 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "====================================="
|
||||
echo "= Alpine Zero-OS Cleanup Script ="
|
||||
echo "====================================="
|
||||
echo ""
|
||||
|
||||
# Define directories and files to clean
|
||||
OUTPUT_DIR="/build/output"
|
||||
KERNEL_DIR="/build/kernel"
|
||||
CACHE_DIR="/build/cache"
|
||||
BOOT_ROOT="/build/boot"
|
||||
ALPINE_ROOT="/build/initramfs"
|
||||
COMPONENTS_DIR="/build/components"
|
||||
|
||||
# Function to safely remove directory with size info
|
||||
cleanup_dir() {
|
||||
local dir="$1"
|
||||
local description="$2"
|
||||
|
||||
if [ -d "$dir" ]; then
|
||||
local size=$(du -sh "$dir" 2>/dev/null | cut -f1 || echo "unknown")
|
||||
echo " Removing $description: $dir ($size)"
|
||||
rm -rf "$dir"
|
||||
else
|
||||
echo " $description: $dir (not found)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to safely remove file with size info
|
||||
cleanup_file() {
|
||||
local file="$1"
|
||||
local description="$2"
|
||||
|
||||
if [ -f "$file" ]; then
|
||||
local size=$(du -sh "$file" 2>/dev/null | cut -f1 || echo "unknown")
|
||||
echo " Removing $description: $file ($size)"
|
||||
rm -f "$file"
|
||||
else
|
||||
echo " $description: $file (not found)"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "[+] Cleaning build outputs..."
|
||||
cleanup_dir "$OUTPUT_DIR" "Build outputs"
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleaning kernel build artifacts..."
|
||||
cleanup_dir "$KERNEL_DIR" "Kernel build directory"
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleaning cache files..."
|
||||
cleanup_dir "$CACHE_DIR" "Build cache"
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleaning boot initramfs..."
|
||||
cleanup_dir "$BOOT_ROOT" "Boot filesystem"
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleaning Alpine initramfs..."
|
||||
cleanup_dir "$ALPINE_ROOT" "Alpine initramfs root"
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleaning component build artifacts..."
|
||||
# Clean Rust target directories in components
|
||||
if [ -d "$COMPONENTS_DIR" ]; then
|
||||
echo " Scanning components for build artifacts..."
|
||||
|
||||
# Clean Rust target directories
|
||||
find "$COMPONENTS_DIR" -type d -name "target" 2>/dev/null | while read target_dir; do
|
||||
if [ -d "$target_dir" ]; then
|
||||
local size=$(du -sh "$target_dir" 2>/dev/null | cut -f1 || echo "unknown")
|
||||
echo " Removing Rust target: $target_dir ($size)"
|
||||
rm -rf "$target_dir"
|
||||
fi
|
||||
done
|
||||
|
||||
# Clean Cargo.lock files (except in git repos where they should be kept)
|
||||
find "$COMPONENTS_DIR" -name "Cargo.lock" -not -path "*/.git/*" 2>/dev/null | while read lock_file; do
|
||||
# Only remove if not in a git repository
|
||||
if ! git -C "$(dirname "$lock_file")" rev-parse --git-dir >/dev/null 2>&1; then
|
||||
echo " Removing Cargo.lock: $lock_file"
|
||||
rm -f "$lock_file"
|
||||
fi
|
||||
done
|
||||
|
||||
# Clean Go build artifacts
|
||||
find "$COMPONENTS_DIR" -type f -name "go.sum" 2>/dev/null | while read go_sum; do
|
||||
echo " Removing Go sum: $go_sum"
|
||||
rm -f "$go_sum"
|
||||
done
|
||||
|
||||
# Clean any temporary build files
|
||||
find "$COMPONENTS_DIR" -type f \( -name "*.tmp" -o -name "*.temp" -o -name ".build-*" \) 2>/dev/null | while read temp_file; do
|
||||
echo " Removing temp file: $temp_file"
|
||||
rm -f "$temp_file"
|
||||
done
|
||||
else
|
||||
echo " Components directory not found: $COMPONENTS_DIR"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleaning Docker build artifacts..."
|
||||
# Clean any Docker build artifacts if docker is available
|
||||
if command -v docker >/dev/null 2>&1; then
|
||||
echo " Removing dangling Docker images..."
|
||||
docker image prune -f >/dev/null 2>&1 || echo " No dangling images to remove"
|
||||
|
||||
echo " Removing stopped containers..."
|
||||
docker container prune -f >/dev/null 2>&1 || echo " No stopped containers to remove"
|
||||
|
||||
# Remove specific build containers if they exist
|
||||
for container in alpine-initramfs-builder alpine-cached-builder; do
|
||||
if docker ps -a --format "table {{.Names}}" | grep -q "^${container}$"; then
|
||||
echo " Removing container: $container"
|
||||
docker rm -f "$container" >/dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo " Docker not available, skipping Docker cleanup"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleaning temporary files..."
|
||||
# Clean any temporary files in the project root
|
||||
cleanup_file "/build/build.conf" "Build configuration"
|
||||
cleanup_file "/build/.build-timestamp" "Build timestamp"
|
||||
|
||||
# Clean any log files
|
||||
find /build -name "*.log" -type f 2>/dev/null | while read log_file; do
|
||||
echo " Removing log file: $log_file"
|
||||
rm -f "$log_file"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleaning system package cache..."
|
||||
# Clean APK cache if we're in Alpine
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
echo " Cleaning APK cache..."
|
||||
apk cache clean 2>/dev/null || echo " APK cache already clean"
|
||||
|
||||
# Remove APK cache directory if it exists and is not needed
|
||||
if [ -d "/var/cache/apk" ]; then
|
||||
local cache_size=$(du -sh "/var/cache/apk" 2>/dev/null | cut -f1 || echo "unknown")
|
||||
if [ "$cache_size" != "0" ] && [ "$cache_size" != "unknown" ]; then
|
||||
echo " Removing APK cache directory: /var/cache/apk ($cache_size)"
|
||||
rm -rf /var/cache/apk/*
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleanup summary:"
|
||||
echo " The following have been cleaned:"
|
||||
echo " • Build outputs (vmlinuz.efi, initramfs.cpio.xz, etc.)"
|
||||
echo " • Kernel source and build artifacts"
|
||||
echo " • Component build artifacts (Rust target/, Go artifacts)"
|
||||
echo " • Cache files and temporary files"
|
||||
echo " • Docker build artifacts"
|
||||
echo " • System package cache"
|
||||
echo ""
|
||||
echo " The following have been preserved:"
|
||||
echo " • Source code and git repositories"
|
||||
echo " • Configuration files"
|
||||
echo " • Build scripts"
|
||||
echo " • Git submodules (use git submodule update to restore)"
|
||||
echo ""
|
||||
|
||||
# Show disk space freed
|
||||
echo "[+] Disk space status:"
|
||||
df -h /build 2>/dev/null | tail -1 | awk '{print " Available space: " $4 " (" $5 " used)"}'
|
||||
|
||||
echo ""
|
||||
echo "[+] Cleanup completed successfully!"
|
||||
echo ""
|
||||
echo "To rebuild the project after cleanup:"
|
||||
echo " 1. Run: ./build.sh # Full rebuild"
|
||||
echo " 2. Or: docker-compose up --build # Docker rebuild"
|
||||
echo " 3. Or: scripts/setup-submodules.sh # Restore submodules first"
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
ALPINE_ROOT="/build/initramfs"
|
||||
@@ -56,14 +56,6 @@ build_rust_component() {
|
||||
# Source cargo environment
|
||||
. ~/.cargo/env
|
||||
|
||||
# Set git version for components that use git_version macro
|
||||
# Many git_version crates check these environment variables first
|
||||
export VERGEN_GIT_DESCRIBE=$(cd "$COMPONENTS_DIR/$component_name" && git describe --tags --always --dirty=-modified 2>/dev/null || echo "unknown")
|
||||
export GIT_VERSION=$(cd "$COMPONENTS_DIR/$component_name" && git describe --tags --always --dirty=-modified 2>/dev/null || echo "unknown")
|
||||
export VERGEN_GIT_BRANCH=$(cd "$COMPONENTS_DIR/$component_name" && git branch --show-current 2>/dev/null || echo "main")
|
||||
export VERGEN_GIT_COMMIT_TIMESTAMP=$(cd "$COMPONENTS_DIR/$component_name" && git log -1 --format=%ct 2>/dev/null || echo "0")
|
||||
export VERGEN_GIT_SHA=$(cd "$COMPONENTS_DIR/$component_name" && git rev-parse HEAD 2>/dev/null || echo "unknown")
|
||||
|
||||
# Build with musl target for static linking
|
||||
cargo build --release --target x86_64-unknown-linux-musl
|
||||
|
||||
@@ -124,6 +116,55 @@ build_go_component() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to build mycelium (special case - builds from myceliumd subdirectory)
|
||||
build_mycelium_component() {
|
||||
local component_name="$1"
|
||||
local binary_name="$2"
|
||||
local install_path="$3"
|
||||
|
||||
echo " Building Mycelium component: $component_name"
|
||||
|
||||
if ! prepare_component "$component_name"; then
|
||||
echo " Skipping $component_name (not available)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Change to myceliumd subdirectory
|
||||
if [ ! -d "myceliumd" ]; then
|
||||
echo " Error: myceliumd subdirectory not found in $component_name"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo " Building from myceliumd subdirectory..."
|
||||
cd myceliumd
|
||||
|
||||
# Source cargo environment
|
||||
. ~/.cargo/env
|
||||
|
||||
# Build with musl target for static linking from myceliumd directory
|
||||
cargo build --release --target x86_64-unknown-linux-musl
|
||||
|
||||
# Debug: Check what was actually built
|
||||
echo " Checking build results..."
|
||||
ls -la target/x86_64-unknown-linux-musl/release/ | grep -v "\.d$" | grep -v "\.rlib$" || true
|
||||
|
||||
# The binary is in target/x86_64-unknown-linux-musl/release/ (relative to myceliumd directory)
|
||||
if [ ! -f "target/x86_64-unknown-linux-musl/release/$binary_name" ]; then
|
||||
echo " Error: Binary not found at target/x86_64-unknown-linux-musl/release/$binary_name"
|
||||
echo " Available files:"
|
||||
ls -la target/x86_64-unknown-linux-musl/release/ || true
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Install binary to Alpine root
|
||||
mkdir -p "$ALPINE_ROOT$install_path"
|
||||
cp "target/x86_64-unknown-linux-musl/release/$binary_name" "$ALPINE_ROOT$install_path/"
|
||||
chmod +x "$ALPINE_ROOT$install_path/$binary_name"
|
||||
|
||||
echo " Success: $install_path/$binary_name installed to Alpine root (musl static)"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Install build dependencies if needed
|
||||
echo " Checking build dependencies..."
|
||||
if ! command -v git >/dev/null; then
|
||||
@@ -167,8 +208,8 @@ else
|
||||
echo " Warning: CoreX binary not found"
|
||||
fi
|
||||
|
||||
# 4. Mycelium - Networking layer (Rust) - 0.6.1 with musl
|
||||
if build_rust_component "mycelium" "mycelium" "/usr/bin"; then
|
||||
# 4. Mycelium - Networking layer (Rust) - 0.6.1 with musl (special build from myceliumd subdirectory)
|
||||
if build_mycelium_component "mycelium" "mycelium" "/usr/bin"; then
|
||||
echo " Mycelium built successfully"
|
||||
else
|
||||
echo " Warning: Failed to build mycelium"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
GITHUB_DIR="/build/github"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
INITRAMFS_ROOT="/build/initramfs"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
INITRAMFS_ROOT="/build/initramfs"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
INITRAMFS_ROOT="/build/initramfs"
|
||||
@@ -37,7 +37,7 @@ fi
|
||||
# Create debug script for compatibility
|
||||
echo " Creating debug script..."
|
||||
cat > "$INITRAMFS_ROOT/init-debug" << 'EOF'
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# Debug file injection script (Alpine version)
|
||||
echo "[+] debug mode enabled"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# Ensure all scripts are executable
|
||||
|
||||
chmod +x /build/scripts/*.sh
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "[+] Setting up Zero-OS components..."
|
||||
|
||||
Reference in New Issue
Block a user