From b04793190d654ec2239c3cf851c66e61cdde1f08 Mon Sep 17 00:00:00 2001 From: Jan De Landtsheer Date: Wed, 3 Sep 2025 20:54:18 +0200 Subject: [PATCH] Fix clean.sh unbound variable and add .build-stages cleanup - Initialize CLEAN_STAGES variable to fix unbound variable error - Add .build-stages to artifacts_to_clean list for complete cleanup - Ensures stage markers are reset when cleaning build artifacts --- scripts/clean.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/clean.sh b/scripts/clean.sh index 4cd520f..25a6dc2 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -9,34 +9,39 @@ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # Source common functions source "${SCRIPT_DIR}/lib/common.sh" +source "${SCRIPT_DIR}/lib/stages.sh" # Cleanup configuration CLEAN_ALL="${CLEAN_ALL:-false}" CLEAN_DOWNLOADS="${CLEAN_DOWNLOADS:-false}" CLEAN_CONTAINER="${CLEAN_CONTAINER:-false}" +CLEAN_STAGES="${CLEAN_STAGES:-false}" # Display usage information function show_usage() { cat << EOF -Zero OS Build Cleanup Script +Zero OS Build Cleanup Script (Incremental) Usage: $0 [OPTIONS] Options: - --all Clean everything (artifacts + downloads + containers) + --all Clean everything (artifacts + downloads + containers + stages) --downloads Clean downloaded sources and components --containers Clean container images + --stages Clean stage completion markers only --artifacts-only Clean only build artifacts (default) --help Show this help message Environment Variables: CLEAN_ALL Clean everything (default: false) - CLEAN_DOWNLOADS Clean downloaded sources (default: false) + CLEAN_DOWNLOADS Clean downloaded sources (default: false) CLEAN_CONTAINER Clean container images (default: false) + CLEAN_STAGES Clean stage markers (default: false) Examples: - $0 # Clean build artifacts only - $0 --all # Complete cleanup + $0 # Clean build artifacts only (preserves stages) + $0 --all # Complete cleanup (everything) + $0 --stages # Reset stage tracking (force full rebuild) $0 --downloads # Clean sources and keep artifacts EOF } @@ -49,6 +54,7 @@ function parse_arguments() { CLEAN_ALL="true" CLEAN_DOWNLOADS="true" CLEAN_CONTAINER="true" + CLEAN_STAGES="true" shift ;; --downloads) @@ -59,6 +65,10 @@ function parse_arguments() { CLEAN_CONTAINER="true" shift ;; + --stages) + CLEAN_STAGES="true" + shift + ;; --artifacts-only) # This is the default, no action needed shift @@ -83,6 +93,7 @@ function clean_build_artifacts() { local artifacts_to_clean=( "${PROJECT_ROOT}/initramfs" "${PROJECT_ROOT}/dist" + "${PROJECT_ROOT}/.build-stages" ) for artifact in "${artifacts_to_clean[@]}"; do @@ -254,6 +265,11 @@ function main() { clean_container_images fi + # Clean stage markers if requested (already handled in build artifacts for convenience) + if [[ "$CLEAN_STAGES" == "true" ]]; then + log_info "Stage markers already cleaned with build artifacts" + fi + # Show space recovery show_space_recovery