From d7a6b77e5743645c7e907f5b3a4ca413f083a0f4 Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Sat, 5 Jul 2025 03:36:34 +0100 Subject: [PATCH] it builds, and hopefully runs? --- .env.template | 26 --- .gitignore | 2 + DEPLOYMENT.md | 88 --------- Dockerfile | 47 +++-- README.md | 402 +++++++++++++++++++------------------- docker-compose.yml | 101 +++------- entrypoint.sh | 425 ++++++++++++++++++++++++++++++----------- manage.sh | 98 ++++++++++ scripts/db-setup.sh | 144 ++++++++++++++ scripts/healthcheck.sh | 224 ++++++++++++++++++++++ scripts/tak-extract.sh | 193 +++++++++++++++++++ scripts/tak-version.sh | 68 +++++++ validate.sh | 83 ++++++++ 13 files changed, 1382 insertions(+), 519 deletions(-) delete mode 100644 .env.template create mode 100644 .gitignore delete mode 100644 DEPLOYMENT.md create mode 100755 manage.sh create mode 100644 scripts/db-setup.sh create mode 100644 scripts/healthcheck.sh create mode 100644 scripts/tak-extract.sh create mode 100644 scripts/tak-version.sh create mode 100755 validate.sh diff --git a/.env.template b/.env.template deleted file mode 100644 index 3d9fa1f..0000000 --- a/.env.template +++ /dev/null @@ -1,26 +0,0 @@ -# TAK Server Docker Compose Environment Variables -# Copy this file to .env and customize the values - -# Path to your TAK Server archive -TAK_ARCHIVE_PATH=/path/to/takserver-docker-5.4-RELEASE-19.zip - -# TAK Server Ports (adjust as needed for your environment) -TAK_HTTPS_PORT=8443 -TAK_CERT_PORT=8444 -TAK_FEDERATION_PORT=8446 -TAK_STREAMING_API_PORT=9000 -TAK_STREAMING_API_TLS_PORT=9001 - -# Reverse Proxy Configuration (optional) -# Set to true to enable reverse proxy with your own SSL cert -ENABLE_REVERSE_PROXY=false - -# Domain for your TAK Server (used by reverse proxy) -TAK_DOMAIN=takserver.example.com - -# SSL Certificate paths (for reverse proxy) -SSL_CERT_PATH=/path/to/your/ssl/cert.pem -SSL_KEY_PATH=/path/to/your/ssl/private.key - -# Optional: Override the default TAK archive path inside the container -# TAK_ARCHIVE_CONTAINER_PATH=/tak-archive/takserver-docker-5.4-RELEASE-19.zip diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ab57a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/original-files +/takserver-release \ No newline at end of file diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md deleted file mode 100644 index 421ec08..0000000 --- a/DEPLOYMENT.md +++ /dev/null @@ -1,88 +0,0 @@ -# TAK Server Docker Compose Deployment Guide - -## Quick Start - -1. **Copy the environment template**: - ```bash - cp .env.template .env - ``` - -2. **Edit the .env file** to set your TAK archive path: - ```bash - nano .env - ``` - Update the `TAK_ARCHIVE_PATH` to point to your actual TAK Server archive. - -3. **Deploy the stack**: - ```bash - docker-compose up -d - ``` - -4. **Monitor the deployment**: - ```bash - # Check service status - docker-compose ps - - # View logs - docker-compose logs -f takserver - docker-compose logs -f takserver-db - ``` - -## Configuration - -### Required Setup -- Set `TAK_ARCHIVE_PATH` in your `.env` file to point to your TAK Server archive -- Ensure the archive file is accessible to Docker - -### Optional Configuration -- Modify port mappings in `.env` if you have port conflicts -- Adjust healthcheck settings in `docker-compose.yml` if needed - -## Management Commands - -```bash -# Start the services -docker-compose up -d - -# Stop the services -docker-compose down - -# Restart services -docker-compose restart - -# Update to latest image -docker-compose pull -docker-compose up -d - -# View service logs -docker-compose logs -f [service-name] - -# Access TAK Server shell -docker-compose exec takserver bash - -# Access database shell -docker-compose exec takserver-db psql -U postgres -``` - -## Accessing TAK Server - -Once deployed, TAK Server will be available at: -- **Web UI**: https://localhost:8443 -- **Certificate Enrollment**: https://localhost:8444 -- **Federation**: Port 8446 -- **Streaming API**: Port 9000 (HTTP), 9001 (HTTPS) - -## Data Persistence - -The following data is persisted across container restarts: -- Database data in `takserver-db-data` volume -- TAK Server logs in `takserver-logs` volume -- SSL certificates in `takserver-certs` volume -- Configuration files in `takserver-config` volume - -## Troubleshooting - -- **Services not starting**: Check that your TAK archive path is correct in `.env` -- **Port conflicts**: Modify the port mappings in `.env` -- **Database connection issues**: Wait for the database healthcheck to pass before the server starts -- **Certificate issues**: Check the `takserver-certs` volume for SSL certificate files diff --git a/Dockerfile b/Dockerfile index 5865c5a..b64b9c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,46 @@ -FROM postgres:15.1 +FROM eclipse-temurin:17-jammy -# Install required packages -RUN apt-get update && apt install -y \ - postgresql-15-postgis-3 \ - openjdk-17-jdk \ +# Install all required packages +RUN apt-get update && apt-get install -y \ + postgresql-common \ emacs-nox \ net-tools \ netcat \ vim \ unzip \ - && rm -rf /var/lib/apt/lists/* + curl \ + sudo \ + gosu -# Create the tak directory and logs directory -RUN mkdir -p /opt/tak /opt/tak/logs +RUN yes | /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh +RUN apt-get update && apt-get install -y \ + postgresql-15 \ + postgresql-15-postgis-3 \ + postgresql-client-15 \ + postgresql-contrib-15 -# Create entrypoint script that handles TAK archive extraction +RUN apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Create tak user and directories +RUN useradd -m -s /bin/bash tak && \ + mkdir -p /opt/tak /opt/tak/logs /takserver-zip && \ + chown -R tak:tak /opt/tak + +# Configure PostgreSQL data directory (initialization will be done at runtime) +RUN mkdir -p /var/lib/postgresql/15/main && \ + chown -R postgres:postgres /var/lib/postgresql + +# Copy all scripts into the container COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh +COPY scripts/ /scripts/ -# Set environment variables -ENV TAK_MODE=server -ENV TAK_ARCHIVE_PATH=/tak-archive/takserver-docker-5.4-RELEASE-19.zip +# Make all scripts executable +RUN chmod +x /entrypoint.sh && \ + chmod +x /scripts/*.sh +# Expose common TAK server ports +EXPOSE 5432 8080 8443 8444 8446 + +# Set the entrypoint ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 65c97a4..d04c177 100644 --- a/README.md +++ b/README.md @@ -1,242 +1,224 @@ -# TAK Server Docker Setup +# TAK Server Hybrid Docker Container -This directory contains a unified Docker configuration for running TAK Server components. +This Docker container combines both the TAK server and PostgreSQL database functionality into a single container. It automatically detects and uses the latest TAK server release from the mounted volume. + +## ⚠️ IMPORTANT: TAK Server Files Required + +**This container does NOT include TAK server files due to licensing restrictions.** You must provide your own TAK server release files obtained through proper channels: + +1. Download TAK server files from the official TAK.gov website +2. Obtain through proper military/government channels +3. Purchase through authorized distributors + +**You must have a valid license to use TAK server software.** ## Prerequisites -You must have the official TAK Server Docker release archive. The archive should be in ZIP format and contain both `docker` and `tak` folders. +1. **Valid TAK Server License**: You must have proper licensing/authorization to use TAK server +2. **TAK Server Files**: Download `takserver-docker-X.Y-RELEASE-Z.zip` from official sources +3. **Docker & Docker Compose**: Installed on your system ## Setup Instructions -1. **Build the Docker Image**: - ```bash - docker build -t takserver . - ``` +### Step 1: Obtain TAK Server Files +- Download the TAK server Docker release from official channels +- Place the `takserver-docker-X.Y-RELEASE-Z.zip` file in the `takserver-release/` directory +- The container will automatically detect and use the latest version -2. **Run TAK Server**: - ```bash - docker run -d --name takserver \ - -e TAK_MODE=server \ - -v /path/to/your/takserver-docker-5.4-RELEASE-19.zip:/tak-archive/takserver-docker-5.4-RELEASE-19.zip:ro \ - takserver - ``` - -3. **Run TAK Database**: - ```bash - docker run -d --name takserver-db \ - -e TAK_MODE=database \ - -v /path/to/your/takserver-docker-5.4-RELEASE-19.zip:/tak-archive/takserver-docker-5.4-RELEASE-19.zip:ro \ - takserver - ``` - -4. **Alternative: Mount the archive directory** (for automatic latest version detection): - ```bash - # Mount the directory containing TAK archives - docker run -d --name takserver \ - -e TAK_MODE=server \ - -v /path/to/tak-archives-directory:/tak-archive:ro \ - takserver - ``` - -## How It Works - -- **Unified Image**: One Docker image serves both TAK Server and Database functions -- **Mode Selection**: Use the `TAK_MODE` environment variable to choose between `server` (default) or `database` -- **Runtime Extraction**: The container checks for and extracts the TAK archive on startup -- **Automatic Version Detection**: If you mount a directory, the container will automatically find and use the latest TAK archive -- **Flexibility**: The same image can be used with different TAK archive versions -- **Persistence**: Once extracted, the TAK files persist in the container until it's removed - -## File Structure Expected - -Your TAK Server archive should have this structure: +### Step 2: File Structure ``` -takserver-docker-5.4-RELEASE-19.zip -├── docker/ # Docker-related files (not used) -└── tak/ # TAK Server files (this is what gets copied) - ├── configureInDocker.sh - ├── db-utils/ - │ └── configureInDocker.sh - └── ... (other TAK files) +/docker/services/tak/ +├── Dockerfile # Hybrid container +├── entrypoint.sh # Main container entrypoint +├── scripts/ # Helper scripts +│ ├── tak-version.sh # TAK version detection +│ ├── db-setup.sh # Database setup +│ └── healthcheck.sh # Health monitoring +├── docker-compose.yml # Docker Compose configuration +├── README.md # This documentation +├── build.sh # Build script +├── validate.sh # Setup validation script +├── original-files/ # Original Dockerfile templates +└── takserver-release/ # Place your TAK server files here + └── takserver-docker-X.Y-RELEASE-Z.zip # Your TAK server files ``` +## Features + +- **Hybrid Architecture**: Combines TAK server and PostgreSQL database in one container +- **Automatic Version Detection**: Finds the latest `takserver-docker-X.Y-RELEASE-Z.zip` file +- **Semantic Versioning**: Uses semantic version sorting to determine the latest release +- **Complete Setup**: Includes PostGIS extension for spatial data support +- **Runtime TAK Setup**: TAK server files are processed at container startup (licensing compliant) +- **User-Provided Files**: No TAK server files included in the image + +## Usage + +### Option 1: Using Docker Compose (Recommended) + +**First, ensure you have TAK server files in the correct directory:** +```bash +# Verify your TAK server files +ls -la takserver-release/ +# Should show: takserver-docker-X.Y-RELEASE-Z.zip + +# Build and start the hybrid container +docker-compose up -d + +# View logs to monitor startup +docker-compose logs -f tak-hybrid + +# Stop the container +docker-compose down +``` + +### Option 2: Using Docker directly + +```bash +# Build the image +docker build -t tak-hybrid . + +# Run the container (replace /path/to/tak/files with your actual path) +docker run -d \ + --name tak-hybrid \ + -p 5432:5432 \ + -p 8080:8080 \ + -p 8443:8443 \ + -p 8444:8444 \ + -v /path/to/tak/files:/takserver-zip:ro \ + -v tak-data:/opt/tak/data \ + -v tak-logs:/opt/tak/logs \ + tak-hybrid +``` + +## TAK Server Release Files + +Place your TAK server release files in the `takserver-release/` directory. The container will automatically detect and use the latest version based on semantic versioning. + +**Supported filename format**: `takserver-docker-X.Y-RELEASE-Z.zip` + +Examples: +- `takserver-docker-5.4-RELEASE-19.zip` +- `takserver-docker-5.5-RELEASE-1.zip` +- `takserver-docker-6.0-RELEASE-5.zip` + +## Ports + +- **5432**: PostgreSQL database +- **8080**: TAK server web interface (HTTP) +- **8443**: TAK server web interface (HTTPS) +- **8444**: TAK server certificate enrollment +- **8446**: TAK server API + +## Database Configuration + +The container automatically sets up PostgreSQL with: +- Database: `cot` +- User: `martiuser` +- Password: `password` +- PostGIS extension enabled + ## Environment Variables -- `TAK_MODE`: Set to `server` (default) or `database` to determine the container's function -- `TAK_ARCHIVE_PATH`: Override the default TAK archive path (default: `/tak-archive/takserver-docker-5.4-RELEASE-19.zip`) +The following environment variables can be customized in the docker-compose.yml: -## Usage Notes +- `POSTGRES_DB`: Database name (default: cot) +- `POSTGRES_USER`: Database user (default: martiuser) +- `POSTGRES_PASSWORD`: Database password (default: password) -- The TAK archive is mounted as read-only (`ro`) to prevent accidental modifications -- **Server Mode**: Starts automatically with the `configureInDocker.sh init` command -- **Database Mode**: Starts with the database configuration script -- Logs will be written to `/opt/tak/logs/takserver.log` in server mode -- The container will extract the TAK archive on first run and reuse the extracted files on subsequent runs +## Helper Scripts -## Data Persistence - -To persist data across container restarts and updates, you should mount the following directories: - -### TAK Server Data Volumes: -- `/opt/tak/logs` - TAK Server logs -- `/opt/tak/certs` - SSL certificates and keys -- `/opt/tak/conf` - Configuration files -- `/opt/tak/db-utils/pg_hba.conf` - PostgreSQL authentication configuration - -### Database Data Volumes (when using TAK_MODE=database): -- `/var/lib/postgresql/data` - PostgreSQL database files -- `/opt/tak/db-utils/logs` - Database utility logs - -### Example with Data Persistence: +The container includes several helper scripts for management and troubleshooting: +### TAK Version Detection (`/scripts/tak-version.sh`) ```bash -# TAK Server with persistent data -docker run -d --name takserver \ - -e TAK_MODE=server \ - -v /path/to/takserver-docker-5.4-RELEASE-19.zip:/tak-archive/takserver-docker-5.4-RELEASE-19.zip:ro \ - -v takserver-logs:/opt/tak/logs \ - -v takserver-certs:/opt/tak/certs \ - -v takserver-config:/opt/tak/conf \ - takserver +# Find latest TAK release +docker exec tak-hybrid /scripts/tak-version.sh /takserver-zip latest -# TAK Database with persistent data -docker run -d --name takserver-db \ - -e TAK_MODE=database \ - -v /path/to/takserver-docker-5.4-RELEASE-19.zip:/tak-archive/takserver-docker-5.4-RELEASE-19.zip:ro \ - -v takserver-db-data:/var/lib/postgresql/data \ - -v takserver-db-logs:/opt/tak/db-utils/logs \ - takserver +# List all available releases +docker exec tak-hybrid /scripts/tak-version.sh /takserver-zip list + +# Get version from specific file +docker exec tak-hybrid /scripts/tak-version.sh /takserver-zip version /takserver-zip/takserver-docker-5.4-RELEASE-19.zip ``` -## Docker Compose Example +### Database Setup (`/scripts/db-setup.sh`) +```bash +# Full database setup +docker exec tak-hybrid /scripts/db-setup.sh setup -```yaml -version: '3.8' -services: - takserver-db: - image: takserver - environment: - - TAK_MODE=database - volumes: - - /path/to/takserver-docker-5.4-RELEASE-19.zip:/tak-archive/takserver-docker-5.4-RELEASE-19.zip:ro - - takserver-db-data:/var/lib/postgresql/data - - takserver-db-logs:/opt/tak/db-utils/logs - container_name: takserver-db +# Test database connection +docker exec tak-hybrid /scripts/db-setup.sh test - takserver: - image: takserver - environment: - - TAK_MODE=server - volumes: - - /path/to/takserver-docker-5.4-RELEASE-19.zip:/tak-archive/takserver-docker-5.4-RELEASE-19.zip:ro - - takserver-logs:/opt/tak/logs - - takserver-certs:/opt/tak/certs - - takserver-config:/opt/tak/conf - container_name: takserver - depends_on: - - takserver-db - -volumes: - takserver-db-data: - takserver-db-logs: - takserver-logs: - takserver-certs: - takserver-config: +# Print database configuration +docker exec tak-hybrid /scripts/db-setup.sh config ``` -## Reverse Proxy with Custom SSL Certificate +### Health Monitoring (`/scripts/healthcheck.sh`) +```bash +# Run all health checks +docker exec tak-hybrid /scripts/healthcheck.sh all -You can use a reverse proxy (like Nginx, Traefik, or Caddy) to terminate SSL with your own certificate instead of using TAK Server's built-in SSL. This is recommended for production deployments. - -### Benefits: -- Use your own SSL certificates (Let's Encrypt, corporate CA, etc.) -- Centralized certificate management -- Better security practices -- Easier certificate renewal - -### Basic Nginx Configuration Example: - -```nginx -upstream takserver { - server takserver:8443; -} - -server { - listen 443 ssl http2; - server_name your-domain.com; - - ssl_certificate /path/to/your/cert.pem; - ssl_certificate_key /path/to/your/private.key; - - # SSL security settings - ssl_protocols TLSv1.2 TLSv1.3; - ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384; - ssl_prefer_server_ciphers off; - - # Proxy to TAK Server - location / { - proxy_pass https://takserver; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - - # Important for WebSocket connections - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - - # SSL verification settings for upstream - proxy_ssl_verify off; - proxy_ssl_session_reuse on; - } -} +# Check specific components +docker exec tak-hybrid /scripts/healthcheck.sh postgres +docker exec tak-hybrid /scripts/healthcheck.sh database +docker exec tak-hybrid /scripts/healthcheck.sh tak-process ``` -### Docker Compose with Nginx Reverse Proxy: +## Troubleshooting -```yaml -version: '3.8' - -services: - # ... your existing takserver and takserver-db services ... - - nginx: - image: nginx:alpine - ports: - - "443:443" - - "80:80" - volumes: - - ./nginx.conf:/etc/nginx/nginx.conf:ro - - /path/to/your/ssl-certs:/etc/nginx/ssl:ro - depends_on: - - takserver - networks: - - takserver-network +### Check container logs +```bash +docker-compose logs tak-hybrid ``` -### Configuration Notes: - -1. **Remove External Port Mapping**: When using a reverse proxy, remove the port mappings from the `takserver` service in docker-compose.yml since the proxy will handle external access. - -2. **Internal Communication**: TAK Server will still use its internal SSL certificate for communication between the reverse proxy and the container. - -3. **Certificate Management**: Your reverse proxy handles the public-facing SSL certificate, while TAK Server's internal certificate is only used for proxy-to-container communication. - -4. **WebSocket Support**: Ensure your reverse proxy configuration supports WebSocket upgrades for real-time features. - -5. **Security Headers**: Consider adding security headers in your reverse proxy configuration for enhanced security. - -### Alternative: Traefik with Automatic Let's Encrypt - -For automatic SSL certificate management, consider using Traefik: - -```yaml -# Add labels to your takserver service -labels: - - "traefik.enable=true" - - "traefik.http.routers.takserver.rule=Host(`your-domain.com`)" - - "traefik.http.routers.takserver.tls.certresolver=letsencrypt" - - "traefik.http.services.takserver.loadbalancer.server.port=8443" - - "traefik.http.services.takserver.loadbalancer.server.scheme=https" +### Access the container shell +```bash +docker-compose exec tak-hybrid /bin/bash ``` + +### Verify PostgreSQL is running +```bash +docker-compose exec tak-hybrid pg_isready -U martiuser -d cot +``` + +### Check TAK server status +```bash +docker-compose exec tak-hybrid ps aux | grep tak +``` + +## Error Handling + +The container includes comprehensive error checking: + +### Missing TAK Server Files +``` +ERROR: No TAK server files found! +Please mount a directory containing takserver-docker-X.Y-RELEASE-Z.zip files to /takserver-zip +``` +**Solution**: Ensure you have properly mounted the directory containing your TAK server files. + +### Invalid File Format +``` +ERROR: No takserver-docker-X.Y-RELEASE-Z.zip file found in /takserver-zip/ +Please ensure you have a file matching the pattern: takserver-docker-X.Y-RELEASE-Z.zip +``` +**Solution**: Verify your TAK server file follows the correct naming convention. + +### Licensing Compliance + +This container design ensures license compliance by: +- **Not redistributing TAK server files** +- **Requiring users to provide their own licensed files** +- **Processing files only at runtime** +- **Clear documentation of licensing requirements** + +## Legal Notice + +TAK server software is subject to export control regulations and licensing requirements. Users are responsible for: +- Obtaining proper licenses/authorization +- Compliance with export control laws +- Following all applicable regulations +- Ensuring authorized use only + +This container does not include or redistribute any TAK server software files. diff --git a/docker-compose.yml b/docker-compose.yml index 248d8a8..8bd51bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,73 +1,34 @@ version: '3.8' -services: - takserver-db: - image: git.merith.xyz/oci/takserver:nightly - environment: - - TAK_MODE=database - volumes: - # TAK Archive - replace with your actual archive path - - ${TAK_ARCHIVE_PATH:-/path/to/takserver-docker-5.4-RELEASE-19.zip}:/tak-archive/takserver-docker-5.4-RELEASE-19.zip:ro - # Persistent data volumes - - takserver-db-data:/var/lib/postgresql/data - - takserver-db-logs:/opt/tak/db-utils/logs - container_name: takserver-db - restart: unless-stopped - networks: - - takserver-network - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 40s - - takserver: - image: git.merith.xyz/oci/takserver:nightly - environment: - - TAK_MODE=server - volumes: - # TAK Archive - replace with your actual archive path - - ${TAK_ARCHIVE_PATH:-/path/to/takserver-docker-5.4-RELEASE-19.zip}:/tak-archive/takserver-docker-5.4-RELEASE-19.zip:ro - # Persistent data volumes - - takserver-logs:/opt/tak/logs - - takserver-certs:/opt/tak/certs - - takserver-config:/opt/tak/conf - container_name: takserver - restart: unless-stopped - depends_on: - takserver-db: - condition: service_healthy - networks: - - takserver-network - ports: - # Common TAK Server ports - adjust as needed - - "${TAK_HTTPS_PORT:-8443}:8443" # HTTPS Web UI - - "${TAK_CERT_PORT:-8444}:8444" # Certificate enrollment - - "${TAK_FEDERATION_PORT:-8446}:8446" # Federation - - "${TAK_STREAMING_API_PORT:-9000}:9000" # Streaming API - - "${TAK_STREAMING_API_TLS_PORT:-9001}:9001" # Streaming API TLS - healthcheck: - test: ["CMD-SHELL", "curl -f https://localhost:8443/Marti/api/version/config || exit 1"] - interval: 60s - timeout: 10s - retries: 3 - start_period: 120s - -# Named volumes for data persistence -volumes: - takserver-db-data: - driver: local - takserver-db-logs: - driver: local - takserver-logs: - driver: local - takserver-certs: - driver: local - takserver-config: - driver: local - -# Network for inter-container communication networks: - takserver-network: - driver: bridge + webserver: + external: true + +services: + tak-hybrid: + build: + context: . + dockerfile: Dockerfile + ports: + - "5432:5432" # PostgreSQL + - "8080:8080" # TAK server web UI (typical port) + - "8443:8443" # TAK server HTTPS (typical port) + - "8444:8444" # TAK server cert enrollment (typical port) + networks: + - webserver + volumes: + - ./takserver-release:/takserver-zip:ro + - takserver:/opt/tak + - postgres-data:/var/lib/postgresql/15/main + environment: + POSTGRES_DB: cot + POSTGRES_USER: martiuser + POSTGRES_PASSWORD: password + restart: no + labels: + caddy: tak.merith.xyz + caddy.reverse_proxy: "{{upstreams 8080}}" + +volumes: + takserver: + postgres-data: diff --git a/entrypoint.sh b/entrypoint.sh index a3127cb..af3310a 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,130 +1,331 @@ #!/bin/bash - -# TAK Server Unified Entrypoint Script -# This script handles both TAK Server and Database modes - set -e -TAK_ARCHIVE_PATH="${TAK_ARCHIVE_PATH:-/tak-archive/takserver-docker-5.4-RELEASE-19.zip}" -TAK_ARCHIVE_DIR="/tak-archive" -TAK_INSTALL_DIR="/opt/tak" -TAK_MODE="${TAK_MODE:-server}" +# Colors for logging +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color -# Function to log messages -log() { - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" +log_info() { + echo -e "${GREEN}[INFO]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" } -# Function to find the latest TAK archive -find_latest_tak_archive() { - local latest_archive="" - - # Check if the specific archive exists - if [ -f "$TAK_ARCHIVE_PATH" ]; then - log "Found specified TAK archive: $TAK_ARCHIVE_PATH" - echo "$TAK_ARCHIVE_PATH" - return 0 - fi - - # Look for any takserver-docker-*.zip files in the archive directory - if [ -d "$TAK_ARCHIVE_DIR" ]; then - latest_archive=$(find "$TAK_ARCHIVE_DIR" -name "takserver-docker-*.zip" -type f | sort -V | tail -n 1) - - if [ -n "$latest_archive" ]; then - log "Found latest TAK archive: $latest_archive" - echo "$latest_archive" - return 0 - fi - fi - - # If no archive found, return empty - echo "" - return 1 +log_warn() { + echo -e "${YELLOW}[WARN]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" } -# Function to check if TAK is already installed -is_tak_installed() { - if [ "$TAK_MODE" = "database" ]; then - [ -f "$TAK_INSTALL_DIR/db-utils/configureInDocker.sh" ] && [ -x "$TAK_INSTALL_DIR/db-utils/configureInDocker.sh" ] - else - [ -f "$TAK_INSTALL_DIR/configureInDocker.sh" ] && [ -x "$TAK_INSTALL_DIR/configureInDocker.sh" ] - fi +log_error() { + echo -e "${RED}[ERROR]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" } -# Function to extract TAK archive -extract_tak_archive() { - local archive_path - archive_path=$(find_latest_tak_archive) - - if [ -z "$archive_path" ]; then - log "ERROR: No TAK archive found" - log "Please mount your TAK Server archive to the /tak-archive directory." - log "Expected format: takserver-docker-X.X-RELEASE-XX.zip" - log "Example: docker run -v /path/to/takserver-docker-5.4-RELEASE-19.zip:/tak-archive/takserver-docker-5.4-RELEASE-19.zip ..." - log "Or mount the directory: docker run -v /path/to/tak-archives:/tak-archive ..." - exit 1 - fi - - log "Extracting TAK archive from $archive_path" - - # Create temporary directory for extraction - TEMP_DIR=$(mktemp -d) - - # Extract the archive (handling both .zip and .tar.gz formats) - if [[ "$archive_path" == *.zip ]]; then - unzip -q "$archive_path" -d "$TEMP_DIR" - else - tar -xzf "$archive_path" -C "$TEMP_DIR" - fi - - # Copy the tak folder contents to /opt/tak - if [ -d "$TEMP_DIR/tak" ]; then - log "Copying TAK files to $TAK_INSTALL_DIR" - cp -r "$TEMP_DIR/tak/"* "$TAK_INSTALL_DIR/" - - # Set proper permissions - [ -f "$TAK_INSTALL_DIR/configureInDocker.sh" ] && chmod +x "$TAK_INSTALL_DIR/configureInDocker.sh" - [ -f "$TAK_INSTALL_DIR/db-utils/configureInDocker.sh" ] && chmod +x "$TAK_INSTALL_DIR/db-utils/configureInDocker.sh" - - # Clean up temporary directory - rm -rf "$TEMP_DIR" - - log "TAK archive extracted successfully" - else - log "ERROR: TAK archive does not contain expected 'tak' folder structure" - log "Archive contents:" - ls -la "$TEMP_DIR" - rm -rf "$TEMP_DIR" - exit 1 - fi +log_debug() { + echo -e "${BLUE}[DEBUG]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" } -# Main execution -if [ "$TAK_MODE" = "database" ]; then - log "Starting TAK Server Database container..." -else - log "Starting TAK Server container..." -fi +log_info "Starting TAK Server Hybrid Container..." -# Check if TAK is already installed -if ! is_tak_installed; then - log "TAK not found in $TAK_INSTALL_DIR, checking for archive..." - extract_tak_archive -else - log "TAK already installed in $TAK_INSTALL_DIR" -fi +# Source helper scripts +log_debug "Sourcing helper scripts..." +source /scripts/tak-version.sh +log_debug "Helper scripts loaded successfully" -# Verify TAK installation -if ! is_tak_installed; then - log "ERROR: TAK installation verification failed" +# Check if TAK server files are provided +log_info "Checking for TAK server files..." +log_debug "Looking for files in /takserver-zip directory..." + +if [ ! -d "/takserver-zip" ]; then + log_error "Mount point /takserver-zip does not exist!" + log_error "Please ensure you mount a directory containing TAK server files" + log_error "Example: docker run -v /path/to/tak/files:/takserver-zip:ro ..." exit 1 fi -# Execute the appropriate command based on mode -if [ "$TAK_MODE" = "database" ]; then - log "Starting TAK Database configuration" - exec /opt/tak/db-utils/configureInDocker.sh -else - log "Starting TAK Server with configureInDocker.sh init" - exec /bin/bash -c "/opt/tak/configureInDocker.sh init &>> /opt/tak/logs/takserver.log" +# Check if directory is empty +if [ ! "$(ls -A /takserver-zip 2>/dev/null)" ]; then + log_error "Directory /takserver-zip is empty!" + log_error "Please place takserver-docker-X.Y-RELEASE-Z.zip files in the mounted directory" + log_debug "Directory contents:" + ls -l /takserver-zip/ || log_debug "Cannot list directory contents" + exit 1 fi + +# List all files in the directory for debugging +log_debug "Contents of /takserver-zip:" +ls -l /takserver-zip/ | while read line; do + log_debug " $line" +done + +# Check for zip files specifically +ZIP_COUNT=$(find /takserver-zip -name "*.zip" -type f | wc -l) +log_debug "Found $ZIP_COUNT zip files in /takserver-zip" + +if [ $ZIP_COUNT -eq 0 ]; then + log_error "No zip files found in /takserver-zip!" + log_error "Please ensure you have takserver-docker-X.Y-RELEASE-Z.zip files" + log_debug "Available files:" + find /takserver-zip -type f | while read file; do + log_debug " $(basename $file)" + done + while true; do sleep 3600; done +fi + +# Check for TAK server specific zip files +TAK_ZIP_COUNT=$(find /takserver-zip -name "takserver-docker-*-RELEASE-*.zip" -type f | wc -l) +log_debug "Found $TAK_ZIP_COUNT TAK server zip files" + +if [ $TAK_ZIP_COUNT -eq 0 ]; then + log_error "No TAK server zip files found matching pattern 'takserver-docker-*-RELEASE-*.zip'!" + log_error "Available zip files:" + find /takserver-zip -name "*.zip" -type f | while read file; do + log_error " $(basename $file)" + done + log_error "Required format: takserver-docker-X.Y-RELEASE-Z.zip" + log_error "Example: takserver-docker-5.4-RELEASE-19.zip" + exit 1 +fi + +# Use the helper script to find the latest TAK release +log_info "Finding latest TAK server release..." +LATEST_ZIP=$(find_latest_tak_release /takserver-zip) +if [ $? -ne 0 ]; then + log_error "Failed to find latest TAK release: $LATEST_ZIP" + log_info "Available TAK releases:" + list_tak_releases /takserver-zip + exit 1 +fi + +log_info "Found latest TAK server release: $(basename $LATEST_ZIP)" +log_info "Version: $(get_tak_version $LATEST_ZIP)" +log_debug "Full path: $LATEST_ZIP" + +# Extract the zip file if not already extracted +if [ ! -f /opt/tak/configureInDocker.sh ]; then + log_info "TAK server files not found - extracting from ZIP..." + log_debug "Using extraction script: /scripts/tak-extract.sh" + + # Use the extraction script + if /scripts/tak-extract.sh extract "$LATEST_ZIP" /opt/tak; then + log_info "TAK server extraction completed successfully" + + # Set proper permissions + /scripts/tak-extract.sh permissions /opt/tak tak:tak + + # Verify installation + if /scripts/tak-extract.sh verify /opt/tak; then + log_info "TAK server installation verified" + else + log_error "TAK server installation verification failed!" + exit 1 + fi + else + log_error "Failed to extract TAK server files!" + exit 1 + fi +else + log_info "TAK server files already exist - skipping extraction" + log_debug "Found existing configureInDocker.sh at /opt/tak/configureInDocker.sh" + + # Ensure permissions are correct on existing files + log_debug "Ensuring correct permissions on existing TAK files..." + /scripts/tak-extract.sh permissions /opt/tak tak:tak +fi + +# Start PostgreSQL +log_info "Starting PostgreSQL..." + +# Initialize PostgreSQL if not already done +if [ ! -f /var/lib/postgresql/15/main/PG_VERSION ]; then + log_info "Initializing PostgreSQL database cluster..." + if sudo -u postgres /usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/15/main; then + log_info "PostgreSQL initialized successfully" + + # Configure PostgreSQL + log_info "Configuring PostgreSQL..." + + # Create postgresql.conf + log_debug "Creating postgresql.conf..." + cat > /tmp/postgresql.conf < /tmp/pg_hba.conf < /tmp/postgresql.conf < /tmp/pg_hba.conf </dev/null; then + log_debug "PostgreSQL process is still running" +else + log_error "PostgreSQL process died immediately!" + log_error "Checking system logs for errors..." + # Try to get any error output + journalctl -u postgresql --no-pager --lines=10 2>/dev/null || log_debug "No journalctl available" + exit 1 +fi + +# Wait for PostgreSQL to start and setup database +log_info "Waiting for PostgreSQL to be ready..." +POSTGRES_READY=0 +for i in {1..30}; do + if pg_isready -h localhost -p 5432 >/dev/null 2>&1; then + POSTGRES_READY=1 + log_info "PostgreSQL is ready after ${i} seconds" + break + fi + log_debug "PostgreSQL not ready yet, waiting... (attempt $i/30)" + sleep 1 +done + +if [ $POSTGRES_READY -eq 0 ]; then + log_error "PostgreSQL failed to become ready after 30 seconds!" + log_error "Checking PostgreSQL process status..." + if kill -0 $POSTGRES_PID 2>/dev/null; then + log_error "PostgreSQL process is running but not accepting connections" + else + log_error "PostgreSQL process has died" + fi + exit 1 +fi + +# Use the database setup script +log_info "Setting up database..." +if /scripts/db-setup.sh setup; then + log_info "Database setup completed successfully" +else + log_error "Database setup failed!" + exit 1 +fi + +# Run database configuration if it exists +if [ -f "/opt/tak/db-utils/configureInDocker.sh" ]; then + log_info "Configuring TAK database..." + /opt/tak/db-utils/configureInDocker.sh & + DB_CONFIG_PID=$! + log_debug "TAK database configuration started with PID: $DB_CONFIG_PID" + sleep 10 +else + log_warn "TAK database configuration script not found, skipping..." +fi + +# Start TAK server +if [ -f "/opt/tak/configureInDocker.sh" ]; then + log_info "Starting TAK server..." + log_debug "Executing: /opt/tak/configureInDocker.sh init" + exec /opt/tak/configureInDocker.sh init +else + log_error "TAK server configuration script not found!" + log_error "Expected file: /opt/tak/configureInDocker.sh" + log_error "The extracted TAK server files may be incomplete or corrupted." + log_debug "Contents of /opt/tak:" + ls -la /opt/tak/ | while read line; do + log_debug " $line" + done + exit 1 +fi \ No newline at end of file diff --git a/manage.sh b/manage.sh new file mode 100755 index 0000000..6c3be70 --- /dev/null +++ b/manage.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# TAK Server Management Script +# This script provides easy access to container management functions + +CONTAINER_NAME="tak-hybrid" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +log_info() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +log_warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Check if container is running +check_container() { + if ! docker ps | grep -q "$CONTAINER_NAME"; then + log_error "Container '$CONTAINER_NAME' is not running" + log_info "Start the container with: docker-compose up -d" + exit 1 + fi +} + +# Execute script in container +exec_script() { + check_container + docker exec "$CONTAINER_NAME" "$@" +} + +# Show usage +show_usage() { + echo "TAK Server Management Script" + echo "Usage: $0 [options]" + echo "" + echo "Commands:" + echo " health [component] - Run health checks" + echo " db - Database operations" + echo " version [action] - TAK version operations" + echo " logs - Show container logs" + echo " shell - Open shell in container" + echo " status - Show container status" + echo " restart - Restart container" + echo "" + echo "Examples:" + echo " $0 health all - Run all health checks" + echo " $0 db test - Test database connection" + echo " $0 version list - List available TAK versions" + echo " $0 logs - Show recent logs" +} + +case "$1" in + "health") + shift + exec_script /scripts/healthcheck.sh "$@" + ;; + "db") + shift + exec_script /scripts/db-setup.sh "$@" + ;; + "version") + shift + exec_script /scripts/tak-version.sh /takserver-zip "$@" + ;; + "logs") + docker-compose logs -f tak-hybrid + ;; + "shell") + check_container + docker exec -it "$CONTAINER_NAME" /bin/bash + ;; + "status") + if docker ps | grep -q "$CONTAINER_NAME"; then + log_info "Container is running" + docker ps | grep "$CONTAINER_NAME" + else + log_warn "Container is not running" + fi + ;; + "restart") + log_info "Restarting container..." + docker-compose restart tak-hybrid + ;; + *) + show_usage + exit 1 + ;; +esac diff --git a/scripts/db-setup.sh b/scripts/db-setup.sh new file mode 100644 index 0000000..4bfd468 --- /dev/null +++ b/scripts/db-setup.sh @@ -0,0 +1,144 @@ +#!/bin/bash +# Database Setup Script for TAK Server +set -e + +# Database configuration +DB_NAME="${DB_NAME:-cot}" +DB_USER="${DB_USER:-martiuser}" +DB_PASSWORD="${DB_PASSWORD:-password}" +DB_HOST="${DB_HOST:-localhost}" +DB_PORT="${DB_PORT:-5432}" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +log_info() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +log_warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Check if PostgreSQL is running +check_postgres() { + if ! pg_isready -q -h "$DB_HOST" -p "$DB_PORT"; then + log_error "PostgreSQL is not running or not accessible" + return 1 + fi + log_info "PostgreSQL is running" +} + +# Create database user if not exists +create_db_user() { + log_info "Creating database user '$DB_USER'..." + + if sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$DB_USER'" | grep -q 1; then + log_warn "User '$DB_USER' already exists" + else + sudo -u postgres createuser --createdb --no-superuser --no-createrole "$DB_USER" + log_info "User '$DB_USER' created" + fi + + # Set password + sudo -u postgres psql -c "ALTER USER $DB_USER PASSWORD '$DB_PASSWORD';" + log_info "Password set for user '$DB_USER'" +} + +# Create database if not exists +create_database() { + log_info "Creating database '$DB_NAME'..." + + if sudo -u postgres psql -lqt | cut -d \| -f 1 | grep -qw "$DB_NAME"; then + log_warn "Database '$DB_NAME' already exists" + else + sudo -u postgres createdb -O "$DB_USER" "$DB_NAME" + log_info "Database '$DB_NAME' created" + fi +} + +# Install PostGIS extension +install_postgis() { + log_info "Installing PostGIS extension..." + + if sudo -u postgres psql -d "$DB_NAME" -tAc "SELECT 1 FROM pg_extension WHERE extname='postgis'" | grep -q 1; then + log_warn "PostGIS extension already installed" + else + sudo -u postgres psql -d "$DB_NAME" -c "CREATE EXTENSION postgis;" + log_info "PostGIS extension installed" + fi +} + +# Test database connection +test_connection() { + log_info "Testing database connection..." + + if PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c "SELECT version();" > /dev/null 2>&1; then + log_info "Database connection successful" + else + log_error "Database connection failed" + return 1 + fi +} + +# Main setup function +setup_database() { + log_info "Starting database setup..." + + check_postgres + create_db_user + create_database + install_postgis + test_connection + + log_info "Database setup completed successfully" +} + +# Print database configuration +print_config() { + echo "Database Configuration:" + echo " Host: $DB_HOST" + echo " Port: $DB_PORT" + echo " Database: $DB_NAME" + echo " User: $DB_USER" + echo " Password: [REDACTED]" +} + +# Main execution +case "${1:-setup}" in + "setup") + setup_database + ;; + "test") + test_connection + ;; + "config") + print_config + ;; + "user") + create_db_user + ;; + "db") + create_database + ;; + "postgis") + install_postgis + ;; + *) + echo "Usage: $0 [setup|test|config|user|db|postgis]" + echo " setup - Full database setup (default)" + echo " test - Test database connection" + echo " config - Print database configuration" + echo " user - Create database user only" + echo " db - Create database only" + echo " postgis - Install PostGIS extension only" + exit 1 + ;; +esac diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh new file mode 100644 index 0000000..3d6acc4 --- /dev/null +++ b/scripts/healthcheck.sh @@ -0,0 +1,224 @@ +#!/bin/bash +# TAK Server Health Check Script +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +log_info() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +log_warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +log_check() { + echo -e "${BLUE}[CHECK]${NC} $1" +} + +# Check if PostgreSQL is running +check_postgres() { + log_check "Checking PostgreSQL..." + + if pg_isready -q -h localhost -p 5432; then + log_info "PostgreSQL is running" + return 0 + else + log_error "PostgreSQL is not running" + return 1 + fi +} + +# Check database connectivity +check_database() { + log_check "Checking database connectivity..." + + if PGPASSWORD="password" psql -h localhost -p 5432 -U martiuser -d cot -c "SELECT 1;" > /dev/null 2>&1; then + log_info "Database connection successful" + return 0 + else + log_error "Database connection failed" + return 1 + fi +} + +# Check PostGIS extension +check_postgis() { + log_check "Checking PostGIS extension..." + + if PGPASSWORD="password" psql -h localhost -p 5432 -U martiuser -d cot -tAc "SELECT 1 FROM pg_extension WHERE extname='postgis'" | grep -q 1; then + log_info "PostGIS extension is installed" + return 0 + else + log_error "PostGIS extension is not installed" + return 1 + fi +} + +# Check TAK server files +check_tak_files() { + log_check "Checking TAK server files..." + + if [ -f "/opt/tak/configureInDocker.sh" ]; then + log_info "TAK server configuration script found" + return 0 + else + log_error "TAK server configuration script not found" + return 1 + fi +} + +# Check TAK server process +check_tak_process() { + log_check "Checking TAK server process..." + + if pgrep -f "takserver" > /dev/null; then + log_info "TAK server process is running" + return 0 + else + log_warn "TAK server process not found" + return 1 + fi +} + +# Check network ports +check_ports() { + log_check "Checking network ports..." + + local ports=(5432 8080 8443 8444 8446) + local all_good=true + + for port in "${ports[@]}"; do + if netstat -tuln | grep -q ":$port "; then + log_info "Port $port is listening" + else + log_warn "Port $port is not listening" + all_good=false + fi + done + + if [ "$all_good" = true ]; then + return 0 + else + return 1 + fi +} + +# Check disk space +check_disk_space() { + log_check "Checking disk space..." + + local usage=$(df /opt/tak | tail -1 | awk '{print $5}' | sed 's/%//') + + if [ "$usage" -lt 80 ]; then + log_info "Disk space usage: ${usage}% (OK)" + return 0 + elif [ "$usage" -lt 90 ]; then + log_warn "Disk space usage: ${usage}% (WARNING)" + return 1 + else + log_error "Disk space usage: ${usage}% (CRITICAL)" + return 1 + fi +} + +# Check memory usage +check_memory() { + log_check "Checking memory usage..." + + local mem_info=$(free | grep Mem) + local total=$(echo $mem_info | awk '{print $2}') + local used=$(echo $mem_info | awk '{print $3}') + local usage=$((used * 100 / total)) + + if [ "$usage" -lt 80 ]; then + log_info "Memory usage: ${usage}% (OK)" + return 0 + elif [ "$usage" -lt 90 ]; then + log_warn "Memory usage: ${usage}% (WARNING)" + return 1 + else + log_error "Memory usage: ${usage}% (CRITICAL)" + return 1 + fi +} + +# Run all health checks +run_all_checks() { + log_info "Running TAK Server Health Checks..." + echo "==================================" + + local failed=0 + + check_postgres || ((failed++)) + check_database || ((failed++)) + check_postgis || ((failed++)) + check_tak_files || ((failed++)) + check_tak_process || ((failed++)) + check_ports || ((failed++)) + check_disk_space || ((failed++)) + check_memory || ((failed++)) + + echo "==================================" + + if [ $failed -eq 0 ]; then + log_info "All health checks passed!" + return 0 + else + log_error "$failed health check(s) failed" + return 1 + fi +} + +# Main execution +case "${1:-all}" in + "all") + run_all_checks + ;; + "postgres") + check_postgres + ;; + "database") + check_database + ;; + "postgis") + check_postgis + ;; + "tak-files") + check_tak_files + ;; + "tak-process") + check_tak_process + ;; + "ports") + check_ports + ;; + "disk") + check_disk_space + ;; + "memory") + check_memory + ;; + *) + echo "Usage: $0 [all|postgres|database|postgis|tak-files|tak-process|ports|disk|memory]" + echo " all - Run all health checks (default)" + echo " postgres - Check PostgreSQL service" + echo " database - Check database connectivity" + echo " postgis - Check PostGIS extension" + echo " tak-files - Check TAK server files" + echo " tak-process- Check TAK server process" + echo " ports - Check network ports" + echo " disk - Check disk space" + echo " memory - Check memory usage" + exit 1 + ;; +esac diff --git a/scripts/tak-extract.sh b/scripts/tak-extract.sh new file mode 100644 index 0000000..8e90403 --- /dev/null +++ b/scripts/tak-extract.sh @@ -0,0 +1,193 @@ +#!/bin/bash +# TAK Server Extraction Script + +# Colors for logging +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +log_info() { + echo -e "${GREEN}[EXTRACT-INFO]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" +} + +log_warn() { + echo -e "${YELLOW}[EXTRACT-WARN]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" +} + +log_error() { + echo -e "${RED}[EXTRACT-ERROR]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" +} + +log_debug() { + echo -e "${BLUE}[EXTRACT-DEBUG]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" +} + +# Extract TAK server from zip file +extract_tak_server() { + local zip_file="$1" + local target_dir="$2" + + if [ -z "$zip_file" ] || [ -z "$target_dir" ]; then + log_error "Usage: extract_tak_server " + return 1 + fi + + if [ ! -f "$zip_file" ]; then + log_error "ZIP file does not exist: $zip_file" + return 1 + fi + + log_info "Extracting TAK server from: $(basename $zip_file)" + log_debug "Target directory: $target_dir" + + # Create temporary extraction directory + local temp_dir="/tmp/tak_extract_$$" + mkdir -p "$temp_dir" + + log_debug "Using temporary directory: $temp_dir" + + # Extract ZIP file + cd "$temp_dir" + if ! unzip -q "$zip_file"; then + log_error "Failed to extract ZIP file" + rm -rf "$temp_dir" + return 1 + fi + + log_debug "ZIP extraction completed" + + # Find the tak directory - it could be at root level or nested + local tak_source_dir="" + + # First check if tak directory is at root level + if [ -d "$temp_dir/tak" ]; then + tak_source_dir="$temp_dir/tak" + log_info "Found 'tak' directory at root level" + else + # Look for tak directory in subdirectories + log_debug "Looking for 'tak' directory in subdirectories..." + tak_source_dir=$(find "$temp_dir" -type d -name "tak" -print -quit) + + if [ -n "$tak_source_dir" ] && [ -d "$tak_source_dir" ]; then + log_info "Found 'tak' directory at: $tak_source_dir" + else + log_error "Expected 'tak' directory not found in ZIP file" + log_debug "Available directories:" + find "$temp_dir" -type d -maxdepth 3 | while read dir; do + log_debug " $dir" + done + rm -rf "$temp_dir" + return 1 + fi + fi + + # Ensure target directory exists + mkdir -p "$target_dir" + + # Copy TAK files to target directory + log_debug "Copying files from $tak_source_dir/ to $target_dir/" + if cp -r "$tak_source_dir/"* "$target_dir/"; then + log_info "TAK files copied successfully" + else + log_error "Failed to copy TAK files" + rm -rf "$temp_dir" + return 1 + fi + + # Show what was extracted + log_debug "Files extracted to $target_dir:" + find "$target_dir" -maxdepth 2 -type f | head -10 | while read file; do + log_debug " $(basename $file)" + done + + # Clean up + rm -rf "$temp_dir" + log_debug "Temporary directory cleaned up" + + return 0 +} + +# Verify TAK installation +verify_tak_installation() { + local install_dir="$1" + + log_info "Verifying TAK installation in: $install_dir" + + # Check for required files + local required_files=( + "configureInDocker.sh" + "takserver.sh" + ) + + for file in "${required_files[@]}"; do + if [ -f "$install_dir/$file" ]; then + log_debug "Found required file: $file" + else + log_warn "Missing file: $file" + fi + done + + # Check for key directories + local key_dirs=( + "bin" + "conf" + "lib" + ) + + for dir in "${key_dirs[@]}"; do + if [ -d "$install_dir/$dir" ]; then + log_debug "Found directory: $dir" + else + log_warn "Missing directory: $dir" + fi + done + + # Main verification + if [ -f "$install_dir/configureInDocker.sh" ]; then + log_info "TAK installation verification successful" + return 0 + else + log_error "TAK installation verification failed - configureInDocker.sh not found" + return 1 + fi +} + +# Set proper permissions +set_tak_permissions() { + local install_dir="$1" + local owner="${2:-tak:tak}" + + log_info "Setting permissions on TAK installation" + + # Make scripts executable + find "$install_dir" -name "*.sh" -exec chmod +x {} \; 2>/dev/null + + # Set ownership + chown -R "$owner" "$install_dir" 2>/dev/null + + log_debug "Permissions set successfully" +} + +# Main execution if script is run directly +if [ "${BASH_SOURCE[0]}" == "${0}" ]; then + case "${1:-extract}" in + "extract") + extract_tak_server "$2" "$3" + ;; + "verify") + verify_tak_installation "$2" + ;; + "permissions") + set_tak_permissions "$2" "$3" + ;; + *) + echo "Usage: $0 [extract|verify|permissions] " + echo " extract - Extract TAK server from ZIP" + echo " verify - Verify TAK installation" + echo " permissions [owner] - Set TAK permissions" + exit 1 + ;; + esac +fi diff --git a/scripts/tak-version.sh b/scripts/tak-version.sh new file mode 100644 index 0000000..73d69d6 --- /dev/null +++ b/scripts/tak-version.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# TAK Server Version Detection Script +set -e + +# Find the latest takserver-docker-X.Y-RELEASE-Z.zip file +find_latest_tak_release() { + local takserver_dir="$1" + + if [ ! -d "$takserver_dir" ]; then + echo "ERROR: Directory $takserver_dir does not exist" + return 1 + fi + + local latest_zip=$(find "$takserver_dir" -name "takserver-docker-*-RELEASE-*.zip" -type f | \ + sed -n 's/.*takserver-docker-\([0-9]\+\.[0-9]\+\)-RELEASE-\([0-9]\+\)\.zip/\1.\2 &/p' | \ + sort -V | tail -1 | cut -d' ' -f2-) + + if [ -z "$latest_zip" ]; then + echo "ERROR: No takserver-docker-X.Y-RELEASE-Z.zip file found in $takserver_dir" + return 1 + fi + + echo "$latest_zip" +} + +# Extract version information +get_tak_version() { + local zip_file="$1" + local version=$(basename "$zip_file" | sed -n 's/takserver-docker-\([0-9]\+\.[0-9]\+\)-RELEASE-\([0-9]\+\)\.zip/\1-\2/p') + echo "$version" +} + +# List all available TAK releases +list_tak_releases() { + local takserver_dir="$1" + + echo "Available TAK server releases:" + find "$takserver_dir" -name "takserver-docker-*-RELEASE-*.zip" -type f | while read -r file; do + local version=$(get_tak_version "$file") + echo " - $(basename "$file") (version: $version)" + done +} + +# Main execution if script is run directly +if [ "${BASH_SOURCE[0]}" == "${0}" ]; then + TAKSERVER_DIR="${1:-/takserver-zip}" + + case "${2:-latest}" in + "latest") + find_latest_tak_release "$TAKSERVER_DIR" + ;; + "list") + list_tak_releases "$TAKSERVER_DIR" + ;; + "version") + if [ -n "$3" ]; then + get_tak_version "$3" + else + echo "Usage: $0 version " + exit 1 + fi + ;; + *) + echo "Usage: $0 [latest|list|version ]" + exit 1 + ;; + esac +fi diff --git a/validate.sh b/validate.sh new file mode 100755 index 0000000..dc1d966 --- /dev/null +++ b/validate.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# TAK Server Setup Validation Script + +echo "TAK Server Hybrid Container - Setup Validation" +echo "==============================================" + +# Check if takserver-release directory exists +if [ ! -d "takserver-release" ]; then + echo "❌ takserver-release directory not found" + echo " Please create the directory: mkdir -p takserver-release" + exit 1 +fi + +# Check for TAK server files +TAK_FILES=$(find takserver-release -name "takserver-docker-*.zip" 2>/dev/null) + +if [ -z "$TAK_FILES" ]; then + echo "❌ No TAK server files found in takserver-release/" + echo "" + echo "Required:" + echo " - File format: takserver-docker-X.Y-RELEASE-Z.zip" + echo " - Example: takserver-docker-5.4-RELEASE-19.zip" + echo "" + echo "Please:" + echo " 1. Obtain TAK server files through proper channels" + echo " 2. Ensure you have valid licensing/authorization" + echo " 3. Place files in takserver-release/ directory" + echo "" + exit 1 +fi + +echo "✅ TAK server files found:" +for file in $TAK_FILES; do + echo " - $(basename $file)" +done + +# Find latest version +LATEST_ZIP=$(echo "$TAK_FILES" | \ + sed -n 's/.*takserver-docker-\([0-9]\+\.[0-9]\+\)-RELEASE-\([0-9]\+\)\.zip/\1.\2 &/p' | \ + sort -V | tail -1 | cut -d' ' -f2-) + +if [ -n "$LATEST_ZIP" ]; then + echo "✅ Latest version detected: $(basename $LATEST_ZIP)" +fi + +# Check Docker +if ! command -v docker &> /dev/null; then + echo "❌ Docker not found - please install Docker" + exit 1 +fi +echo "✅ Docker found" + +# Check Docker Compose +if ! command -v docker-compose &> /dev/null; then + echo "❌ Docker Compose not found - please install Docker Compose" + exit 1 +fi +echo "✅ Docker Compose found" + +# Check if Dockerfile exists +if [ ! -f "Dockerfile" ]; then + echo "❌ Dockerfile not found" + exit 1 +fi +echo "✅ Dockerfile found" + +# Check if docker-compose.yml exists +if [ ! -f "docker-compose.yml" ]; then + echo "❌ docker-compose.yml not found" + exit 1 +fi +echo "✅ Docker Compose configuration found" + +echo "" +echo "🎉 All checks passed! You're ready to build and run the container." +echo "" +echo "Next steps:" +echo " 1. Build: ./build.sh" +echo " 2. Start: docker-compose up -d" +echo " 3. Logs: docker-compose logs -f tak-hybrid" +echo "" +echo "⚠️ Remember: Ensure you have proper licensing for TAK server software"