Files
contactsync/deploy.sh
fitcrm 125010bbe3 Initial commit: ContactSync Android app
- SyncAdapter with account type com.bitrix24.contacts.sync
- Two-phase sync: download to Room DB, then import to phone contacts
- FCM push for instant contact addition
- WorkManager: periodic sync (30min) + heartbeat (1h)
- QR code activation (JSON format)
- Event log UI with LiveData
- Auto-update mechanism via version.php
- Duplicate contacts cleanup
- CALLER_IS_SYNCADAPTER optimization for bulk inserts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 10:41:16 +05:00

89 lines
2.7 KiB
Bash

#!/bin/bash
# Deploy script: build release APK and upload to Bitrix server
# Usage: ./deploy.sh [--mandatory]
#
# Requires BITRIX_WEBHOOK_URL environment variable, e.g.:
# export BITRIX_WEBHOOK_URL="https://bitrix.powerhousegym.ru/rest/1/abc123xyz/"
# Create webhook in Bitrix: Applications → Webhooks → Inbound webhook
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
export ANDROID_HOME="${ANDROID_HOME:-D:/android-sdk}"
# Check webhook URL
if [ -z "$BITRIX_WEBHOOK_URL" ]; then
echo "BITRIX_WEBHOOK_URL is not set."
echo "Create an inbound webhook in Bitrix24 (Applications → Webhooks)"
echo "Then: export BITRIX_WEBHOOK_URL=\"https://bitrix.powerhousegym.ru/rest/1/your-token/\""
exit 1
fi
# Read version from build.gradle.kts
VERSION_CODE=$(grep 'versionCode' app/build.gradle.kts | head -1 | grep -o '[0-9]*')
VERSION_NAME=$(grep 'versionName' app/build.gradle.kts | head -1 | grep -o '"[^"]*"' | tr -d '"')
# Server URL
SERVER_URL=$(echo "$BITRIX_WEBHOOK_URL" | grep -o 'https://[^/]*')
# Extract webhook token from URL (last path segment before trailing slash)
WEBHOOK_TOKEN=$(echo "$BITRIX_WEBHOOK_URL" | grep -oP 'rest/\d+/\K[^/]+')
WEBHOOK_USER=$(echo "$BITRIX_WEBHOOK_URL" | grep -oP 'rest/\K\d+')
MANDATORY="false"
if [ "$1" = "--mandatory" ]; then
MANDATORY="true"
fi
echo "=== ContactSync Deploy ==="
echo " Version: $VERSION_NAME ($VERSION_CODE)"
echo " Server: $SERVER_URL"
echo " Webhook: user=$WEBHOOK_USER"
echo " Mandatory: $MANDATORY"
echo ""
# Step 1: Build release APK
echo "[1/3] Building release APK..."
./gradlew.bat assembleRelease --no-daemon -q
APK_PATH="app/build/outputs/apk/release/app-release.apk"
if [ ! -f "$APK_PATH" ]; then
echo "ERROR: APK not found at $APK_PATH"
exit 1
fi
APK_SIZE=$(ls -lh "$APK_PATH" | awk '{print $5}')
echo " APK built: $APK_SIZE"
# Step 2: Upload to server
echo "[2/3] Uploading to $SERVER_URL..."
UPLOAD_URL="${SERVER_URL}/local/modules/contact.sync/api/upload_apk.php"
RESPONSE=$(curl -s -X POST "$UPLOAD_URL" \
-F "apk=@$APK_PATH" \
-F "version_code=$VERSION_CODE" \
-F "version_name=$VERSION_NAME" \
-F "mandatory=$MANDATORY" \
-F "webhook_user=$WEBHOOK_USER" \
-F "webhook_token=$WEBHOOK_TOKEN")
echo " Server response: $RESPONSE"
# Check success
SUCCESS=$(echo "$RESPONSE" | grep -o '"success":true' || echo "")
if [ -z "$SUCCESS" ]; then
echo "ERROR: Upload failed!"
exit 1
fi
# Step 3: Verify
echo "[3/3] Verifying..."
VERIFY=$(curl -s "${SERVER_URL}/local/modules/contact.sync/api/version.php")
echo " Version on server: $VERIFY"
echo ""
echo "=== Deploy complete ==="
echo " All devices will see the update on next app open."