knightonline/server/LogInServer/build.sh

248 lines
5.5 KiB
Bash

#!/bin/bash
# Knight Online Login Server Build Script for Linux
# Author: Levent Ferrah
# Set script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
BUILD_DIR="build"
JOBS=$(nproc)
# Functions
log_message() {
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1"
}
log_error() {
echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] ERROR:${NC} $1"
}
log_success() {
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] SUCCESS:${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] WARNING:${NC} $1"
}
# Check dependencies
check_dependencies() {
log_message "Checking build dependencies..."
# Check for cmake
if ! command -v cmake &> /dev/null; then
log_error "cmake is not installed"
echo "Please install cmake: sudo apt-get install cmake"
return 1
fi
# Check for g++
if ! command -v g++ &> /dev/null; then
log_error "g++ is not installed"
echo "Please install g++: sudo apt-get install g++ build-essential"
return 1
fi
# Check for ODBC
if ! pkg-config --exists odbc &> /dev/null; then
log_warning "ODBC development files might not be installed"
echo "Consider installing: sudo apt-get install unixodbc-dev"
fi
log_success "Dependencies check completed"
return 0
}
# Clean build directory
clean_build() {
log_message "Cleaning build directory..."
if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
log_success "Build directory cleaned"
fi
}
# Build project
build_project() {
log_message "Starting build process..."
# Create build directory
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Configure with cmake
log_message "Configuring project with CMake..."
if ! cmake ..; then
log_error "CMake configuration failed"
return 1
fi
# Build project
log_message "Building project with $JOBS parallel jobs..."
if ! make -j$JOBS; then
log_error "Build failed"
return 1
fi
cd ..
log_success "Build completed successfully"
return 0
}
# Install project
install_project() {
log_message "Installing project..."
# Create bin directory if it doesn't exist
mkdir -p bin
# Copy binary
if [ -f "$BUILD_DIR/bin/LoginServer" ]; then
cp "$BUILD_DIR/bin/LoginServer" bin/
chmod +x bin/LoginServer
log_success "LoginServer binary installed to bin/"
else
log_error "LoginServer binary not found in build directory"
return 1
fi
# Make scripts executable
chmod +x loginserver.sh
log_success "Scripts made executable"
return 0
}
# Show usage
show_usage() {
echo "Knight Online Login Server Build Script"
echo ""
echo "Usage: $0 [OPTIONS] [COMMAND]"
echo ""
echo "Commands:"
echo " build - Build the project (default)"
echo " clean - Clean build directory"
echo " rebuild - Clean and build"
echo " install - Install built binaries"
echo " all - Clean, build, and install"
echo ""
echo "Options:"
echo " -h, --help - Show this help message"
echo " -j, --jobs N - Use N parallel jobs (default: $JOBS)"
echo ""
echo "Examples:"
echo " $0 # Build project"
echo " $0 clean # Clean build files"
echo " $0 rebuild # Clean and rebuild"
echo " $0 all # Full build and install"
echo " $0 -j 4 build # Build with 4 parallel jobs"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_usage
exit 0
;;
-j|--jobs)
JOBS="$2"
shift 2
;;
clean)
COMMAND="clean"
shift
;;
build)
COMMAND="build"
shift
;;
rebuild)
COMMAND="rebuild"
shift
;;
install)
COMMAND="install"
shift
;;
all)
COMMAND="all"
shift
;;
*)
log_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Default command
if [ -z "$COMMAND" ]; then
COMMAND="build"
fi
# Main execution
log_message "Knight Online Login Server Build Script"
log_message "Build command: $COMMAND"
log_message "Parallel jobs: $JOBS"
echo ""
case "$COMMAND" in
clean)
clean_build
;;
build)
if ! check_dependencies; then
exit 1
fi
if ! build_project; then
exit 1
fi
;;
rebuild)
if ! check_dependencies; then
exit 1
fi
clean_build
if ! build_project; then
exit 1
fi
;;
install)
if ! install_project; then
exit 1
fi
;;
all)
if ! check_dependencies; then
exit 1
fi
clean_build
if ! build_project; then
exit 1
fi
if ! install_project; then
exit 1
fi
log_success "Build and installation completed successfully!"
echo ""
echo "To start the server:"
echo " ./loginserver.sh start"
echo ""
echo "To check server status:"
echo " ./loginserver.sh status"
;;
esac
exit 0