Created
August 25, 2022 13:49
-
-
Save dtrunk90/7947b80ca12de83201082e772c1b34b9 to your computer and use it in GitHub Desktop.
Can be executed within android root dir for moving found identical proprietary files
This file contains 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 | |
vendor="sony" | |
devices=("akari" "akatsuki" "aurora" "xz2c") | |
common_device="tama-common" | |
device_devices=(${devices[@]/#/device/${vendor}/}) | |
common_proprietary_files_file="device/${vendor}/${common_device}/proprietary-files.txt" | |
vendor_devices=(${devices[@]/#/vendor/${vendor}/}) | |
# loop through identical blobs | |
while IFS= read -r file; do | |
common_device_file="vendor/${vendor}/${common_device}/proprietary/${file}" | |
# find section and line of file in first device's proprietary-files.txt | |
while IFS= read -r line; do | |
if [[ "${line}" == "#"* ]]; then | |
file_section="${line}" | |
fi | |
if [[ "${line}" == "${file}"* ]]; then | |
file_line="${line}" | |
break | |
fi | |
done < "device/${vendor}/${devices[0]}/proprietary-files.txt" | |
# remove line of file from all device's proprietary-files.txt | |
sed -i "/$(printf '%s\n' "${file}" | sed -e 's/[\/&]/\\&/g')/d" ${device_devices[@]/%//proprietary-files.txt} | |
# check if blob isn't commonized already | |
if [[ ! -f "${common_device_file}" ]]; then | |
# check if common proprietary-files.txt has section | |
if grep -xq "$(printf '%s' "${file_section}" | sed -e 's/[\/&]/\\&/g')" "${common_proprietary_files_file}"; then | |
# add line of file directly after the section header | |
sed -i "/^${file_section}/a ${file_line}" "${common_proprietary_files_file}" | |
else | |
# append new section | |
cat <<EOS >> "${common_proprietary_files_file}" | |
${file_section} | |
${file_line} | |
EOS | |
fi | |
fi | |
# finally move one file and delete the others | |
for vendor_device in "${vendor_devices[@]}"; do | |
device_file="${vendor_device}/proprietary/${file}" | |
if [[ "${vendor_device}" == "${vendor_devices[0]}" ]]; then | |
mkdir -p "$(dirname "${common_device_file}")" | |
mv "${device_file}" "${common_device_file}" | |
else | |
rm "${device_file}" | |
fi | |
done | |
done < <(list-identical-blobs) | |
# remove empty directories | |
find ${vendor_devices[@]/%//proprietary} -type d -empty -delete | |
# re-sort sections of "${common_proprietary_files_file}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment