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
This commit is contained in:
2025-09-03 20:54:18 +02:00
parent 76b26204f9
commit b04793190d

View File

@@ -9,34 +9,39 @@ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Source common functions # Source common functions
source "${SCRIPT_DIR}/lib/common.sh" source "${SCRIPT_DIR}/lib/common.sh"
source "${SCRIPT_DIR}/lib/stages.sh"
# Cleanup configuration # Cleanup configuration
CLEAN_ALL="${CLEAN_ALL:-false}" CLEAN_ALL="${CLEAN_ALL:-false}"
CLEAN_DOWNLOADS="${CLEAN_DOWNLOADS:-false}" CLEAN_DOWNLOADS="${CLEAN_DOWNLOADS:-false}"
CLEAN_CONTAINER="${CLEAN_CONTAINER:-false}" CLEAN_CONTAINER="${CLEAN_CONTAINER:-false}"
CLEAN_STAGES="${CLEAN_STAGES:-false}"
# Display usage information # Display usage information
function show_usage() { function show_usage() {
cat << EOF cat << EOF
Zero OS Build Cleanup Script Zero OS Build Cleanup Script (Incremental)
Usage: $0 [OPTIONS] Usage: $0 [OPTIONS]
Options: Options:
--all Clean everything (artifacts + downloads + containers) --all Clean everything (artifacts + downloads + containers + stages)
--downloads Clean downloaded sources and components --downloads Clean downloaded sources and components
--containers Clean container images --containers Clean container images
--stages Clean stage completion markers only
--artifacts-only Clean only build artifacts (default) --artifacts-only Clean only build artifacts (default)
--help Show this help message --help Show this help message
Environment Variables: Environment Variables:
CLEAN_ALL Clean everything (default: false) 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_CONTAINER Clean container images (default: false)
CLEAN_STAGES Clean stage markers (default: false)
Examples: Examples:
$0 # Clean build artifacts only $0 # Clean build artifacts only (preserves stages)
$0 --all # Complete cleanup $0 --all # Complete cleanup (everything)
$0 --stages # Reset stage tracking (force full rebuild)
$0 --downloads # Clean sources and keep artifacts $0 --downloads # Clean sources and keep artifacts
EOF EOF
} }
@@ -49,6 +54,7 @@ function parse_arguments() {
CLEAN_ALL="true" CLEAN_ALL="true"
CLEAN_DOWNLOADS="true" CLEAN_DOWNLOADS="true"
CLEAN_CONTAINER="true" CLEAN_CONTAINER="true"
CLEAN_STAGES="true"
shift shift
;; ;;
--downloads) --downloads)
@@ -59,6 +65,10 @@ function parse_arguments() {
CLEAN_CONTAINER="true" CLEAN_CONTAINER="true"
shift shift
;; ;;
--stages)
CLEAN_STAGES="true"
shift
;;
--artifacts-only) --artifacts-only)
# This is the default, no action needed # This is the default, no action needed
shift shift
@@ -83,6 +93,7 @@ function clean_build_artifacts() {
local artifacts_to_clean=( local artifacts_to_clean=(
"${PROJECT_ROOT}/initramfs" "${PROJECT_ROOT}/initramfs"
"${PROJECT_ROOT}/dist" "${PROJECT_ROOT}/dist"
"${PROJECT_ROOT}/.build-stages"
) )
for artifact in "${artifacts_to_clean[@]}"; do for artifact in "${artifacts_to_clean[@]}"; do
@@ -254,6 +265,11 @@ function main() {
clean_container_images clean_container_images
fi 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
show_space_recovery show_space_recovery