A127f U7 Auto Patch Page

# 2. Load saved state (if any) if [ -f "$STATE_FILE" ]; then SAVED_PATCH_VERSION=$(jq -r .patch_version "$STATE_FILE") else SAVED_PATCH_VERSION="0" fi log "Last applied patch version: $SAVED_PATCH_VERSION"

# Example fastboot commands (adjust to your actual zip content): fastboot flash boot "$PATCH_FILE/boot.img" fastboot flash system "$PATCH_FILE/system.img" fastboot flash radio "$PATCH_FILE/radio.img" fastboot reboot else log "Unknown patch_type '$PATCH_TYPE' – aborting." rm -rf "$TMP_DIR" exit 1 fi

# 6. Create temp folder mkdir -p "$TMP_DIR" PATCH_FILE="$TMP_DIR/patch_$REMOTE_PATCH_VERSION.zip"

# Reboot into recovery reboot recovery # The script will *not* continue past this point; TWRP will flash, # then reboot back into Android where the script will run again. # To avoid an infinite loop we check the state file later. elif [ "$PATCH_TYPE" = "fastboot" ]; then # -------------------------------------------------------------- # Fastboot approach – we reboot to fastboot and flash images. # -------------------------------------------------------------- log "Rebooting to fastboot …" reboot bootloader # Give the device a few seconds to settle sleep 8 a127f u7 auto patch

# Cleanup rm -rf "$TMP_DIR"

# 9. Apply the patch if [ "$PATCH_TYPE" = "twrp_zip" ]; then # -------------------------------------------------------------- # TWRP approach – we reboot into recovery and let TWRP flash it. # -------------------------------------------------------------- log "Rebooting into TWRP to install ZIP …" # Store path in a known location that TWRP can read after reboot. cp "$PATCH_FILE" /cache/recovery/auto_patch.zip

# 10. Record success (this line runs only for the TWRP‑case *after* the device # comes back online; for fastboot it runs immediately after flashing) log "Patch $REMOTE_PATCH_VERSION applied successfully – persisting state." cat > "$STATE_FILE" <<EOF # To avoid an infinite loop we check the state file later

log() echo "[$LOG_TAG] $*"

if [ -z "$MANIFEST_JSON" ]; then log "Empty manifest – aborting." exit 1 fi

# 4. Parse manifest (requires jq) REMOTE_PATCH_VERSION=$(echo "$MANIFEST_JSON" | jq -r .patch_version) PATCH_URL=$(echo "$MANIFEST_JSON" | jq -r .patch_url) PATCH_SHA256=$(echo "$MANIFEST_JSON" | jq -r .patch_sha256) PATCH_TYPE=$(echo "$MANIFEST_JSON" | jq -r .patch_type) # "twrp_zip" or "fastboot" Apply the patch if [ "$PATCH_TYPE" = "twrp_zip"

# 8. Verify SHA‑256 log "Verifying integrity …" CALC_SHA=$(sha256sum "$PATCH_FILE" | awk 'print $1') if [ "$CALC_SHA" != "$PATCH_SHA256" ]; then log "Checksum mismatch! Expected $PATCH_SHA256, got $CALC_SHA" rm -rf "$TMP_DIR" exit 1 fi log "Checksum OK."

# 7. Download the patch log "Downloading patch from $PATCH_URL ..." if command -v curl >/dev/null 2>&1; then curl -fLo "$PATCH_FILE" "$PATCH_URL" elif command -v wget >/dev/null 2>&1; then wget -O "$PATCH_FILE" "$PATCH_URL" fi