#!/bin/bash
#
# Copyright (C) 2019-Present A-Team Digital Solutions
#

BRANCH="lineage-23.2"

set -e
echo 
echo 
echo "Syncing Avatrn Device Dependencies ..."
echo 
echo "Repo Branch: $BRANCH"
echo 
echo 
clone_repo() {
    local repo="$1"
    local path="$2"
    if [ -d "$path" ]; then
        echo "Skipping Existing: $path" 
    else
        echo "Cloning $repo -> $path ..." 
        mkdir -p "$(dirname "$path")"
        git clone --depth=1 -b "$BRANCH" "https://github.com/$repo.git" "$path" || {
            echo "FAILED: $repo"
        }
    fi
}
# Device
clone_repo "LineageOS/android_device_motorola_avatrn" \
           "device/motorola/avatrn"
echo 
echo 
clone_repo "LineageOS/android_device_motorola_sm7435-common" \
           "device/motorola/sm7435-common"
echo 
echo 
# Kernel
clone_repo "LineageOS/android_kernel_motorola_sm7435" \
           "kernel/motorola/sm7435"
echo 
echo
clone_repo "LineageOS/android_kernel_motorola_sm7435-modules" \
           "kernel/motorola/sm7435-modules"
echo 
echo 
clone_repo "LineageOS/android_kernel_motorola_sm7435-devicetrees" \
           "kernel/motorola/sm7435-devicetrees"
echo 
echo 
# Hardware
clone_repo "LineageOS/android_hardware_motorola" \
           "hardware/motorola"
echo 
echo 
# Vendor Blobs
clone_repo "TheMuppets/proprietary_vendor_motorola_avatrn" \
           "vendor/motorola/avatrn"
echo 
echo
clone_repo "TheMuppets/proprietary_vendor_motorola_sm7435-common" \
           "vendor/motorola/sm7435-common"
echo 
echo 
echo "Finished."
echo 
echo "Checking Vendor:"
ls vendor/motorola/avatrn 2>/dev/null || echo "Vendor Missing!"
echo 
echo 
echo "Sync Done"
echo 
echo 
