Skip to content

Commit

Permalink
migrate.sh: retain previous Advanced Settings values
Browse files Browse the repository at this point in the history
  • Loading branch information
osm0sis authored Aug 6, 2024
1 parent a926c52 commit 096c894
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions module/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ esac;

item() { echo "- $@"; }
die() { [ "$INSTALL" ] || echo "$N$N! $@"; exit 1; }
grep_get_json() { eval set -- "$(cat "$FILE" | tr -d '\r\n' | grep -m1 -o "$1"'".*' | cut -d: -f2-)"; echo "$1" | sed -e 's|"|\\\\\\"|g' -e 's|[,}]*$||'; }
grep_check_json() { grep -q "$1" "$FILE" && [ "$(grep_get_json $1)" ]; }
grep_get_json() { local target="$FILE"; [ -n "$2" ] && target="$2"; eval set -- "$(cat "$target" | tr -d '\r\n' | grep -m1 -o "$1"'".*' | cut -d: -f2-)"; echo "$1" | sed -e 's|"|\\\\\\"|g' -e 's|[,}]*$||'; }
grep_check_json() { local target="$FILE"; [ -n "$2" ] && target="$2"; grep -q "$1" "$target" && [ "$(grep_get_json $1 "$target")" ]; }

case "$1" in
-f|--force|force) FORCE=1; shift;;
Expand Down Expand Up @@ -109,10 +109,19 @@ if [ -z "$DEVICE_INITIAL_SDK_INT" -o "$DEVICE_INITIAL_SDK_INT" = "null" ]; then
DEVICE_INITIAL_SDK_INT=25;
fi;

ADVSETTINGS="spoofBuild spoofProps spoofProvider spoofSignature verboseLogs";
spoofBuild=1; spoofProps=1; spoofProvider=1; spoofSignature=0; verboseLogs=0;

if [ -f "$OUT" ]; then
item "Renaming old file to $(basename "$OUT").bak ...";
mv -f "$OUT" "$OUT.bak";
grep -qE "verboseLogs|VERBOSE_LOGS" "$OUT.bak" && ADVANCED=1;
if grep -qE "verboseLogs|VERBOSE_LOGS" "$OUT.bak"; then
ADVANCED=1;
grep_check_json VERBOSE_LOGS "$OUT.bak" && verboseLogs="$(grep_get_json VERBOSE_LOGS "$OUT.bak")";
for SETTING in $ADVSETTINGS; do
eval grep_check_json $SETTING \"$OUT.bak\" \&\& $SETTING=\"$(grep_get_json $SETTING "$OUT.bak")\";
done;
fi;
fi;

[ "$INSTALL" ] || item "Writing fields and properties to updated custom.pif.json ...";
Expand All @@ -129,11 +138,9 @@ echo ' "*.security_patch": "'$SECURITY_PATCH'",';
echo ' "*api_level": "'$DEVICE_INITIAL_SDK_INT'",';
if [ "$ADVANCED" ]; then
echo "$N // Advanced Settings";
echo ' "spoofBuild": "1",';
echo ' "spoofProps": "1",';
echo ' "spoofProvider": "1",';
echo ' "spoofSignature": "0",';
echo ' "verboseLogs": "0",';
for SETTING in $ADVSETTINGS; do
eval echo '\ \ \ \ \"$SETTING\": \"'\$$SETTING'\",';
done;
fi) | sed '$s/,/\n}/' > "$OUT";

[ "$INSTALL" ] || cat "$OUT";

0 comments on commit 096c894

Please sign in to comment.