diff --git a/module/autopif.sh b/module/autopif.sh index de82d4a..f403f97 100644 --- a/module/autopif.sh +++ b/module/autopif.sh @@ -1,26 +1,26 @@ #!/system/bin/sh -if [ "$USER" != "root" -o "$(whoami 2>/dev/null)" != "root" ]; then - echo "autopif: need root permissions"; +if [ "$USER" != "root" -a "$(whoami 2>/dev/null)" != "root" ]; then + echo "autopif2: need root permissions"; exit 1; fi; case "$1" in - -h|--help|help) echo "sh autopif.sh [-a]"; exit 0;; - -a|--advanced|advanced) ARGS="-a";; + -h|--help|help) echo "sh autopif2.sh [-a]"; exit 0;; + -a|--advanced|advanced) ARGS="-a"; shift;; esac; -echo "Xiaomi.eu pif.json extractor script \ +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 '/.*autopif.sh$')";; + *) DIR="$(lsof -p $$ 2>/dev/null | grep -o '/.*autopif2.sh$')";; esac; DIR=$(dirname "$(readlink -f "$DIR")"); item() { echo "\n- $@"; } -die() { echo "\nError: $@!"; exit 1; } +die() { echo "\nError: $@, install busybox!"; exit 1; } find_busybox() { [ -n "$BUSYBOX" ] && return 0; @@ -36,59 +36,90 @@ find_busybox() { if ! which wget >/dev/null || grep -q "wget-curl" $(which wget); then if ! find_busybox; then - die "wget not found, install busybox"; + die "wget not found"; elif $BUSYBOX ping -c1 -s2 android.com 2>&1 | grep -q "bad address"; then - die "wget broken, install busybox"; + die "wget broken"; else wget() { $BUSYBOX wget "$@"; } fi; fi; +if date -D '%s' -d "$(date '+%s')" 2>&1 | grep -q "bad date"; then + if ! find_busybox; then + die "date broken"; + else + date() { $BUSYBOX date "$@"; } + fi; +fi; + if [ "$DIR" = /data/adb/modules/playintegrityfix ]; then - DIR=$DIR/autopif; + DIR=$DIR/autopif2; mkdir -p $DIR; fi; cd "$DIR"; -if [ ! -f apktool_2.0.3-dexed.jar ]; then - item "Downloading Apktool ..."; - wget --no-check-certificate -O apktool_2.0.3-dexed.jar https://github.com/osm0sis/APK-Patcher/raw/master/tools/apktool_2.0.3-dexed.jar 2>&1 || exit 1; +item "Crawling Android Developers for latest Pixel Beta ..."; +wget -q -O PIXEL_GSI_HTML --no-check-certificate https://developer.android.com/topic/generic-system-image/releases 2>&1 || exit 1; +grep -m1 -o 'li>.*(Beta)' PIXEL_GSI_HTML | cut -d\> -f2; + +BETA_REL_DATE="$(date -D '%B %e, %Y' -d "$(grep -m1 -o 'Date:.*' PIXEL_GSI_HTML | cut -d\ -f2-4)" '+%Y-%m-%d')"; +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')"; +echo "Beta Released: $BETA_REL_DATE \ + \nEstimated Expiry: $BETA_EXP_DATE"; + +RELEASE="$(grep -m1 'corresponding Google Pixel builds' PIXEL_GSI_HTML | grep -o '/versions/.*' | cut -d\/ -f3)"; +ID="$(grep -m1 -o 'Build:.*' PIXEL_GSI_HTML | cut -d\ -f2)"; +INCREMENTAL="$(grep -m1 -o "$ID-.*-" PIXEL_GSI_HTML | cut -d- -f2)"; + +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; +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; + +MODEL_LIST="$(grep -A1 'tr id=' PIXEL_BETA_HTML | grep 'td' | sed 's;.*