Files
tischlerCtrl/agents/tapo/build-all.sh
seb 028763bdb2 feat(tapo-agent): add schedule/countdown timer API support
- Fork tapo crate to add missing schedule/timer APIs
- Add get_countdown_rules, get_schedule_rules, get_next_event methods
- New readings: countdown_active, countdown_remain, schedule_count,
  schedule_active_count, next_event_time
- Add local compilation to build script alongside cross-compilation
- Implement offline polling - device collection continues when server disconnects
- Add more device readings: on_time, signal_level, rssi, runtime_today/month, energy_month

Vendored tapo fork in tapo-fork/ with minimal changes to add schedule APIs.
2025-12-23 00:46:42 +01:00

176 lines
5.2 KiB
Bash
Executable File

#!/bin/bash
#
# Build Tapo agent for various Raspberry Pi targets
#
# Targets:
# - Pi 2, Pi 3, Pi 4 (32-bit): armv7-unknown-linux-gnueabihf
# - Pi 3, Pi 4 (64-bit): aarch64-unknown-linux-gnu
#
# Usage: ./build-all.sh
#
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo "=========================================="
echo "Tapo Agent Cross-Compilation Build"
echo "=========================================="
echo ""
# ============================================
# Prerequisites Check
# ============================================
MISSING_DEPS=0
echo -e "${BLUE}Checking prerequisites...${NC}"
echo ""
# Check for Rust/Cargo
if ! command -v cargo &> /dev/null; then
echo -e "${RED}✗ Rust/Cargo not found${NC}"
echo " Install with:"
echo -e " ${YELLOW}curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh${NC}"
echo " source \$HOME/.cargo/env"
echo ""
MISSING_DEPS=1
else
RUST_VERSION=$(rustc --version | cut -d' ' -f2)
echo -e "${GREEN}✓ Rust/Cargo installed${NC} (v$RUST_VERSION)"
fi
# Check for Docker
if ! command -v docker &> /dev/null; then
echo -e "${RED}✗ Docker not found${NC}"
echo " Install with:"
echo -e " ${YELLOW}sudo apt update && sudo apt install -y docker.io${NC}"
echo -e " ${YELLOW}sudo usermod -aG docker \$USER${NC}"
echo " (log out and back in after adding to docker group)"
echo ""
MISSING_DEPS=1
else
DOCKER_VERSION=$(docker --version | cut -d' ' -f3 | tr -d ',')
echo -e "${GREEN}✓ Docker installed${NC} (v$DOCKER_VERSION)"
# Check if Docker daemon is running
if ! docker info &> /dev/null; then
echo -e "${RED}✗ Docker daemon not running or no permission${NC}"
echo " Try:"
echo -e " ${YELLOW}sudo systemctl start docker${NC}"
echo " Or if permission denied:"
echo -e " ${YELLOW}sudo usermod -aG docker \$USER${NC}"
echo " (log out and back in)"
echo ""
MISSING_DEPS=1
else
echo -e "${GREEN}✓ Docker daemon running${NC}"
fi
fi
# Check for cross
if ! command -v cross &> /dev/null; then
echo -e "${YELLOW}! cross not found - will install automatically${NC}"
NEED_CROSS=1
else
CROSS_VERSION=$(cross --version 2>/dev/null | head -1 | cut -d' ' -f2 || echo "unknown")
echo -e "${GREEN}✓ cross installed${NC} (v$CROSS_VERSION)"
NEED_CROSS=0
fi
echo ""
# Exit if missing dependencies
if [ $MISSING_DEPS -eq 1 ]; then
echo -e "${RED}Please install missing dependencies and try again.${NC}"
exit 1
fi
# Install cross if needed
if [ "${NEED_CROSS:-0}" -eq 1 ]; then
echo -e "${YELLOW}Installing 'cross' for cross-compilation...${NC}"
cargo install cross --git https://github.com/cross-rs/cross
echo ""
fi
# ============================================
# Build
# ============================================
# Create output directory
mkdir -p dist
# Define targets
declare -A TARGETS=(
["armv7-unknown-linux-gnueabihf"]="pi2_pi3_pi4_32bit"
["aarch64-unknown-linux-gnu"]="pi3_pi4_64bit"
)
echo -e "${BLUE}Starting builds...${NC}"
echo ""
# ============================================
# Local/Native Build
# ============================================
echo -e "${GREEN}Building for local/native target...${NC}"
# Get host target
HOST_TARGET=$(rustc -vV | grep host | cut -d' ' -f2)
# Use separate target dir for local builds to avoid GLIBC conflicts with cross builds
CARGO_TARGET_DIR=target-local cargo build --release -j $(nproc)
# Copy binary to dist folder
cp "target-local/release/tapo-agent" "dist/tapo-agent-local-${HOST_TARGET}"
# Get binary size
size=$(du -h "dist/tapo-agent-local-${HOST_TARGET}" | cut -f1)
echo -e "${GREEN}dist/tapo-agent-local-${HOST_TARGET}${NC} ($size)"
echo ""
# ============================================
# Cross-Compilation Builds
# ============================================
echo -e "${BLUE}Starting cross-compilation builds...${NC}"
echo ""
for target in "${!TARGETS[@]}"; do
name="${TARGETS[$target]}"
echo -e "${GREEN}Building for $target ($name)...${NC}"
cross build --release --target "$target" -j $(nproc)
# Copy binary to dist folder with descriptive name
cp "target/$target/release/tapo-agent" "dist/tapo-agent-$name"
# Get binary size
size=$(du -h "dist/tapo-agent-$name" | cut -f1)
echo -e "${GREEN}dist/tapo-agent-$name${NC} ($size)"
echo ""
done
echo "=========================================="
echo -e "${GREEN}Build complete!${NC} Binaries in dist/"
echo "=========================================="
ls -lh dist/
echo ""
echo "To deploy to Raspberry Pi:"
echo -e " ${YELLOW}scp dist/tapo-agent-pi3_pi4_64bit pi@raspberrypi:~/tapo-agent${NC}"
echo -e " ${YELLOW}ssh pi@raspberrypi 'chmod +x ~/tapo-agent && ./tapo-agent'${NC}"
echo ""
echo -e "${BLUE}Upload to bashupload.com for web console deploy (3 days, 1 download):${NC}"
echo -e " ${YELLOW}curl https://bashupload.com -F=@dist/tapo-agent-pi3_pi4_64bit${NC}"
echo -e " ${YELLOW}curl https://bashupload.com -F=@dist/tapo-agent-pi2_pi3_pi4_32bit${NC}"
echo ""
echo "Then on Pi, download and run:"
echo -e " ${YELLOW}curl -sSL https://bashupload.com/XXXXX -o tapo-agent && chmod +x tapo-agent${NC}"