#!/bin/bash # ------------------------------------------------------------------ # Yocto Repo Refresh & Rebuild Script # Safely re-syncs all repositories to the latest manifest version # while preserving downloads and removing stale build outputs. # ------------------------------------------------------------------ set -e # --- CONFIGURATION ------------------------------------------------- # Adjust these if needed BUILD_DIR="leahi-distro" # your build directory IMAGE="ely-image-qt" # your main image name NUM_JOBS=$(nproc) # number of parallel jobs # --- STEP 1: Confirm manifest is initialized ----------------------- echo "๐Ÿ”น Ensuring repo manifest is initialized..." if [ ! -d .repo ]; then echo "โŒ No .repo directory found. Run 'repo init -u -b ' first." exit 1 fi # --- STEP 2: Sync all sources ------------------------------------- echo "๐Ÿ”น Syncing all repositories..." repo sync -j${NUM_JOBS} --force-sync --fetch-submodules --prune # --- STEP 3: Clean stale build output but keep downloads ---------- if [ -d "${BUILD_DIR}/tmp" ]; then echo "๐Ÿงน Cleaning tmp directory (but keeping downloads/ and sstate-cache/)..." rm -rf "${BUILD_DIR}/tmp" fi # Optional: uncomment this if you want to clean sstate too # rm -rf "${BUILD_DIR}/sstate-cache" # --- STEP 4: Reset all repos to manifest HEAD --------------------- echo "๐Ÿ”น Resetting repos to manifest HEAD..." repo forall -c 'echo "โ†’ $REPO_PATH"; git reset --hard HEAD; git clean -fdx' # --- STEP 5: Rebuild image ---------------------------------------- echo "๐Ÿš€ Starting new build..." source ely-setup-environment ${BUILD_DIR} bitbake -c cleansstate virtual/kernel bitbake ${IMAGE} echo "โœ… Build complete: ${IMAGE}"