Skip to content

Commit d535747

Browse files
authored
autopif.sh: improve error catching, busybox finding, etc.
- simplify error display - catch missing inject_fields.xml or FINGERPRINT, from e.g. bad download/extraction failure - more robust busybox finding function - accept a local migrate.sh and give it precedence over the module copy
1 parent 98bb234 commit d535747

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

module/autopif.sh

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,31 @@ case "$0" in
1414
esac;
1515
DIR=$(dirname "$(readlink -f "$DIR")");
1616

17+
item() { echo "\n- $@"; }
18+
die() { echo "Error: $@!"; exit 1; }
19+
20+
find_busybox() {
21+
[ -n "$BUSYBOX" ] && return 0;
22+
local path;
23+
for path in /data/adb/modules/busybox-ndk/system/*/busybox /data/adb/magisk/busybox /data/adb/ksu/bin/busybox /data/adb/ap/bin/busybox; do
24+
if [ -f "$path" ]; then
25+
BUSYBOX="$path";
26+
return 0;
27+
fi;
28+
done;
29+
return 1;
30+
}
31+
1732
if ! which wget >/dev/null || grep -q "wget-curl" $(which wget); then
18-
if [ -f /data/adb/modules/busybox-ndk/system/*/busybox ]; then
19-
wget() { /data/adb/modules/busybox-ndk/system/*/busybox wget "$@"; }
20-
elif [ -f /data/adb/magisk/busybox ] && /data/adb/magisk/busybox ping -c1 -s2 sourceforge.net 2>&1 | grep -vq "bad address"; then
21-
wget() { /data/adb/magisk/busybox wget "$@"; }
22-
elif [ -f /data/adb/ksu/bin/busybox ]; then
23-
wget() { /data/adb/ksu/bin/busybox wget "$@"; }
24-
elif [ -f /data/adb/ap/bin/busybox ]; then
25-
wget() { /data/adb/ap/bin/busybox wget "$@"; }
33+
if ! find_busybox; then
34+
die "wget not found, install busybox";
35+
elif $BUSYBOX ping -c1 -s2 android.com 2>&1 | grep -q "bad address"; then
36+
die "wget broken, install busybox";
2637
else
27-
echo "Error: wget not found, install busybox!";
28-
exit 1;
38+
wget() { $BUSYBOX wget "$@"; }
2939
fi;
3040
fi;
3141

32-
item() { echo "\n- $@"; }
33-
3442
if [ "$DIR" = /data/adb/modules/playintegrityfix ]; then
3543
DIR=$DIR/autopif;
3644
mkdir -p $DIR;
@@ -61,30 +69,31 @@ if [ ! -d $OUT ]; then
6169
if grep -q "apex" $PREFIX/bin/dalvikvm; then
6270
DALVIKVM=$PREFIX/bin/dalvikvm;
6371
else
64-
echo 'Error: Outdated Termux packages, run "pkg upgrade" from a user prompt!';
65-
exit 1;
72+
die 'Outdated Termux packages, run "pkg upgrade" from a user prompt';
6673
fi;
6774
else
68-
echo "Error: Play Store Termux not supported, use GitHub/F-Droid Termux!";
69-
exit 1;
75+
die "Play Store Termux not supported, use GitHub/F-Droid Termux";
7076
fi;
7177
fi;
7278
$DALVIKVM -Xnoimage-dex2oat -cp apktool_2.0.3-dexed.jar brut.apktool.Main d -f --no-src -p $OUT -o $OUT $APKNAME || exit 1;
79+
[ -f $OUT/res/xml/inject_fields.xml ] || die "inject_fields.xml not found";
7380
fi;
7481

7582
item "Converting inject_fields.xml to pif.json ...";
7683
(echo '{';
7784
grep -o '<field.*' $OUT/res/xml/inject_fields.xml | sed 's;.*name=\(".*"\) type.* value=\(".*"\).*; \1: \2,;g';
7885
echo ' "DEVICE_INITIAL_SDK_INT": "32",' ) | sed '$s/,/\n}/' | tee pif.json;
86+
grep -q "FINGERPRINT" pif.json || die "Failed to extract information from inject_fields.xml";
7987

80-
if [ -f /data/adb/modules/playintegrityfix/migrate.sh ]; then
88+
for MIGRATE in migrate.sh /data/adb/modules/playintegrityfix/migrate.sh; do
89+
[ -f "$MIGRATE" ] && break;
90+
done;
91+
if [ -f "$MIGRATE" ]; then
8192
OLDJSON=/data/adb/modules/playintegrityfix/custom.pif.json;
82-
if [ -f "$OLDJSON" ]; then
83-
grep -qE "verboseLogs|VERBOSE_LOGS" $OLDJSON && ARGS="-a";
84-
fi;
93+
[ -f "$OLDJSON" ] && grep -qE "verboseLogs|VERBOSE_LOGS" $OLDJSON && ARGS="-a";
8594
item "Converting pif.json to custom.pif.json with migrate.sh:";
8695
rm -f custom.pif.json;
87-
sh /data/adb/modules/playintegrityfix/migrate.sh -i $ARGS pif.json;
96+
sh $MIGRATE -i $ARGS pif.json;
8897
if [ -n "$ARGS" ]; then
8998
grep_json() { grep -m1 "$1" $2 | cut -d\" -f4; }
9099
verboseLogs=$(grep_json "VERBOSE_LOGS" $OLDJSON);

0 commit comments

Comments
 (0)