#!/bin/bash # # Script Name: package_build.sh # Description: Package Dubai Metaverse project for distribution # Usage: ./package_build.sh [options] # Author: Dubai Metaverse Team # Date: 2024 # Version: 1.0 # # Exit codes: # 0: Success # 1: General error # 2: Invalid arguments # 3: Missing dependencies set -euo pipefail # Configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" LOG_FILE="${LOG_FILE:-$PROJECT_ROOT/logs/package_build.log}" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # Logging log() { local level="${1:-INFO}" shift local message="$*" local timestamp=$(date +'%Y-%m-%d %H:%M:%S') echo "[$timestamp] [$level] $message" | tee -a "$LOG_FILE" } error_exit() { log "ERROR" "$*" exit 1 } warning() { log "WARNING" "$*" } success() { log "SUCCESS" "$*" } # Parse arguments BUILD_CONFIG="Shipping" PLATFORM="Windows" OUTPUT_DIR="${PROJECT_ROOT}/Builds" DRY_RUN=false VERBOSE=false usage() { cat << EOF Usage: $0 [OPTIONS] Package Dubai Metaverse project for distribution. Options: -h, --help Show this help message -c, --config CONFIG Build configuration (Development/Shipping) [default: Shipping] -p, --platform PLAT Platform (Windows/Linux) [default: Windows] -o, --output DIR Output directory [default: Builds/] -d, --dry-run Perform dry run without packaging -v, --verbose Enable verbose output Examples: $0 --config Shipping --platform Windows $0 --dry-run $0 --output /path/to/output EOF } parse_args() { while [[ $# -gt 0 ]]; do case $1 in -h|--help) usage exit 0 ;; -c|--config) BUILD_CONFIG="$2" shift 2 ;; -p|--platform) PLATFORM="$2" shift 2 ;; -o|--output) OUTPUT_DIR="$2" shift 2 ;; -d|--dry-run) DRY_RUN=true shift ;; -v|--verbose) VERBOSE=true shift ;; *) error_exit "Unknown option: $1. Use --help for usage." ;; esac done } # Validate prerequisites validate_prerequisites() { log "INFO" "Validating prerequisites..." # Check for Unreal Engine if [ -z "${UE_ROOT:-}" ]; then if [ -d "$HOME/UnrealEngine" ]; then export UE_ROOT="$HOME/UnrealEngine" elif [ -d "/opt/UnrealEngine" ]; then export UE_ROOT="/opt/UnrealEngine" else error_exit "Unreal Engine not found. Set UE_ROOT environment variable or install UE5.4" fi fi # Check for project file local project_file=$(find "$PROJECT_ROOT" -name "*.uproject" | head -1) if [ -z "$project_file" ]; then error_exit "Project file (.uproject) not found in $PROJECT_ROOT" fi export PROJECT_FILE="$project_file" log "INFO" "Using project file: $PROJECT_FILE" log "INFO" "Using Unreal Engine: $UE_ROOT" } # Clean build artifacts clean_build() { log "INFO" "Cleaning build artifacts..." if [ "$DRY_RUN" = true ]; then log "INFO" "[DRY RUN] Would clean: Binaries/, Intermediate/, Saved/" return fi cd "$PROJECT_ROOT" # Remove build artifacts [ -d "Binaries" ] && rm -rf Binaries [ -d "Intermediate" ] && rm -rf Intermediate [ -d "Saved" ] && rm -rf Saved success "Build artifacts cleaned" } # Validate assets validate_assets() { log "INFO" "Validating assets..." if [ "$DRY_RUN" = true ]; then log "INFO" "[DRY RUN] Would validate assets" return fi # Run asset validation if [ -f "$SCRIPT_DIR/validate_assets.sh" ]; then "$SCRIPT_DIR/validate_assets.sh" || warning "Asset validation found issues" else warning "Asset validation script not found, skipping" fi } # Package project package_project() { log "INFO" "Packaging project..." log "INFO" "Configuration: $BUILD_CONFIG" log "INFO" "Platform: $PLATFORM" log "INFO" "Output: $OUTPUT_DIR" if [ "$DRY_RUN" = true ]; then log "INFO" "[DRY RUN] Would package to: $OUTPUT_DIR" log "INFO" "[DRY RUN] Command: UnrealEditor -run=Cook -targetplatform=$PLATFORM -project=$PROJECT_FILE" return fi # Create output directory mkdir -p "$OUTPUT_DIR" # Determine UnrealEditor path local editor_path if [ "$PLATFORM" = "Windows" ]; then editor_path="$UE_ROOT/Engine/Binaries/Win64/UnrealEditor.exe" else editor_path="$UE_ROOT/Engine/Binaries/Linux/UnrealEditor" fi if [ ! -f "$editor_path" ]; then error_exit "UnrealEditor not found at: $editor_path" fi log "INFO" "Starting packaging process..." log "INFO" "This may take 30-60 minutes depending on project size..." # Package using UnrealEditor command line # Note: This is a simplified version. Full implementation would use # UnrealEditor's packaging system with proper parameters log "WARNING" "Full packaging implementation requires Unreal Editor command line" log "INFO" "For now, use Unreal Editor GUI: File > Package Project" log "INFO" "Or use Unreal Automation Tool (UAT) for advanced packaging" # Placeholder for actual packaging command # "$editor_path" "$PROJECT_FILE" -run=Cook -targetplatform="$PLATFORM" -project="$PROJECT_FILE" || error_exit "Packaging failed" success "Packaging complete (placeholder - use Unreal Editor GUI for actual packaging)" } # Main function main() { log "INFO" "Starting package_build.sh" # Create log directory mkdir -p "$(dirname "$LOG_FILE")" # Parse arguments parse_args "$@" # Validate prerequisites validate_prerequisites # Clean build clean_build # Validate assets validate_assets # Package project package_project success "Build packaging process complete" log "INFO" "Output directory: $OUTPUT_DIR" log "INFO" "Log file: $LOG_FILE" } # Run main if executed directly if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then main "$@" fi