Skip to content

Commit 0d05112

Browse files
committed
Replace autopif with autopif2
1 parent d8ff58d commit 0d05112

File tree

3 files changed

+165
-133
lines changed

3 files changed

+165
-133
lines changed

module/action.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MODPATH="${0%/*}"
44
set +o standalone
55
unset ASH_STANDALONE
66

7-
sh $MODPATH/autopif.sh || exit 1
7+
sh $MODPATH/autopif2.sh || exit 1
88

99
echo -e "\nDone!"
1010

module/autopif.sh

Lines changed: 0 additions & 132 deletions
This file was deleted.

module/autopif2.sh

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/system/bin/sh
2+
3+
if [ "$USER" != "root" -a "$(whoami 2>/dev/null)" != "root" ]; then
4+
echo "autopif2: need root permissions";
5+
exit 1;
6+
fi;
7+
8+
case "$1" in
9+
-h|--help|help) echo "sh autopif2.sh [-a]"; exit 0;;
10+
-a|--advanced|advanced) ARGS="-a"; shift;;
11+
esac;
12+
13+
echo "Pixel Beta pif.json generator script \
14+
\n by osm0sis @ xda-developers";
15+
16+
case "$0" in
17+
*.sh) DIR="$0";;
18+
*) DIR="$(lsof -p $$ 2>/dev/null | grep -o '/.*autopif2.sh$')";;
19+
esac;
20+
DIR=$(dirname "$(readlink -f "$DIR")");
21+
22+
item() { echo "\n- $@"; }
23+
die() { echo "\nError: $@, install busybox!"; exit 1; }
24+
25+
find_busybox() {
26+
[ -n "$BUSYBOX" ] && return 0;
27+
local path;
28+
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
29+
if [ -f "$path" ]; then
30+
BUSYBOX="$path";
31+
return 0;
32+
fi;
33+
done;
34+
return 1;
35+
}
36+
37+
if ! which wget >/dev/null || grep -q "wget-curl" $(which wget); then
38+
if ! find_busybox; then
39+
die "wget not found";
40+
elif $BUSYBOX ping -c1 -s2 android.com 2>&1 | grep -q "bad address"; then
41+
die "wget broken";
42+
else
43+
wget() { $BUSYBOX wget "$@"; }
44+
fi;
45+
fi;
46+
47+
if date -D '%s' -d "$(date '+%s')" 2>&1 | grep -q "bad date"; then
48+
if ! find_busybox; then
49+
die "date broken";
50+
else
51+
date() { $BUSYBOX date "$@"; }
52+
fi;
53+
fi;
54+
55+
if [ "$DIR" = /data/adb/modules/playintegrityfix ]; then
56+
DIR=$DIR/autopif2;
57+
mkdir -p $DIR;
58+
fi;
59+
cd "$DIR";
60+
61+
item "Crawling Android Developers for latest Pixel Beta ...";
62+
wget -q -O PIXEL_GSI_HTML --no-check-certificate https://developer.android.com/topic/generic-system-image/releases 2>&1 || exit 1;
63+
grep -m1 -o 'li>.*(Beta)' PIXEL_GSI_HTML | cut -d\> -f2;
64+
65+
BETA_REL_DATE="$(date -D '%B %e, %Y' -d "$(grep -m1 -o 'Date:.*' PIXEL_GSI_HTML | cut -d\ -f2-4)" '+%Y-%m-%d')";
66+
BETA_EXP_DATE="$(date -D '%s' -d "$(($(date -D '%Y-%m-%d' -d "$BETA_REL_DATE" '+%s') + 60 * 60 * 24 * 7 * 6))" '+%Y-%m-%d')";
67+
echo "Beta Released: $BETA_REL_DATE \
68+
\nEstimated Expiry: $BETA_EXP_DATE";
69+
70+
RELEASE="$(grep -m1 'corresponding Google Pixel builds' PIXEL_GSI_HTML | grep -o '/versions/.*' | cut -d\/ -f3)";
71+
ID="$(grep -m1 -o 'Build:.*' PIXEL_GSI_HTML | cut -d\ -f2)";
72+
INCREMENTAL="$(grep -m1 -o "$ID-.*-" PIXEL_GSI_HTML | cut -d- -f2)";
73+
74+
wget -q -O PIXEL_GET_HTML --no-check-certificate https://developer.android.com$(grep -m1 'corresponding Google Pixel builds' PIXEL_GSI_HTML | grep -o 'href.*' | cut -d\" -f2) 2>&1 || exit 1;
75+
wget -q -O PIXEL_BETA_HTML --no-check-certificate https://developer.android.com$(grep -m1 'Factory images for Google Pixel' PIXEL_GET_HTML | grep -o 'href.*' | cut -d\" -f2) 2>&1 || exit 1;
76+
77+
MODEL_LIST="$(grep -A1 'tr id=' PIXEL_BETA_HTML | grep 'td' | sed 's;.*<td>\(.*\)</td>;\1;')";
78+
PRODUCT_LIST="$(grep -o 'factory/.*_beta' PIXEL_BETA_HTML | cut -d\/ -f2)";
79+
80+
wget -q -O PIXEL_SECBULL_HTML --no-check-certificate https://source.android.com/docs/security/bulletin/pixel 2>&1 || exit 1;
81+
82+
SECURITY_PATCH="$(grep -A15 "$(grep -m1 -o 'Security patch level:.*' PIXEL_GSI_HTML | cut -d\ -f4-)" PIXEL_SECBULL_HTML | grep -m1 -B1 '</tr>' | grep 'td' | sed 's;.*<td>\(.*\)</td>;\1;')";
83+
84+
case "$1" in
85+
-m)
86+
DEVICE="$(getprop ro.product.device)";
87+
case "$PRODUCT_LIST" in
88+
*${DEVICE}_beta*)
89+
MODEL="$(getprop ro.product.model)";
90+
PRODUCT="${DEVICE}_beta";
91+
;;
92+
esac;
93+
;;
94+
esac;
95+
item "Selecting Pixel Beta device ...";
96+
if [ -z "$PRODUCT" ]; then
97+
set_random_beta() {
98+
local list_count="$(echo "$MODEL_LIST" | wc -l)";
99+
local list_rand="$((RANDOM % $list_count + 1))";
100+
local IFS=$'\n';
101+
set -- $MODEL_LIST;
102+
MODEL="$(eval echo \${$list_rand})";
103+
set -- $PRODUCT_LIST;
104+
PRODUCT="$(eval echo \${$list_rand})";
105+
DEVICE="$(echo "$PRODUCT" | sed 's/_beta//')";
106+
}
107+
set_random_beta;
108+
fi;
109+
echo "$MODEL ($PRODUCT)";
110+
111+
item "Dumping values to minimal pif.json ...";
112+
cat <<EOF | tee pif.json;
113+
{
114+
"MANUFACTURER": "Google",
115+
"MODEL": "$MODEL",
116+
"FINGERPRINT": "google/$PRODUCT/$DEVICE:$RELEASE/$ID/$INCREMENTAL:user/release-keys",
117+
"PRODUCT": "$PRODUCT",
118+
"DEVICE": "$DEVICE",
119+
"SECURITY_PATCH": "$SECURITY_PATCH",
120+
"DEVICE_INITIAL_SDK_INT": "32"
121+
}
122+
EOF
123+
124+
for MIGRATE in migrate.sh /data/adb/modules/playintegrityfix/migrate.sh; do
125+
[ -f "$MIGRATE" ] && break;
126+
done;
127+
if [ -f "$MIGRATE" ]; then
128+
OLDJSON=/data/adb/modules/playintegrityfix/custom.pif.json;
129+
[ -f "$OLDJSON" ] && grep -qE "verboseLogs|VERBOSE_LOGS" $OLDJSON && ARGS="-a";
130+
item "Converting pif.json to custom.pif.json with migrate.sh:";
131+
rm -f custom.pif.json;
132+
sh $MIGRATE -i $ARGS pif.json;
133+
if [ -n "$ARGS" ]; then
134+
grep_json() { grep -m1 "$1" $2 | cut -d\" -f4; }
135+
verboseLogs=$(grep_json "VERBOSE_LOGS" $OLDJSON);
136+
ADVSETTINGS="spoofBuild spoofProps spoofProvider spoofSignature verboseLogs";
137+
for SETTING in $ADVSETTINGS; do
138+
eval [ -z \"\$$SETTING\" ] \&\& $SETTING=$(grep_json "$SETTING" $OLDJSON);
139+
eval TMPVAL=\$$SETTING;
140+
[ -n "$TMPVAL" ] && sed -i "s;\($SETTING\": \"\).;\1$TMPVAL;" custom.pif.json;
141+
done;
142+
fi;
143+
grep -q '//"\*.security_patch"' $OLDJSON && sed -i 's;"\*.security_patch";//"\*.security_patch";' custom.pif.json;
144+
sed -i "s;};\n // Beta Released: $BETA_REL_DATE\n // Estimated Expiry: $BETA_EXP_DATE\n};" custom.pif.json;
145+
cat custom.pif.json;
146+
fi;
147+
148+
if [ "$DIR" = /data/adb/modules/playintegrityfix/autopif2 ]; then
149+
if [ -f /data/adb/modules/playintegrityfix/migrate.sh ]; then
150+
NEWNAME="custom.pif.json";
151+
else
152+
NEWNAME="pif.json";
153+
fi;
154+
if [ -f "../$NEWNAME" ]; then
155+
item "Renaming old file to $NEWNAME.bak ...";
156+
mv -fv ../$NEWNAME ../$NEWNAME.bak;
157+
fi;
158+
item "Installing new json ...";
159+
cp -fv $NEWNAME ..;
160+
if [ -f /data/adb/modules/playintegrityfix/killgms.sh ]; then
161+
item "Killing any running GMS DroidGuard process ...";
162+
sh /data/adb/modules/playintegrityfix/killgms.sh 2>&1 || true;
163+
fi;
164+
fi;

0 commit comments

Comments
 (0)