takserver/entrypoint.sh
Merith-TK ba547a2130
Some checks failed
Build Docker Image on Commit / build-and-publish (push) Failing after 3m8s
lets test and push
2025-07-04 02:34:05 +01:00

130 lines
4 KiB
Bash

#!/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}"
# Function to log messages
log() {
echo "[$(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
}
# 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
}
# 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
}
# Main execution
if [ "$TAK_MODE" = "database" ]; then
log "Starting TAK Server Database container..."
else
log "Starting TAK Server container..."
fi
# 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
# Verify TAK installation
if ! is_tak_installed; then
log "ERROR: TAK installation verification failed"
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"
fi