mirror of
git://f0xx.org/android_cast
synced 2026-07-29 03:38:52 +03:00
crash handler snapshot, unverified
This commit is contained in:
90
scripts/generate-ota-v0.sh
Executable file
90
scripts/generate-ota-v0.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate v0 OTA artifacts for one APK (stdout = channel stable.json).
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/generate-ota-v0.sh path/to/app-release.apk https://host[:port] [out-dir]
|
||||
#
|
||||
# Writes under out-dir (default: ./ota-publish):
|
||||
# v0/ota/channel/stable.json
|
||||
# v0/ota/00/00.MM/00.MM.mm/android_cast_00.MM.mm.BB_manifest.json
|
||||
# v0/ota/00/00.MM/00.MM.mm/android_cast_00.MM.mm.BB_sign.json
|
||||
# (copy APK to …/android_cast_00.MM.mm.BB.otapkg if out-dir set)
|
||||
set -euo pipefail
|
||||
|
||||
apk="${1:?APK path required}"
|
||||
host_base="${2:?Base URL required, e.g. https://192.168.1.1:8080}"
|
||||
out_dir="${3:-ota-publish}"
|
||||
|
||||
if [[ ! -f "$apk" ]]; then
|
||||
echo "APK not found: $apk" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pad2() { printf '%02d' "$1"; }
|
||||
|
||||
major="" minor="" build=""
|
||||
if command -v aapt >/dev/null 2>&1; then
|
||||
badging="$(aapt dump badging "$apk" 2>/dev/null || true)"
|
||||
version_code="$(echo "$badging" | sed -n "s/.*versionCode='\([^']*\)'.*/\1/p" | head -1)"
|
||||
version_name="$(echo "$badging" | sed -n "s/.*versionName='\([^']*\)'.*/\1/p" | head -1)"
|
||||
if [[ -n "${version_code:-}" ]]; then
|
||||
major=$((version_code / 10000))
|
||||
minor=$(((version_code / 100) % 100))
|
||||
build=$((version_code % 100))
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "${major:-}" ]]; then
|
||||
echo "Could not read versionCode from APK (install build-tools / aapt)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
maj_p="$(pad2 "$major")"
|
||||
min_p="$(pad2 "$minor")"
|
||||
bld_p="$(pad2 "$build")"
|
||||
ver_p="${maj_p}.${min_p}.${bld_p}"
|
||||
base="${host_base%/}/v0/ota/00/${maj_p}/${ver_p}"
|
||||
artifact_base="${base}/android_cast_${ver_p}.${bld_p}"
|
||||
apk_url="${artifact_base}.otapkg"
|
||||
sign_url="${artifact_base}_sign.json"
|
||||
manifest_url="${artifact_base}_manifest.json"
|
||||
sha256="$(sha256sum "$apk" | awk '{print $1}')"
|
||||
|
||||
rel_root="${out_dir}/v0/ota"
|
||||
rel_dir="${rel_root}/00/${maj_p}/${ver_p}"
|
||||
mkdir -p "${rel_dir}" "${rel_root}/channel"
|
||||
|
||||
pkg_name="android_cast_${ver_p}.${bld_p}.otapkg"
|
||||
cp -f "$apk" "${rel_dir}/${pkg_name}"
|
||||
|
||||
cat >"${rel_dir}/android_cast_${ver_p}.${bld_p}_sign.json" <<EOF
|
||||
{
|
||||
"schema": "v0",
|
||||
"sha256": "${sha256}"
|
||||
}
|
||||
EOF
|
||||
|
||||
cat >"${rel_dir}/android_cast_${ver_p}.${bld_p}_manifest.json" <<EOF
|
||||
{
|
||||
"schema": "v0",
|
||||
"major": ${major},
|
||||
"minor": ${minor},
|
||||
"build": ${build},
|
||||
"versionName": "${version_name:-${major}.${minor}.${build}}",
|
||||
"apkUrl": "${apk_url}",
|
||||
"signUrl": "${sign_url}",
|
||||
"mandatory": false,
|
||||
"releaseNotes": ""
|
||||
}
|
||||
EOF
|
||||
|
||||
cat >"${rel_root}/channel/stable.json" <<EOF
|
||||
{
|
||||
"schema": "v0",
|
||||
"manifestUrl": "${manifest_url}"
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "Published v0 OTA under ${out_dir}/v0/ota" >&2
|
||||
echo "Channel: ${host_base%/}/v0/ota/channel/stable.json" >&2
|
||||
cat "${rel_root}/channel/stable.json"
|
||||
Reference in New Issue
Block a user