#!/usr/bin/env bash
# Create BE OTA artifact directory for nginx location /v0/ota/ (run on alpine-be).
#
# Usage (on BE as root):
#   sudo ./prepare-be-ota-mount.sh
#   sudo ./prepare-be-ota-mount.sh /custom/path/to/ota-artifacts
#
# After mkdir, publish artifacts:
#   rsync -av ./out/ota/v0/ /var/www/.../ota-artifacts/v0/
# Or enable builder config build.ota_mount + auto_deploy.
set -euo pipefail

OTA_ROOT="${1:-/var/www/localhost/htdocs/apps/app/androidcast_project/ota-artifacts}"
V0="${OTA_ROOT}/v0"

mkdir -p "${V0}/ota/channel"
chown -R nginx:nginx "${OTA_ROOT}"
chmod -R 775 "${OTA_ROOT}"

echo "OTA mount ready: ${OTA_ROOT}"
echo "nginx alias target: ${V0}/ota/"
echo "Channel URL: https://apps.f0xx.org/v0/ota/channel/stable.json"
echo
echo "Publish example:"
echo "  rsync -av out/ota/v0/ ${V0}/"
