Last active
June 10, 2025 04:36
-
-
Save adithya2306/322946de5d4603f0c8d1eec54d6420d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Forked from https://github.com/osm0sis/PlayIntegrityFork/blob/main/module/autopif2.sh | |
| FORCE_DEPTH=1 | |
| until [ -z "$1" ]; do | |
| case "$1" in | |
| -h|--help|help) echo -e "./autopif2.sh [-p] [-d #] [-m device]"; exit 0;; | |
| -p|--preview|preview) FORCE_PREVIEW=1; shift;; | |
| -d|--depth|depth) echo -e "$2" | grep -q '^[1-9]$' || exit 1; FORCE_DEPTH=$2; shift 2;; | |
| -m|--device) DEVICE_OVERRIDE="$2"; shift 2;; | |
| *) break;; | |
| esac | |
| done | |
| echo -e "Pixel Beta pif.json generator script \ | |
| \n by osm0sis @ xda-developers" | |
| DIR="$(pwd)" | |
| TEMP_DIR="$(mktemp -d)" | |
| item() { echo -e "\n- $@"; } | |
| die() { echo -e "\nError: $@!"; exit 1; } | |
| cd "$TEMP_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 -n1) 2>&1 || exit 1 | |
| if grep -qE 'Developer Preview|tooltip>.*preview program' PIXEL_LATEST_HTML && [ ! "$FORCE_PREVIEW" ]; then | |
| wget -q -O PIXEL_BETA_HTML --no-check-certificate $(grep -o 'https://developer.android.com/about/versions/.*[0-9]"' PIXEL_VERSIONS_HTML | sort -ru | cut -d\" -f1 | head -n2 | tail -n1) 2>&1 || exit 1 | |
| else | |
| TITLE="Preview " | |
| mv -f PIXEL_LATEST_HTML PIXEL_BETA_HTML | |
| fi | |
| wget -q -O PIXEL_OTA_HTML --no-check-certificate https://developer.android.com$(grep -o 'href=".*download-ota.*"' PIXEL_BETA_HTML | cut -d\" -f2 | head -n$FORCE_DEPTH | tail -n1) 2>&1 || exit 1 | |
| echo -e "$(grep -m1 -oE 'tooltip>Android .*[0-9]' PIXEL_OTA_HTML | cut -d\> -f2) $TITLE$(grep -oE 'tooltip>QPR.* Beta' PIXEL_OTA_HTML | cut -d\> -f2 | head -n$FORCE_DEPTH | tail -n1)" | |
| RAW_DATE="$(grep -m1 -A1 'Release date' PIXEL_OTA_HTML | tail -n1 | sed 's;.*<td>\(.*\)</td>.*;\1;')" | |
| BETA_REL_DATE="$(date -d "$RAW_DATE" '+%Y-%m-%d')" | |
| BETA_EXP_DATE="$(date -d "$BETA_REL_DATE +42 days" '+%Y-%m-%d')" | |
| echo -e "Beta Released: $BETA_REL_DATE \ | |
| \nEstimated Expiry: $BETA_EXP_DATE" | |
| MODEL_LIST="$(grep -A1 'tr id=' PIXEL_OTA_HTML | grep 'td' | sed 's;.*<td>\(.*\)</td>;\1;')" | |
| PRODUCT_LIST="$(grep -o 'ota/.*_beta' PIXEL_OTA_HTML | cut -d\/ -f2)" | |
| OTA_LIST="$(grep 'ota/.*_beta' PIXEL_OTA_HTML | cut -d\" -f2)" | |
| select_device_by_name() { | |
| local name="$1" | |
| local index=0 | |
| while read -r product; do | |
| device="${product%_beta}" | |
| if [[ "$device" == "$name" ]]; then | |
| break | |
| fi | |
| ((index++)) | |
| done <<< "$PRODUCT_LIST" | |
| MODEL=$(echo "$MODEL_LIST" | sed -n "$((index + 1))p") | |
| PRODUCT=$(echo "$PRODUCT_LIST" | sed -n "$((index + 1))p") | |
| OTA=$(echo "$OTA_LIST" | sed -n "$((index + 1))p") | |
| DEVICE="${PRODUCT%_beta}" | |
| item "Selected device: $MODEL ($PRODUCT)" | |
| } | |
| set_random_device() { | |
| item "Selecting Pixel Beta device ..." | |
| local count | |
| count=$(echo "$MODEL_LIST" | wc -l) | |
| local rand=$((RANDOM % count + 1)) | |
| MODEL=$(echo "$MODEL_LIST" | sed -n "${rand}p") | |
| PRODUCT=$(echo "$PRODUCT_LIST" | sed -n "${rand}p") | |
| OTA=$(echo "$OTA_LIST" | sed -n "${rand}p") | |
| DEVICE="${PRODUCT%_beta}" | |
| echo "$MODEL ($PRODUCT)" | |
| } | |
| if [[ -n "$DEVICE_OVERRIDE" ]]; then | |
| if echo "$PRODUCT_LIST" | grep -q "${DEVICE_OVERRIDE}_beta"; then | |
| select_device_by_name "$DEVICE_OVERRIDE" | |
| else | |
| die "Device '$DEVICE_OVERRIDE' not found in list." | |
| fi | |
| else | |
| set_random_device | |
| fi | |
| (ulimit -f 2; wget -q -O PIXEL_ZIP_METADATA --no-check-certificate $OTA) 2>/dev/null | |
| FINGERPRINT="$(grep -am1 'post-build=' PIXEL_ZIP_METADATA 2>/dev/null | cut -d= -f2)" | |
| SECURITY_PATCH="$(grep -am1 'security-patch-level=' PIXEL_ZIP_METADATA 2>/dev/null | cut -d= -f2)" | |
| if [ -z "$FINGERPRINT" -o -z "$SECURITY_PATCH" ]; then | |
| die "Error: Failed to extract information from metadata!" | |
| fi | |
| cd "$DIR" | |
| item "Dumping values to minimal pif.json ..." | |
| cat <<EOF | tee pif.json | |
| { | |
| "MANUFACTURER": "Google", | |
| "MODEL": "$MODEL", | |
| "FINGERPRINT": "$FINGERPRINT", | |
| "PRODUCT": "$PRODUCT", | |
| "DEVICE": "$DEVICE", | |
| "SECURITY_PATCH": "$SECURITY_PATCH", | |
| "DEVICE_INITIAL_SDK_INT": "32" | |
| } | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment