clense for rebuild

This commit is contained in:
Merith-TK 2025-07-05 16:14:58 +01:00
parent 40fc5d810a
commit c772f0ca99
13 changed files with 19 additions and 1557 deletions

View file

@ -1,144 +0,0 @@
#!/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

View file

@ -1,224 +0,0 @@
#!/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

View file

@ -1,193 +0,0 @@
#!/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 <zip_file> <target_dir>"
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] <args>"
echo " extract <zip_file> <target_dir> - Extract TAK server from ZIP"
echo " verify <install_dir> - Verify TAK installation"
echo " permissions <install_dir> [owner] - Set TAK permissions"
exit 1
;;
esac
fi

View file

@ -1,68 +0,0 @@
#!/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 <dir> version <zip_file>"
exit 1
fi
;;
*)
echo "Usage: $0 <directory> [latest|list|version <zip_file>]"
exit 1
;;
esac
fi