Skip to content

Commit

Permalink
dumpyara: Generate proprietary file list
Browse files Browse the repository at this point in the history
* Taked from dumprx

Change-Id: I37c68723d87042553bb7d81e057a9cead7eb0ebe
  • Loading branch information
Kizziama committed Apr 12, 2024
1 parent a0c13e5 commit 2217af7
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions dumpyara.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ EXTENSION=$(echo ${URL##*.} | inline-detox)
UNZIP_DIR=${FILE/.$EXTENSION/}
PARTITIONS="system systemex system_ext system_other vendor cust odm odm_ext oem factory product modem xrom oppo_product opproduct reserve india my_preload my_odm my_stock my_operator my_country my_product my_company my_engineering my_heytap my_custom my_manifest my_carrier my_region my_bigball my_version special_preload vendor_dlkm odm_dlkm system_dlkm mi_ext"

EXTERNAL_TOOLS=(
Hopireika/android_tools
)

if [[ -d "$1" ]]; then
echo 'Directory detected. Copying...'
cp -a "$1" "$PROJECT_DIR"/working/"${UNZIP_DIR}"
Expand All @@ -83,6 +87,14 @@ else
git clone -q https://github.com/marin-m/vmlinux-to-elf "$PROJECT_DIR/vmlinux-to-elf"
fi

for tool_slug in "${EXTERNAL_TOOLS[@]}"; do
if ! [[ -d "${PROJECT_DIR}"/"${tool_slug#*/}" ]]; then
git clone -q https://github.com/"${tool_slug}".git "${PROJECT_DIR}"/"${tool_slug#*/}"
else
git -C "${PROJECT_DIR}"/"${tool_slug#*/}" pull
fi
done

# extract rom via Firmware_extractor
[[ ! -d "$1" ]] && bash "$PROJECT_DIR"/Firmware_extractor/extractor.sh "$PROJECT_DIR"/input/"${FILE}" "$PROJECT_DIR"/working/"${UNZIP_DIR}"

Expand Down Expand Up @@ -226,6 +238,52 @@ manufacturer=$(echo "$manufacturer" | tr '[:upper:]' '[:lower:]' | tr -dc '[:pri
printf "# %s\n- manufacturer: %s\n- platform: %s\n- codename: %s\n- flavor: %s\n- release: %s\n- id: %s\n- incremental: %s\n- tags: %s\n- fingerprint: %s\n- is_ab: %s\n- brand: %s\n- branch: %s\n- repo: %s\n" "$description" "$manufacturer" "$platform" "$codename" "$flavor" "$release" "$id" "$incremental" "$tags" "$fingerprint" "$is_ab" "$brand" "$branch" "$repo" > "$PROJECT_DIR"/working/"${UNZIP_DIR}"/README.md
cat "$PROJECT_DIR"/working/"${UNZIP_DIR}"/README.md

# Generate Files having the sha1sum values of the Blobs
function write_sha1sum(){
# Usage: write_sha1sum <file> <destination_file>

local SRC_FILE=$1
local DST_FILE=$2

# Temporary file
local TMP_FILE=${SRC_FILE}.sha1sum.tmp

# Get rid of all the Blank lines and Comments
( cat ${SRC_FILE} | grep -v '^[[:space:]]*$' | grep -v "# " ) > ${TMP_FILE}

# Append the sha1sum of blobs in the Destination File
cp ${SRC_FILE} ${DST_FILE}
cat ${TMP_FILE} | while read -r i; do {
local BLOB=${i}

# Do we have a "-" before the blob's path? If yes, then remove it
local BLOB_TOPDIR=$(echo ${BLOB} | cut -d / -f1)
[ "${BLOB_TOPDIR:0:1}" = "-" ] && local BLOB=${BLOB_TOPDIR/-/}/${BLOB/${BLOB_TOPDIR}\//}

# Is it a non- /vendor blob?
[ ! -e "${BLOB}" ] && {
# for system libs, bins etc.
if [ -e "system/${BLOB}" ]; then
local BLOB="system/${BLOB}"
# for system-as-root system libs, bins etc.
elif [ -e "system/system/${BLOB}" ]; then
local BLOB="system/system/${BLOB}"
fi
}
local SHA1=$(sha1sum ${BLOB} | gawk '{print $1}')

local BLOB=${i} # Switch back to the Original Blob's name
local ORG_EXP="${BLOB}"
local FINAL_EXP="${BLOB}|${SHA1}"

# Append the |sha1sum
sed -i "s:${ORG_EXP}$:${FINAL_EXP}:g" "${DST_FILE}"
}; done

# Delete the Temporary file
rm ${TMP_FILE}
}

# Generate AOSP device tree
if python3 -c "import aospdtgen"; then
echo "aospdtgen installed, generating device tree"
Expand All @@ -237,6 +295,18 @@ if python3 -c "import aospdtgen"; then
fi
fi

# Generate proprietary-files.txt
printf "Generating proprietary-files.txt...\n"
bash "${PROJECT_DIR}"/android_tools/tools/proprietary-files.sh "${PROJECT_DIR}/working/${UNZIP_DIR}/all_files.txt >/dev/null
printf "# All blobs from %s, unless pinned\n" "${description}" > "${PROJECT_DIR}/working/${UNZIP_DIR}/proprietary-files.txt
cat "${PROJECT_DIR}"/android_tools/working/proprietary-files.txt >> "${PROJECT_DIR}/working/${UNZIP_DIR}/proprietary-files.txt
# Generate proprietary-files.sha1
printf "Generating proprietary-files.sha1...\n"
printf "# All blobs are from \"%s\" and are pinned with sha1sum values\n" "${description}" > "${PROJECT_DIR}/working/${UNZIP_DIR}/proprietary-files.sha1
write_sha1sum ${PROJECT_DIR}/android_tools/working/proprietary-files.{txt,sha1}
cat "${PROJECT_DIR}"/android_tools/working/proprietary-files.sha1 >> "${PROJECT_DIR}/working/${UNZIP_DIR}/proprietary-files.sha1
# copy file names
chown "$(whoami)" ./* -R
chmod -R u+rwX ./* #ensure final permissions
Expand Down

0 comments on commit 2217af7

Please sign in to comment.