- Refactored the dashboard html into seperate pages and all the necessary components - Added login and secured api routes / debugged getting system working on a tailnet. - added some functionality to the debugging and health endpoints - added in a new phone contact import and debugged.
421 lines
9.6 KiB
Markdown
421 lines
9.6 KiB
Markdown
# Android Remote Development Setup Guide
|
|
## SSH + Termux + VS Code Integration for SMS Campaign Manager
|
|
|
|
### Overview
|
|
This guide will help you set up a secure remote development environment on your S24 Ultra using Termux, allowing you to develop your SMS Campaign Manager remotely using VS Code from your Ubuntu homelab over your local network.
|
|
|
|
**Key Benefits:**
|
|
- **Secure Connection**: SSH provides encrypted remote access
|
|
- **Remote Development**: Full VS Code functionality via SSH
|
|
- **Lightweight**: Optimized for Android battery and performance
|
|
- **Simple Setup**: No complex networking requirements
|
|
|
|
**Project Structure Reference:** See `../PROJECT_STRUCTURE.md` for the complete file organization.
|
|
|
|
---
|
|
|
|
## Part 1: Android Setup (Termux Environment)
|
|
|
|
### Step 1.1: Install Required Applications
|
|
|
|
1. **Install Termux and Termux:API from F-Droid** (NOT Google Play Store)
|
|
```bash
|
|
# Download from F-Droid for security and functionality
|
|
# https://f-droid.org/packages/com.termux/
|
|
# https://f-droid.org/packages/com.termux.api/
|
|
```
|
|
|
|
2. **Grant Permissions**
|
|
- Open Android Settings → Apps → Termux:API
|
|
- Grant all requested permissions (SMS, Location, Camera, etc.)
|
|
|
|
### Step 1.2: Initial Termux Configuration
|
|
|
|
```bash
|
|
# Update packages
|
|
pkg update && pkg upgrade -y
|
|
|
|
# Install essential packages
|
|
pkg install -y \
|
|
python \
|
|
python-pip \
|
|
openssh \
|
|
git \
|
|
curl \
|
|
wget \
|
|
nano \
|
|
htop \
|
|
tree \
|
|
file \
|
|
termux-api
|
|
|
|
# Install development tools
|
|
pkg install -y \
|
|
nodejs \
|
|
build-essential \
|
|
clang
|
|
|
|
# Create directories
|
|
mkdir -p ~/.ssh ~/projects ~/bin
|
|
```
|
|
|
|
### Step 1.3: SSH Server Setup in Termux
|
|
|
|
```bash
|
|
# Generate SSH keys if not exist
|
|
if [ ! -f ~/.ssh/id_rsa ]; then
|
|
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""
|
|
fi
|
|
|
|
# Set password for SSH access
|
|
passwd
|
|
|
|
# Create SSH config
|
|
mkdir -p ~/.ssh
|
|
chmod 700 ~/.ssh
|
|
|
|
# Configure SSH server
|
|
cat > $PREFIX/etc/ssh/sshd_config << 'EOF'
|
|
# Termux SSH Configuration
|
|
Port 8022
|
|
PasswordAuthentication yes
|
|
PubkeyAuthentication yes
|
|
PrintMotd yes
|
|
Subsystem sftp $PREFIX/libexec/sftp-server
|
|
EOF
|
|
|
|
# Start SSH server
|
|
sshd
|
|
|
|
# Check SSH server status
|
|
ps aux | grep sshd
|
|
```
|
|
|
|
### Step 1.4: Get Your Phone's IP Address
|
|
|
|
```bash
|
|
# Get your phone's local IP address (Termux-compatible methods)
|
|
# Method 1:
|
|
ifconfig 2>/dev/null | grep -A1 wlan0 | grep inet | awk '{print $2}' | cut -d: -f2
|
|
|
|
# Method 2 (if Method 1 doesn't work):
|
|
ifconfig wlan0 2>/dev/null | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'
|
|
|
|
# Method 3 (alternative):
|
|
ip addr show wlan0 2>/dev/null | grep 'inet ' | awk '{print $2}' | cut -d/ -f1
|
|
|
|
# Your SSH connection string will be:
|
|
PHONE_IP=$(ifconfig 2>/dev/null | grep -A1 wlan0 | grep inet | awk '{print $2}' | cut -d: -f2)
|
|
echo "SSH Connection: ssh -p 8022 $(whoami)@$PHONE_IP"
|
|
```
|
|
|
|
---
|
|
|
|
## Part 2: Ubuntu Homelab Setup
|
|
|
|
### Step 2.1: Configure SSH Client on Ubuntu
|
|
|
|
```bash
|
|
```bash
|
|
# Add your phone to SSH config on your Ubuntu machine
|
|
cat >> ~/.ssh/config << EOF
|
|
Host android-dev
|
|
HostName 10.0.0.193
|
|
User u0_a502
|
|
Port 8022
|
|
ServerAliveInterval 60
|
|
ServerAliveCountMax 3
|
|
EOF
|
|
```
|
|
```
|
|
|
|
### Step 2.2: Test SSH Connection
|
|
|
|
```bash
|
|
# Test the connection from Ubuntu
|
|
ssh android-dev
|
|
|
|
# Or directly:
|
|
ssh -p 8022 u0_a502@YOUR_PHONE_LOCAL_IP
|
|
```
|
|
|
|
### Step 2.3: Set up SSH Key Authentication (Optional but Recommended)
|
|
|
|
**On your Ubuntu machine:**
|
|
```bash
|
|
# Generate SSH key if you don't have one
|
|
if [ ! -f ~/.ssh/id_rsa ]; then
|
|
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
|
fi
|
|
|
|
# Copy your public key
|
|
cat ~/.ssh/id_rsa.pub
|
|
```
|
|
|
|
**On your phone (in Termux):**
|
|
```bash
|
|
# Add the Ubuntu public key to authorized_keys
|
|
echo "YOUR_UBUNTU_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys
|
|
chmod 600 ~/.ssh/authorized_keys
|
|
|
|
# Test the key-based authentication
|
|
exit # Exit SSH session and reconnect to test
|
|
```
|
|
|
|
---
|
|
|
|
## Part 3: Development Environment Options
|
|
|
|
For minimal resource usage:
|
|
|
|
**Install lightweight development tools:**
|
|
```bash
|
|
# Install micro editor (lightweight alternative to VS Code)
|
|
pkg install micro
|
|
|
|
# Install development tools
|
|
pkg install git python-pip nodejs
|
|
|
|
# Clone your project
|
|
cd ~/projects
|
|
git clone YOUR_SMS_CAMPAIGN_REPO
|
|
cd sms-campaign-manager
|
|
|
|
# Install Python dependencies
|
|
pip install -r requirements.txt
|
|
|
|
# Create development script
|
|
cat > ~/bin/dev-setup.sh << 'EOF'
|
|
#!/bin/bash
|
|
cd ~/projects/sms-campaign-manager
|
|
export FLASK_ENV=development
|
|
export PHONE_IP="10.0.0.193"
|
|
echo "Development environment ready"
|
|
echo "Edit with: micro app.py"
|
|
echo "Run with: python app.py"
|
|
EOF
|
|
|
|
chmod +x ~/bin/dev-setup.sh
|
|
```
|
|
|
|
---
|
|
|
|
## Part 4: Project Integration
|
|
|
|
### Step 4.1: Clone Your SMS Campaign Manager
|
|
|
|
```bash
|
|
cd ~/projects
|
|
git clone /path/to/your/sms-campaign-manager.git
|
|
cd sms-campaign-manager
|
|
|
|
# Install Python dependencies
|
|
pip install flask werkzeug
|
|
|
|
# Test basic functionality
|
|
python -c "import flask; print('Flask working')"
|
|
```
|
|
|
|
### Step 4.2: Create Development Environment
|
|
|
|
```bash
|
|
# Create development configuration
|
|
cat > ~/projects/sms-campaign-manager/.env.termux << 'EOF'
|
|
# Termux Development Configuration
|
|
PHONE_IP=localhost
|
|
ADB_PORT=5555
|
|
FLASK_ENV=development
|
|
SECRET_KEY=dev-key-for-testing
|
|
DEFAULT_DELAY_SECONDS=3
|
|
EOF
|
|
|
|
# Create startup script for development
|
|
cat > ~/projects/sms-campaign-manager/start-dev.sh << 'EOF'
|
|
#!/bin/bash
|
|
# Development startup script
|
|
cd "$(dirname "$0")"
|
|
source .env.termux
|
|
export FLASK_APP=app.py
|
|
export FLASK_ENV=development
|
|
python app.py
|
|
EOF
|
|
|
|
chmod +x ~/projects/sms-campaign-manager/start-dev.sh
|
|
```
|
|
|
|
### Step 4.3: Termux API Integration Test
|
|
|
|
```bash
|
|
3. **Test Termux API functionality:**
|
|
```bash
|
|
# Check if Termux API is working
|
|
termux-battery-status
|
|
termux-notification --title "Development Setup" --content "SSH connection successful!"
|
|
```
|
|
```
|
|
|
|
---
|
|
|
|
## Part 5: Automation and Persistence
|
|
|
|
### Step 5.1: Auto-start Scripts
|
|
|
|
Create boot startup script:
|
|
```bash
|
|
cat > ~/bin/startup.sh << 'EOF'
|
|
#!/bin/bash
|
|
# Termux startup script
|
|
|
|
# Start SSH server
|
|
sshd
|
|
|
|
# Get local IP (Termux-compatible)
|
|
LOCAL_IP=$(ifconfig 2>/dev/null | grep -A1 wlan0 | grep inet | awk '{print $2}' | cut -d: -f2)
|
|
|
|
echo "Termux development environment ready!"
|
|
echo "Local IP: $LOCAL_IP"
|
|
echo "SSH: ssh -p 8022 $(whoami)@$LOCAL_IP"
|
|
EOF
|
|
|
|
chmod +x ~/bin/startup.sh
|
|
```
|
|
|
|
### Step 5.2: Termux Boot Configuration
|
|
|
|
```bash
|
|
# Install termux-boot for auto-start
|
|
pkg install termux-boot
|
|
|
|
# Create boot script
|
|
mkdir -p ~/.termux/boot
|
|
cat > ~/.termux/boot/startup << 'EOF'
|
|
#!/data/data/com.termux/files/usr/bin/bash
|
|
# Auto-start script
|
|
sleep 10 # Wait for system to settle
|
|
~/bin/startup.sh
|
|
EOF
|
|
|
|
chmod +x ~/.termux/boot/startup
|
|
```
|
|
|
|
---
|
|
|
|
## Part 6: Security and Optimization
|
|
|
|
### Step 6.1: Security Configuration
|
|
|
|
```bash
|
|
# Configure SSH key authentication
|
|
cat > ~/.ssh/authorized_keys << 'EOF'
|
|
# Add your Ubuntu machine's public key here
|
|
# Copy from ~/.ssh/id_rsa.pub on your Ubuntu machine
|
|
EOF
|
|
|
|
chmod 600 ~/.ssh/authorized_keys
|
|
|
|
# Disable password authentication after key setup
|
|
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' $PREFIX/etc/ssh/sshd_config
|
|
|
|
# Restart SSH with new config
|
|
pkill sshd && sshd
|
|
```
|
|
|
|
### Step 6.2: Battery Optimization
|
|
|
|
```bash
|
|
# Create power-aware development script
|
|
cat > ~/bin/battery-aware-dev.sh << 'EOF'
|
|
#!/bin/bash
|
|
# Battery-aware development environment
|
|
|
|
BATTERY_LEVEL=$(termux-battery-status | grep percentage | cut -d':' -f2 | tr -d ' ,%')
|
|
|
|
if [ "$BATTERY_LEVEL" -lt 20 ]; then
|
|
echo "Low battery ($BATTERY_LEVEL%). Enabling power saving mode."
|
|
# Reduce background processes
|
|
export FLASK_DEBUG=false
|
|
export MINIMAL_MODE=true
|
|
else
|
|
echo "Battery OK ($BATTERY_LEVEL%). Full development mode."
|
|
export FLASK_DEBUG=true
|
|
export MINIMAL_MODE=false
|
|
fi
|
|
|
|
# Start development environment
|
|
~/projects/sms-campaign-manager/start-dev.sh
|
|
EOF
|
|
|
|
chmod +x ~/bin/battery-aware-dev.sh
|
|
```
|
|
|
|
---
|
|
|
|
## Part 7: Usage Instructions
|
|
|
|
### Daily Workflow
|
|
|
|
1. **Start Termux Development Environment**
|
|
```bash
|
|
~/bin/startup.sh
|
|
```
|
|
|
|
2. **From Ubuntu - Connect via VS Code**
|
|
```bash
|
|
# Open VS Code and connect to android-dev host
|
|
code --folder vscode-remote://ssh-remote+android-dev/home/projects/sms-campaign-manager
|
|
```
|
|
|
|
3. **Or use code-server in browser**
|
|
```
|
|
http://YOUR_PHONE_TAILSCALE_IP:8080
|
|
```
|
|
|
|
### Troubleshooting Commands
|
|
|
|
```bash
|
|
# Check SSH server status
|
|
ps aux | grep sshd
|
|
|
|
# Restart SSH server
|
|
pkill sshd && sshd
|
|
|
|
# Check your phone's current IP (multiple methods)
|
|
ifconfig 2>/dev/null | grep -A1 wlan0 | grep inet | awk '{print $2}' | cut -d: -f2
|
|
ifconfig wlan0 2>/dev/null | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'
|
|
ip addr show wlan0 2>/dev/null | grep 'inet ' | awk '{print $2}' | cut -d/ -f1
|
|
|
|
# Test SSH connection locally on phone
|
|
ssh -p 8022 localhost
|
|
|
|
# Check running services
|
|
ps aux | grep -E "(sshd|code-server)"
|
|
```
|
|
|
|
---
|
|
|
|
## Part 8: Integration with Your Existing Project
|
|
|
|
### Modify your workplan.md
|
|
|
|
Update Phase 2 tasks in your workplan:
|
|
- [x] Install Termux and Termux:API
|
|
- [x] Configure SSH networking over local network
|
|
- [x] Set up SSH server and VS Code remote development
|
|
- [ ] Test Termux API commands for SMS integration
|
|
- [ ] Create lightweight Flask API server in Termux
|
|
- [ ] Implement dual connection support (ADB + Termux API)
|
|
|
|
This setup gives you a professional remote development environment that's lightweight, secure, and perfectly suited for your Android-homelab integration project!
|
|
|
|
---
|
|
|
|
## Security Notes
|
|
|
|
- All connections are encrypted through SSH
|
|
- Connections work over your local network only
|
|
- SSH key authentication recommended over passwords
|
|
- Termux API permissions limited to necessary functions
|
|
- Battery optimization prevents excessive drain
|
|
|
|
This configuration provides the foundation for implementing your Android-to-homelab integration concept while maintaining security and simplicity.
|