#!/system/bin/sh if [ "$USER" != "root" -a "$(whoami 2>/dev/null)" != "root" ]; then echo "autopif2: need root permissions"; exit 1; fi; case "$HOME" in *termux*) echo "autopif2: need su root environment"; exit 1;; esac; FORCE_TOP=1; FORCE_DEPTH=1; until [ -z "$1" ]; do case "$1" in -h|--help|help) echo "sh autopif2.sh [-a|-s] [-m] [-t #] [-d #]"; exit 0;; -a|--advanced|advanced) ARGS="-a"; shift;; -s|--strong|strong) ARGS="-a"; PATCH_COMMENT=1; spoofProvider=0; shift;; -m|--match|match) FORCE_MATCH=1; shift;; -t|--top|top) echo "$2" | grep -q '^[1-9]$' || exit 1; FORCE_TOP=$2; shift 2;; -d|--depth|depth) echo "$2" | grep -q '^[1-9]$' || exit 1; FORCE_DEPTH=$2; shift 2;; *) break;; esac; done; echo "Pixel Beta pif.json generator script \ \n by osm0sis @ xda-developers"; case "$0" in *.sh) DIR="$0";; *) DIR="$(lsof -p $$ 2>/dev/null | grep -o '/.*autopif2.sh$')";; esac; DIR=$(dirname "$(readlink -f "$DIR")"); item() { echo "\n- $@"; } die() { echo "\nError: $@, install busybox!"; exit 1; } find_busybox() { [ -n "$BUSYBOX" ] && return 0; local path; 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 if [ -f "$path" ]; then BUSYBOX="$path"; return 0; fi; done; return 1; } if which wget2 >/dev/null; then wget() { wget2 "$@"; } elif ! which wget >/dev/null || grep -q "wget-curl" $(which wget); then if ! find_busybox; then die "wget not found"; elif $BUSYBOX ping -c1 -s2 android.com 2>&1 | grep -q "bad address"; then die "wget broken"; else wget() { $BUSYBOX wget "$@"; } fi; fi; if date -D '%s' -d "$(date '+%s')" 2>&1 | grep -qE "bad date|invalid option"; then if ! find_busybox; then die "date broken"; else date() { $BUSYBOX date "$@"; } fi; fi; if ! echo "A\nB" | grep -m1 -A1 "A" | grep -q "B"; then if ! find_busybox; then die "grep broken"; else grep() { $BUSYBOX grep "$@"; } fi; fi; if [ "$DIR" = /data/adb/modules/playintegrityfix ]; then DIR=$DIR/autopif2; mkdir -p $DIR; fi; cd "$DIR"; item "Crawling Android Developers for latest Pixel Beta ..."; wget -q -O PIXEL_VERSIONS_HTML --no-check-certificate https://developer.android.com/about/versions 2>&1 || exit 1; wget -q -O PIXEL_LATEST_HTML --no-check-certificate $(grep -o 'https://developer.android.com/about/versions/.*[0-9]"' PIXEL_VERSIONS_HTML | sort -ru | cut -d\" -f1 | head -n$FORCE_TOP | tail -n1) 2>&1 || exit 1; wget -q -O PIXEL_OTA_HTML --no-check-certificate https://developer.android.com$(grep -o 'href=".*download-ota.*"' PIXEL_LATEST_HTML | grep 'qpr' | cut -d\" -f2 | head -n$FORCE_DEPTH | tail -n1) 2>&1 || exit 1; echo "$(grep -m1 -oE 'tooltip>Android .*[0-9]' PIXEL_OTA_HTML | cut -d\> -f2) $(grep -oE 'tooltip>QPR.* Beta' PIXEL_OTA_HTML | cut -d\> -f2 | head -n$FORCE_DEPTH | tail -n1)"; BETA_REL_DATE="$(date -D '%B %e, %Y' -d "$(grep -m1 -A1 'Release date' PIXEL_OTA_HTML | tail -n1 | sed 's;.*