freetak/scripts/dev-helper.sh
Merith-TK bfc790355a
All checks were successful
Build Docker Image on Commit / build-and-publish (push) Successful in 16m30s
it builds, but does it run?
2025-07-04 22:27:34 +01:00

160 lines
3.8 KiB
Bash
Executable file

#!/bin/bash
# Development helper script for FreeTAKServer Docker container
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if script exists and is executable
check_script() {
local script_path="$1"
local script_name=$(basename "$script_path")
if [[ ! -f "$script_path" ]]; then
print_error "Script $script_name not found at $script_path"
return 1
fi
if [[ ! -x "$script_path" ]]; then
print_warning "Script $script_name is not executable, fixing..."
chmod +x "$script_path"
fi
print_success "Script $script_name is ready"
return 0
}
# Function to validate scripts
validate_scripts() {
print_status "Validating scripts..."
local scripts=(
"$PROJECT_DIR/scripts/install_freetak.sh"
"$PROJECT_DIR/scripts/start_freetak.sh"
"$PROJECT_DIR/scripts/healthcheck.sh"
"$PROJECT_DIR/scripts/entrypoint.sh"
)
local all_valid=true
for script in "${scripts[@]}"; do
if ! check_script "$script"; then
all_valid=false
fi
done
if [[ "$all_valid" == true ]]; then
print_success "All scripts are valid and executable"
else
print_error "Some scripts have issues"
exit 1
fi
}
# Function to test script syntax
test_syntax() {
print_status "Testing script syntax..."
local scripts=(
"$PROJECT_DIR/scripts/install_freetak.sh"
"$PROJECT_DIR/scripts/start_freetak.sh"
"$PROJECT_DIR/scripts/healthcheck.sh"
"$PROJECT_DIR/scripts/entrypoint.sh"
)
for script in "${scripts[@]}"; do
local script_name=$(basename "$script")
if bash -n "$script"; then
print_success "Syntax check passed for $script_name"
else
print_error "Syntax check failed for $script_name"
exit 1
fi
done
}
# Function to show script information
show_info() {
print_status "FreeTAKServer Docker Scripts Information"
echo
echo "Scripts directory: $PROJECT_DIR/scripts/"
echo
echo "Available scripts:"
echo " install_freetak.sh - Installs FreeTAKServer using Ansible"
echo " start_freetak.sh - Simple startup script"
echo " entrypoint.sh - Main entrypoint with signal handling"
echo " healthcheck.sh - Health check script"
echo
echo "Usage in Dockerfile:"
echo " COPY scripts/ /opt/scripts/"
echo " RUN chmod +x /opt/scripts/*.sh"
echo
}
# Function to show usage
usage() {
echo "Usage: $0 [COMMAND]"
echo
echo "Commands:"
echo " validate Validate all scripts exist and are executable"
echo " test Test script syntax"
echo " info Show information about scripts"
echo " help Show this help message"
echo
echo "If no command is provided, 'validate' is run by default."
}
# Main script logic
main() {
case "${1:-validate}" in
validate)
validate_scripts
;;
test)
validate_scripts
test_syntax
;;
info)
show_info
;;
help|--help|-h)
usage
;;
*)
print_error "Unknown command: $1"
usage
exit 1
;;
esac
}
# Change to project directory
cd "$PROJECT_DIR"
# Run main function
main "$@"