Files
thinkcentre-setup/android/build.sh
T

83 lines
2.0 KiB
Bash

#!/bin/bash
# Android APK Build Wrapper — ThinkCentre 1
# Usage: bash build.sh <app> [branch]
# app: staysober | blockblitz | ticked
# branch: main (default)
#
# Output: /var/www/downloads/<app>/<app>-latest.apk
# Served: http://192.168.0.91:8080/<app>/
set -e
APP="${1:-}"
BRANCH="${2:-main}"
BUILD_DIR="/tmp/builds"
SERVE_DIR="/var/www/downloads"
GIT_BASE="git@192.168.0.34" # Pi git server
# App → repo mapping
declare -A REPOS=(
[staysober]="ottobringts/staysober"
[blockblitz]="ottobringts/blockblitz"
[ticked]="ottobringts/obsidian-tasks-app"
)
if [[ -z "$APP" || -z "${REPOS[$APP]}" ]]; then
echo "Usage: $0 <app> [branch]"
echo "Apps: ${!REPOS[@]}"
exit 1
fi
REPO="${REPOS[$APP]}"
WORK_DIR="$BUILD_DIR/$APP"
APK_OUT="$SERVE_DIR/$APP"
echo "=== Building $APP ($BRANCH) ==="
echo "Repo: $REPO"
# Clone / pull
if [ -d "$WORK_DIR/.git" ]; then
echo "Pulling latest..."
cd "$WORK_DIR"
git fetch origin
git checkout "$BRANCH"
git pull origin "$BRANCH"
else
echo "Cloning..."
mkdir -p "$BUILD_DIR"
git clone --branch "$BRANCH" "https://github.com/$REPO.git" "$WORK_DIR"
cd "$WORK_DIR"
fi
# Set ANDROID_HOME
export ANDROID_HOME="$HOME/android-sdk"
export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools/34.0.0"
# Expo prebuild if needed
if [ -f "app.json" ] && grep -q '"expo"' app.json; then
echo "Expo project detected — running prebuild..."
npx expo prebuild --platform android --no-install 2>&1 | tail -5
fi
# Gradle build
echo "Running Gradle assembleRelease..."
cd android 2>/dev/null || cd .
chmod +x gradlew
./gradlew assembleRelease --no-daemon --quiet 2>&1 | tail -20
# Find and copy APK
APK=$(find . -name "*.apk" -path "*/release/*" | head -1)
if [ -z "$APK" ]; then
echo "ERROR: No APK found!"
exit 1
fi
mkdir -p "$APK_OUT"
cp "$APK" "$APK_OUT/$APP-latest.apk"
echo ""
echo "=== Build complete ==="
echo "APK: $APK_OUT/$APP-latest.apk"
echo "URL: http://192.168.0.91:8080/$APP/$APP-latest.apk"
ls -lh "$APK_OUT/$APP-latest.apk"