#!/usr/bin/env bash
set -euo pipefail

SOURCE_APK="/root/durakometr-0.9.15.apk"
TARGET_APK="/var/www/html/updates/durakometr-0.9.15.apk"

if [[ ! -f "$SOURCE_APK" ]]; then
    echo "FAIL: не найден $SOURCE_APK"
    echo "Сначала загрузи release APK на VPS именно под этим именем."
    exit 1
fi

echo "=== INSTALL APK ==="

install \
    -m 0644 \
    "$SOURCE_APK" \
    "$TARGET_APK"

echo "APK:"
ls -lh "$TARGET_APK"

echo
echo "=== PUBLISH RELEASE ==="

/usr/local/bin/durak-release \
    25 \
    "ZERO FIREBASE: PostgreSQL/VPS авторизация, HTTPS-обновления, production-режим"

echo
echo "=== VERIFY HTTPS METADATA ==="

curl -fsS \
    https://5.188.21.226/updates/latest.json

echo
echo
echo "=== VERIFY APK HEAD ==="

curl -fsSI \
    https://5.188.21.226/updates/durakometr-0.9.15.apk \
    | head -n 8

echo
echo "RELEASE V0.9.15 PUBLISHED"
