Last active
September 6, 2026 08:15
-
-
Save Megh-Rana/c9bb081ad8302a97a49917e0f600bb59 to your computer and use it in GitHub Desktop.
m52xq build script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ## Build script for Samsung Galaxy M52 5G (m52xq) - LineageOS 23.2 | |
| ## Usage: | |
| ## ./build_m52xq.sh # Full clone + build | |
| ## ./build_m52xq.sh sync # Clone/sync repos only, no build | |
| ## ./build_m52xq.sh build # Build only (assumes repos already cloned) | |
| # REMOVED: set -e (We want the script to power through errors) | |
| # Force UTF-8 so box-drawing/status characters render correctly in any | |
| # terminal/container regardless of its default locale. | |
| export LANG=C.UTF-8 | |
| export LC_ALL=C.UTF-8 | |
| # ============================================================================ | |
| # Configuration | |
| # ============================================================================ | |
| BRANCH="lineage-23.2" | |
| GITHUB_ORG="LineageOS" | |
| GITHUB_ORG_COMMON="Megh-Rana" | |
| VENDOR_ORG="TheMuppets" | |
| VENDOR_BRANCH="lineage-23.2" | |
| # Device tree & IMS repos | |
| declare -A REPOS=( | |
| ["device/samsung/m52xq"]="https://github.com/${GITHUB_ORG}/android_device_samsung_m52xq" | |
| ["device/samsung/sm7325-common"]="https://github.com/${GITHUB_ORG_COMMON}/android_device_samsung_sm7325-common" | |
| ["kernel/samsung/sm7325"]="https://github.com/${GITHUB_ORG}/android_kernel_samsung_sm7325" | |
| ["packages/modules/ImsStack"]="https://github.com/krazey/ImsStack" | |
| ["packages/modules/ImsMedia"]="https://github.com/krazey/ImsMedia" | |
| ["vendor/lineage/imsstack-carrier-config-ext"]="https://github.com/krazey/imsstack-carrier-config-ext" | |
| ) | |
| # IMS repos use 'main' branch, everything else uses $BRANCH | |
| declare -A REPO_BRANCHES=( | |
| ["packages/modules/ImsStack"]="main" | |
| ["packages/modules/ImsMedia"]="main" | |
| ["vendor/lineage/imsstack-carrier-config-ext"]="main" | |
| ) | |
| # Vendor blobs | |
| declare -A VENDOR_REPOS=( | |
| ["vendor/samsung/m52xq"]="https://github.com/${VENDOR_ORG}/proprietary_vendor_samsung_m52xq" | |
| ["vendor/samsung/sm7325-common"]="https://github.com/Megh-Rana/proprietary_vendor_samsung_sm7325-common" | |
| ) | |
| # ============================================================================ | |
| # Colors | |
| # ============================================================================ | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| CYAN='\033[0;36m' | |
| NC='\033[0m' | |
| log() { echo -e "${GREEN}[OK]${NC} $*"; } | |
| info() { echo -e "${BLUE}[i]${NC} $*"; } | |
| warn() { echo -e "${YELLOW}[!]${NC} $*"; } | |
| error() { echo -e "${RED}[x]${NC} $*"; } # Removed 'exit 1' so it doesn't kill the script | |
| step() { echo -e "\n${CYAN}=== $* ===${NC}\n"; } | |
| # ============================================================================ | |
| # Sanity checks | |
| # ============================================================================ | |
| check_environment() { | |
| step "Checking build environment" | |
| if [[ ! -f "build/envsetup.sh" ]]; then | |
| warn "This doesn't look like a LineageOS/AOSP source tree root." | |
| fi | |
| log "Environment check finished." | |
| } | |
| # ============================================================================ | |
| # Clone / sync repos | |
| # ============================================================================ | |
| clone_or_update() { | |
| local target_path="$1" | |
| local repo_url="$2" | |
| local branch="$3" | |
| if [[ -d "$target_path/.git" ]]; then | |
| info "Updating ${target_path} ..." | |
| # Try to update, if ANY git command fails, jump to the OR block (||) | |
| ( | |
| cd "$target_path" && \ | |
| git fetch origin "$branch" --depth 1 && \ | |
| (git checkout "$branch" 2>/dev/null || git checkout -b "$branch" "origin/$branch") && \ | |
| git reset --hard "origin/$branch" | |
| ) || { | |
| warn "Clean update failed for ${target_path}. Nuking and recloning..." | |
| rm -rf "$target_path" | |
| git clone --depth 1 -b "$branch" "$repo_url" "$target_path" || warn "CRITICAL: Completely failed to clone ${target_path}!" | |
| } | |
| log "Processed ${target_path}" | |
| else | |
| # If folder exists but isn't a git repo, wipe it out | |
| if [[ -d "$target_path" ]]; then | |
| warn "Directory ${target_path} exists but is junk. Wiping..." | |
| rm -rf "$target_path" | |
| fi | |
| info "Cloning ${repo_url} -> ${target_path} (branch: ${branch})" | |
| git clone --depth 1 -b "$branch" "$repo_url" "$target_path" || warn "CRITICAL: Failed to clone ${target_path}!" | |
| log "Processed ${target_path}" | |
| fi | |
| } | |
| sync_repos() { | |
| step "Nuking known problem repos before sync" | |
| # These three have previously failed repo sync with | |
| # "unsupported checkout state" (stale/corrupted .repo checkout state) -- | |
| # wipe them so repo does a clean fresh checkout instead of choking on | |
| # a bad existing state. | |
| rm -rf kernel/samsung/sm7325 | |
| rm -rf hardware/samsung | |
| rm -rf hardware/samsung_slsi/nfc | |
| # Added || true so failures here don't stop the rest of the script | |
| repo init -u https://github.com/crdroidandroid/android.git -b 16.0 --git-lfs --no-clone-bundle --depth=1 | |
| /opt/crave/resync.sh | |
| step "Cloning device tree and dependencies" | |
| local sorted_paths | |
| sorted_paths=$(printf "%s\n" "${!REPOS[@]}" | sort) | |
| for target_path in $sorted_paths; do | |
| local repo_url="${REPOS[$target_path]}" | |
| local branch="${REPO_BRANCHES[$target_path]:-$BRANCH}" | |
| clone_or_update "$target_path" "$repo_url" "$branch" | |
| done | |
| step "Cloning vendor blobs" | |
| local sorted_vendor_paths | |
| sorted_vendor_paths=$(printf "%s\n" "${!VENDOR_REPOS[@]}" | sort) | |
| for target_path in $sorted_vendor_paths; do | |
| local repo_url="${VENDOR_REPOS[$target_path]}" | |
| # FIX: was previously calling clone_or_update with only | |
| # (target_path, VENDOR_BRANCH) -- repo_url never got passed, so | |
| # branch was empty and the clone silently failed, which is why | |
| # vendor/samsung/m52xq/m52xq-vendor.mk was missing at build time. | |
| clone_or_update "$target_path" "$repo_url" "$VENDOR_BRANCH" | |
| done | |
| rm -rf hardware/samsung | |
| rm -rf hardware/samsung_slsi/nfc | |
| git clone https://github.com/LineageOS/android_hardware_samsung hardware/samsung | |
| git clone https://github.com/LineageOS/android_hardware_samsung_nfc hardware/samsung/nfc | |
| git clone https://github.com/LineageOS/android_hardware_samsung_slsi_nfc hardware/samsung_slsi/nfc | |
| echo "" | |
| log "Sync phase complete. (Check logs above for any warnings)" | |
| } | |
| # ============================================================================ | |
| # Build | |
| # ============================================================================ | |
| run_build() { | |
| step "Setting up build environment" | |
| # shellcheck disable=SC1091 | |
| source build/envsetup.sh || warn "Failed to source envsetup.sh" | |
| step "Starting build for m52xq" | |
| info "lunch target: lineage_m52xq-userdebug" | |
| lunch lineage_m52xq-bp4a-userdebug || warn "Lunch command failed!" | |
| step "Building LineageOS..." | |
| mka bacon || warn "mka bacon encountered an error!" | |
| step "Build script finished processing!" | |
| local out_dir="out/target/product/m52xq" | |
| if [[ -d "$out_dir" ]]; then | |
| log "Checking output files:" | |
| ls -lh "$out_dir"/lineage-*.zip 2>/dev/null || warn "No zip found in ${out_dir}" | |
| fi | |
| } | |
| # ============================================================================ | |
| # Main | |
| # ============================================================================ | |
| main() { | |
| echo -e "${CYAN}" | |
| echo "+----------------------------------------------------------------+" | |
| echo "| LineageOS 23.2 Build Script - Samsung Galaxy M52 5G |" | |
| echo "| Device: m52xq (SM-M526B) | SoC: SM7325 (Snapdragon) |" | |
| echo "+----------------------------------------------------------------+" | |
| echo -e "${NC}" | |
| local mode="${1:-all}" | |
| case "$mode" in | |
| sync) | |
| check_environment | |
| sync_repos | |
| ;; | |
| build) | |
| check_environment | |
| run_build | |
| ;; | |
| all|"") | |
| check_environment | |
| sync_repos | |
| run_build | |
| ;; | |
| *) | |
| echo "Usage: $0 [sync|build|all]" | |
| exit 1 | |
| ;; | |
| esac | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment