diff --git a/module/customize.sh b/module/customize.sh index 4b98bc3..46a3ffd 100644 --- a/module/customize.sh +++ b/module/customize.sh @@ -18,6 +18,15 @@ if [ -f /data/adb/modules/playintegrityfix/custom.pif.json ]; then cp -af /data/adb/modules/playintegrityfix/custom.pif.json $MODPATH/custom.pif.json fi +# Migrate custom.pif.json to latest defaults if needed +if [ -f "$MODPATH/custom.pif.json" ] && ! grep -q "api_level" $MODPATH/custom.pif.json; then + ui_print "- Running migration script on custom.pif.json:" + ui_print " " + chmod 755 $MODPATH/migrate.sh + sh $MODPATH/migrate.sh install $MODPATH/custom.pif.json + ui_print " " +fi + # Clean up any leftover files from previous deprecated methods rm -f /data/data/com.google.android.gms/cache/pif.prop /data/data/com.google.android.gms/pif.prop rm -f /data/data/com.google.android.gms/cache/pif.json /data/data/com.google.android.gms/pif.json diff --git a/module/migrate.sh b/module/migrate.sh new file mode 100644 index 0000000..389f6bc --- /dev/null +++ b/module/migrate.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +case "$1" in + install) INSTALL=1; shift;; + *) echo "custom.pif.json migration script \ + \n by osm0sis @ xda-developers \n";; +esac; + +item() { echo "- $@"; } +die() { [ "$INSTALL" ] || echo "\n\n! $@"; exit 1; } +grep_get_json() { grep "$1" "$DIR/custom.pif.json" | cut -d\" -f4; } +grep_check_json() { grep -q "$1" "$DIR/custom.pif.json" && [ "$(grep_get_json "$1")" ]; } + +if [ -f "$1" ]; then + DIR="$1"; + shift; +else + case "$0" in + *.sh) DIR="$0";; + *) DIR="$(lsof -p $$ 2>/dev/null | grep -o '/.*migrate.sh$')";; + esac; +fi; +DIR=$(dirname "$(readlink -f "$DIR")"); + +[ -f "$DIR/custom.pif.json" ] || die "No custom.pif.json found"; + +grep_check_json api_level && die "No migration required"; + +[ "$INSTALL" ] || item "Parsing fields ..."; + +FPFIELDS="BRAND PRODUCT DEVICE RELEASE ID INCREMENTAL TYPE TAGS"; +ALLFIELDS="MANUFACTURER MODEL FINGERPRINT $FPFIELDS SECURITY_PATCH DEVICE_INITIAL_SDK_INT"; + +for FIELD in $ALLFIELDS; do + eval $FIELD=\"$(grep_get_json \"$FIELD\")\"; +done; + +if [ -z "$ID" ] && grep_check_json BUILD_ID; then + item 'Deprecated entry BUILD_ID found, changing to ID field and "*.build.id" property ...'; + ID="$(grep_get_json BUILD_ID)"; +fi; + +if [ -n "$SECURITY_PATCH" ] && ! grep_check_json security_patch; then + item 'Simple entry SECURITY_PATCH found, changing to SECURITY_PATCH field and "*.security_patch" property ...'; +fi; + +if grep_check_json VNDK_VERSION; then + item 'Deprecated entry VNDK_VERSION found, changing to "*.vndk_version" property ...'; + VNDK_VERSION="$(grep_get_json VNDK_VERSION)"; +fi; + +if [ -z "$DEVICE_INITIAL_SDK_INT" ] && grep_check_json FIRST_API_LEVEL; then + item 'Deprecated entry FIRST_API_LEVEL found, changing to DEVICE_INITIAL_SDK_INT field and "*api_level" property ...'; + DEVICE_INITIAL_SDK_INT="$(grep_get_json FIRST_API_LEVEL)"; +fi; + +if [ -z "$RELEASE" -o -z "$INCREMENTAL" -o -z "$TYPE" -o -z "$TAGS" ]; then + item "Missing default fields found, deriving from FINGERPRINT ..."; + IFS='/:' read F1 F2 F3 F4 F5 F6 F7 F8 < "$DIR/custom.pif.json"; + +[ "$INSTALL" ] || cat "$DIR/custom.pif.json"; +