|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Path to the maintainer info file (not needed anymore in minimal format) |
| 4 | + |
| 5 | +# Prompt user for device codename |
| 6 | +read -p "Enter device codename (e.g. PL2, miatoll): " codename |
| 7 | + |
| 8 | +# Prompt user for release tag |
| 9 | +read -p "Enter release tag (e.g. mm-yyyy): " release_tag |
| 10 | + |
| 11 | +# OTA package directory and pattern |
| 12 | +ota_package_dir="out/target/product/${codename}" |
| 13 | +file_path=$(ls ${ota_package_dir}/AndroidOne-*${codename}-*.zip 2>/dev/null) |
| 14 | + |
| 15 | +# Check if the OTA package exists |
| 16 | +if [[ -z "$file_path" ]]; then |
| 17 | + echo "OTA package file not found in ${ota_package_dir}." |
| 18 | + echo "Ensure the file follows the pattern: AndroidOne-*${codename}-*.zip" |
| 19 | + exit 1 |
| 20 | +else |
| 21 | + echo "Found OTA package: $file_path" |
| 22 | +fi |
| 23 | + |
| 24 | +# Extract info |
| 25 | +filename=$(basename "$file_path") |
| 26 | +datetime=$(grep -oP '^ro.build.date.utc=\K\d+' "${ota_package_dir}/system/build.prop" 2>/dev/null || echo "UNKNOWN") |
| 27 | +id=$(sha256sum "$file_path" | awk '{ print $1 }') |
| 28 | +size=$(stat -c%s "$file_path") |
| 29 | +version="15" # or change based on release/version scheme |
| 30 | + |
| 31 | +# Replace this with your actual storage URL base |
| 32 | +base_url="https://storage.googleapis.com/rom" |
| 33 | +url="${base_url}/${filename}" |
| 34 | + |
| 35 | +# Output directory |
| 36 | +output_dir="./OTA/devices" |
| 37 | +mkdir -p "$output_dir" |
| 38 | +output_file="${output_dir}/${codename}.json" |
| 39 | + |
| 40 | +# Create the JSON |
| 41 | +json=$(cat <<EOF |
| 42 | +{ |
| 43 | + "response": [ |
| 44 | + { |
| 45 | + "datetime": "$datetime", |
| 46 | + "filename": "$filename", |
| 47 | + "id": "$id", |
| 48 | + "size": $size, |
| 49 | + "url": "$url", |
| 50 | + "version": "$version" |
| 51 | + } |
| 52 | + ] |
| 53 | +} |
| 54 | +EOF |
| 55 | +) |
| 56 | + |
| 57 | +# Save prettified if jq is available |
| 58 | +if command -v jq &> /dev/null; then |
| 59 | + echo "$json" | jq '.' > "$output_file" |
| 60 | +else |
| 61 | + echo "$json" > "$output_file" |
| 62 | +fi |
| 63 | + |
| 64 | +echo "Minimal OTA JSON saved to $output_file" |
0 commit comments