#!/bin/bash # Android Services Deployment Script # Deploys SMS Campaign Manager services to Android device via Tailscale set -e # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # Configuration ANDROID_IP="100.107.173.66" SSH_PORT="8022" SSH_USER="${SSH_USER:-$(whoami)}" ANDROID_HOST="${SSH_USER}@${ANDROID_IP}" echo -e "${GREEN}📱 SMS Campaign Manager - Android Deployment${NC}" echo "==============================================" echo -e "${BLUE}Target Device:${NC} ${ANDROID_HOST}:${SSH_PORT}" echo -e "${BLUE}Via Tailscale:${NC} ${ANDROID_IP}" echo "" # Test connectivity echo -e "${YELLOW}⏳ Testing connectivity...${NC}" if ! ping -c 1 -W 2 ${ANDROID_IP} > /dev/null 2>&1; then echo -e "${RED}❌ Cannot reach Android device at ${ANDROID_IP}${NC}" echo " Make sure Tailscale is running on both devices" exit 1 fi echo -e "${GREEN}✅ Device reachable${NC}" # Test SSH echo -e "${YELLOW}⏳ Testing SSH connection...${NC}" if ! ssh -p ${SSH_PORT} -o ConnectTimeout=5 -o BatchMode=yes ${ANDROID_HOST} "exit" 2>/dev/null; then echo -e "${YELLOW}⚠️ SSH requires password authentication${NC}" echo " You'll be prompted for your password during deployment" else echo -e "${GREEN}✅ SSH connection ready${NC}" fi echo "" # Check required files echo -e "${YELLOW}⏳ Checking deployment files...${NC}" if [ ! -d "android" ]; then echo -e "${RED}❌ android/ directory not found${NC}" echo " Please run this script from the project root" exit 1 fi SHELL_SCRIPTS=(android/*.sh) PYTHON_APPS=(android/*.py) if [ ${#SHELL_SCRIPTS[@]} -eq 0 ] || [ ${#PYTHON_APPS[@]} -eq 0 ]; then echo -e "${RED}❌ Missing deployment files in android/ directory${NC}" exit 1 fi echo -e "${GREEN}✅ Found ${#SHELL_SCRIPTS[@]} shell scripts and ${#PYTHON_APPS[@]} Python apps${NC}" echo "" # Deployment confirmation echo -e "${BLUE}Ready to deploy:${NC}" echo " • Shell scripts → ~/bin/" echo " • Python apps → ~/projects/sms-campaign-manager/" echo "" read -p "Continue with deployment? (y/n) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo -e "${YELLOW}Deployment cancelled${NC}" exit 0 fi # Step 1: Create directories echo "" echo -e "${GREEN}[1/5]${NC} Creating directories on Android..." ssh -p ${SSH_PORT} ${ANDROID_HOST} "mkdir -p ~/bin ~/projects/sms-campaign-manager ~/logs" echo -e "${GREEN}✅ Directories created${NC}" # Step 2: Deploy shell scripts echo "" echo -e "${GREEN}[2/5]${NC} Deploying shell scripts to ~/bin/..." scp -P ${SSH_PORT} android/*.sh ${ANDROID_HOST}:~/bin/ echo -e "${GREEN}✅ Shell scripts deployed${NC}" # Step 3: Make scripts executable echo "" echo -e "${GREEN}[3/5]${NC} Setting execute permissions..." ssh -p ${SSH_PORT} ${ANDROID_HOST} "chmod +x ~/bin/*.sh" echo -e "${GREEN}✅ Permissions set${NC}" # Step 4: Deploy Python applications echo "" echo -e "${GREEN}[4/5]${NC} Deploying Python applications..." scp -P ${SSH_PORT} android/*.py ${ANDROID_HOST}:~/projects/sms-campaign-manager/ echo -e "${GREEN}✅ Python apps deployed${NC}" # Step 5: Start services echo "" echo -e "${GREEN}[5/5]${NC} Starting Android services..." echo -e "${YELLOW}⏳ This may take a moment...${NC}" ssh -p ${SSH_PORT} ${ANDROID_HOST} "~/bin/start-all-services.sh" || { echo -e "${YELLOW}⚠️ Service startup script completed with warnings${NC}" echo " Services may still be starting up" } # Verification echo "" echo -e "${GREEN}🔍 Verifying deployment...${NC}" sleep 3 # Check if processes are running echo -e "${YELLOW}⏳ Checking service processes...${NC}" PROCESSES=$(ssh -p ${SSH_PORT} ${ANDROID_HOST} "ps aux | grep -E '(termux-sms-api-server|python.*app.py)' | grep -v grep" || echo "") if [ -n "$PROCESSES" ]; then echo -e "${GREEN}✅ Services are running:${NC}" echo "$PROCESSES" | sed 's/^/ /' else echo -e "${YELLOW}⚠️ Services may still be starting up${NC}" fi # Check API health echo "" echo -e "${YELLOW}⏳ Testing API endpoints...${NC}" sleep 2 if curl -s --max-time 3 http://${ANDROID_IP}:5001/health > /dev/null 2>&1; then echo -e "${GREEN}✅ SMS API Server (port 5001): Responding${NC}" else echo -e "${YELLOW}⚠️ SMS API Server (port 5001): Not responding yet${NC}" fi if curl -s --max-time 3 http://${ANDROID_IP}:5000/ > /dev/null 2>&1; then echo -e "${GREEN}✅ Monitoring Dashboard (port 5000): Responding${NC}" else echo -e "${YELLOW}⚠️ Monitoring Dashboard (port 5000): Not responding yet${NC}" fi # Final summary echo "" echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${GREEN}✅ Deployment Complete!${NC}" echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo "" echo -e "${BLUE}Deployed Files:${NC}" echo " ~/bin/start-all-services.sh" echo " ~/bin/sms-service.sh" echo " ~/bin/start-sms-api.sh" echo " ~/bin/start-monitoring.sh" echo " ~/bin/network-monitor.sh" echo " ~/projects/sms-campaign-manager/termux-sms-api-server.py" echo " ~/projects/sms-campaign-manager/app.py" echo "" echo -e "${BLUE}Service URLs:${NC}" echo " 🌐 Ubuntu Homelab: http://localhost:5000" echo " 📡 Android SMS API: http://${ANDROID_IP}:5001" echo " 📊 Android Monitor: http://${ANDROID_IP}:5000" echo "" echo -e "${BLUE}Useful Commands:${NC}" echo " # Check service status" echo " ssh -p ${SSH_PORT} ${ANDROID_HOST} '~/bin/sms-service.sh status'" echo "" echo " # View logs" echo " ssh -p ${SSH_PORT} ${ANDROID_HOST} 'tail -f ~/logs/sms-api.log'" echo "" echo " # Restart services" echo " ssh -p ${SSH_PORT} ${ANDROID_HOST} '~/bin/start-all-services.sh'" echo "" echo -e "${YELLOW}Note:${NC} If services aren't responding yet, wait 10-20 seconds for startup" echo ""