#!/bin/bash # Setup temp directory TMP_DIR=$(mktemp -d) cd "$TMP_DIR" || exit 1 # Ensure cleanup on exit cleanup() { rm -rf "$TMP_DIR" } trap cleanup EXIT # Helper function for downloads download() { local url="$1" local output="$2" if command -v curl > /dev/null 2>&1; then curl -sL --connect-timeout 10 "$url" -o "$output" elif command -v wget > /dev/null 2>&1; then wget -T 10 -qO "$output" "$url" else echo "Error: neither curl nor wget found" exit 1 fi } # 1. Fetch Latest Pixel Canary URL download "https://developer.android.com/about/versions" "PIXEL_VERSIONS_HTML" LATEST_URL=$(grep -o 'https://developer.android.com/about/versions/.*[0-9]"' "PIXEL_VERSIONS_HTML" | sort -ru | cut -d\" -f1 | head -n1) download "$LATEST_URL" "PIXEL_LATEST_HTML" # 2. Extract Device Information FI_URL="https://developer.android.com$(grep -o 'href=".*download.*"' "PIXEL_LATEST_HTML" | grep 'qpr' | cut -d\" -f2 | head -n1)" download "$FI_URL" "PIXEL_FI_HTML" MODEL_LIST="$(grep -A1 'tr id=' "PIXEL_FI_HTML" | grep 'td' | sed 's;.*\(.*\).*;\1;')" PRODUCT_LIST="$(grep 'tr id=' "PIXEL_FI_HTML" | sed 's;.*.*;\1_beta;')" # 3. Selection Logic count_model=$(echo "$MODEL_LIST" | wc -l) count_product=$(echo "$PRODUCT_LIST" | wc -l) if [ "$count_model" -ne "$count_product" ] || [ "$count_model" -eq 0 ]; then MODEL="Pixel 6" PRODUCT="oriole_beta" else rand_index=$(( RANDOM % count_model )) MODEL=$(echo "$MODEL_LIST" | sed -n "$((rand_index + 1))p") PRODUCT=$(echo "$PRODUCT_LIST" | sed -n "$((rand_index + 1))p") fi DEVICE="$(echo "$PRODUCT" | sed 's/_beta//')" # 4. Fetch Build Details from Flash Tool download "https://flash.android.com" "PIXEL_FLASH_HTML" FLASH_KEY=$(grep -o ' /dev/null 2>&1; then curl -H "Referer: https://flash.android.com" -s "$STATION_URL" > "PIXEL_STATION_JSON" else wget --header "Referer: https://flash.android.com" -qO - "$STATION_URL" > "PIXEL_STATION_JSON" fi # Extract Canary Build Info if command -v tac > /dev/null 2>&1; then tac "PIXEL_STATION_JSON" | grep -m1 -A13 '"canary": true' > "PIXEL_CANARY_JSON" else grep -A20 '"canary": true' "PIXEL_STATION_JSON" | head -n 20 > "PIXEL_CANARY_JSON" fi ID="$(grep 'releaseCandidateName' "PIXEL_CANARY_JSON" | cut -d\" -f4)" INCREMENTAL="$(grep 'buildId' "PIXEL_CANARY_JSON" | cut -d\" -f4)" RELEASE="16" SDK_INT="36" # 5. Security Patch Determination download "https://source.android.com/docs/security/bulletin/pixel" "PIXEL_SECBULL_HTML" CANARY_ID="$(grep '"id"' "PIXEL_CANARY_JSON" | sed -e 's;.*canary-\(.*\)".*;\1;' -e 's;^\(.\{4\}\);\1-;')" SECURITY_PATCH="$(grep "$CANARY_ID" "PIXEL_SECBULL_HTML" | sed 's;.*\(.*\);\1;' | head -n1)" if [ -z "$SECURITY_PATCH" ]; then SECURITY_PATCH="${CANARY_ID}-05" fi # 6. Metadata and Fingerprint BRAND="google" MANUFACTURER="Google" PRODUCT_NAME="$DEVICE" TYPE="user" TAG="" DEVICE_INITIAL_SDK_INT="32" DEBUG="false" FINGERPRINT="$BRAND/$PRODUCT_NAME/$DEVICE:$RELEASE/$ID/$INCREMENTAL:$TYPE/release-keys" # 7. Generate pif.json cat < "$OLDPWD/pif.json" { "ID": "$ID", "BRAND": "$BRAND", "DEVICE": "$DEVICE", "FINGERPRINT": "$FINGERPRINT", "MANUFACTURER": "$MANUFACTURER", "MODEL": "$MODEL", "PRODUCT": "$PRODUCT_NAME", "SECURITY_PATCH": "$SECURITY_PATCH", "DEVICE_INITIAL_SDK_INT": "$DEVICE_INITIAL_SDK_INT", "TYPE": "$TYPE", "TAG": "$TAG", "RELEASE": "$RELEASE", "SDK_INT": "$SDK_INT", "DEBUG": "$DEBUG" } EOF echo "Generated pif.json successfully."