Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Minecraft Server Management Script
- # Supports installation, updates, and mod management
- set -e
- # Configuration
- SERVER_DIR="$HOME/minecraft-server"
- JAVA_VERSION="21" # Minecraft 1.21+ requires Java 17+
- MINECRAFT_VERSION="1.21.4" # Latest stable version
- FORGE_VERSION="51.0.33" # Compatible Forge version
- SERVER_JAR="minecraft_server.${MINECRAFT_VERSION}.jar"
- FORGE_JAR="forge-${MINECRAFT_VERSION}-${FORGE_VERSION}-installer.jar"
- SERVER_RAM="4G" # Adjust based on your system
- # Colors for output
- RED='\033[0;31m'
- GREEN='\033[0;32m'
- YELLOW='\033[1;33m'
- BLUE='\033[0;34m'
- NC='\033[0m' # No Color
- # Top 10 popular Minecraft mods (URLs and filenames)
- declare -A MODS=(
- ["JEI"]="https://www.curseforge.com/api/v1/mods/238222/files/latest/download"
- ["OptiFine"]="https://optifine.net/adloadx?f=OptiFine_1.21.4_HD_U_J2.jar"
- ["JourneyMap"]="https://www.curseforge.com/api/v1/mods/32274/files/latest/download"
- ["Iron Chests"]="https://www.curseforge.com/api/v1/mods/228756/files/latest/download"
- ["Biomes O' Plenty"]="https://www.curseforge.com/api/v1/mods/220318/files/latest/download"
- ["Tinkers Construct"]="https://www.curseforge.com/api/v1/mods/74072/files/latest/download"
- ["Applied Energistics 2"]="https://www.curseforge.com/api/v1/mods/223794/files/latest/download"
- ["Thermal Expansion"]="https://www.curseforge.com/api/v1/mods/69163/files/latest/download"
- ["Waystones"]="https://www.curseforge.com/api/v1/mods/245755/files/latest/download"
- ["Storage Drawers"]="https://www.curseforge.com/api/v1/mods/223852/files/latest/download"
- )
- # Logging function
- log() {
- echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
- }
- error() {
- echo -e "${RED}[ERROR]${NC} $1" >&2
- }
- success() {
- echo -e "${GREEN}[SUCCESS]${NC} $1"
- }
- warn() {
- echo -e "${YELLOW}[WARNING]${NC} $1"
- }
- # Check if Java is installed and install if needed
- install_java() {
- log "Checking Java installation..."
- if command -v java &> /dev/null; then
- JAVA_VER=$(java -version 2>&1 | head -n1 | cut -d'"' -f2 | cut -d'.' -f1)
- if [ "$JAVA_VER" -ge "$JAVA_VERSION" ]; then
- success "Java $JAVA_VER is already installed"
- return 0
- else
- warn "Java $JAVA_VER found, but Java $JAVA_VERSION+ is required"
- fi
- fi
- log "Installing OpenJDK $JAVA_VERSION..."
- sudo apt update
- sudo apt install -y openjdk-${JAVA_VERSION}-jdk
- if command -v java &> /dev/null; then
- success "Java installed successfully"
- else
- error "Failed to install Java"
- exit 1
- fi
- }
- # Create server directory structure
- setup_directories() {
- log "Setting up server directories..."
- mkdir -p "$SERVER_DIR"
- mkdir -p "$SERVER_DIR/mods"
- mkdir -p "$SERVER_DIR/backups"
- mkdir -p "$SERVER_DIR/logs"
- success "Directory structure created"
- }
- # Download Minecraft server
- download_server() {
- log "Downloading Minecraft server $MINECRAFT_VERSION..."
- cd "$SERVER_DIR"
- # Download vanilla server
- if [ ! -f "$SERVER_JAR" ]; then
- wget -O "$SERVER_JAR" "https://piston-data.mojang.com/v1/objects/450698d1863ab5180c25d7c804ef0fe6369dd1ba/server.jar"
- success "Minecraft server downloaded"
- else
- log "Server jar already exists"
- fi
- # Accept EULA
- echo "eula=true" > eula.txt
- log "EULA accepted"
- }
- # Download and install Forge
- install_forge() {
- log "Installing Minecraft Forge..."
- cd "$SERVER_DIR"
- # Download Forge installer
- if [ ! -f "$FORGE_JAR" ]; then
- wget -O "$FORGE_JAR" "https://maven.minecraftforge.net/net/minecraftforge/forge/${MINECRAFT_VERSION}-${FORGE_VERSION}/forge-${MINECRAFT_VERSION}-${FORGE_VERSION}-installer.jar"
- fi
- # Install Forge
- java -jar "$FORGE_JAR" --installServer
- success "Forge installed successfully"
- }
- # Download mods
- download_mods() {
- log "Downloading popular mods..."
- cd "$SERVER_DIR/mods"
- for mod_name in "${!MODS[@]}"; do
- log "Downloading $mod_name..."
- # Note: This is a simplified approach. In reality, you'd need to handle
- # CurseForge API keys and proper mod downloading
- warn "Mod downloading requires manual setup due to API restrictions"
- warn "Please visit CurseForge and download: $mod_name"
- done
- # Create a list of recommended mods
- cat > ../recommended_mods.txt << EOF
- Recommended Mods for your Minecraft Server:
- 1. JEI (Just Enough Items) - Recipe viewer
- 2. OptiFine - Performance optimization
- 3. JourneyMap - Minimap and waypoints
- 4. Iron Chests - Additional storage options
- 5. Biomes O' Plenty - New biomes
- 6. Tinkers Construct - Tool crafting
- 7. Applied Energistics 2 - Advanced storage
- 8. Thermal Expansion - Tech mod
- 9. Waystones - Fast travel
- 10. Storage Drawers - Compact storage
- Download these mods from CurseForge and place them in the mods/ directory.
- EOF
- success "Mod information saved to recommended_mods.txt"
- }
- # Create server configuration
- create_server_config() {
- log "Creating server configuration..."
- cd "$SERVER_DIR"
- # Create server.properties if it doesn't exist
- if [ ! -f "server.properties" ]; then
- cat > server.properties << EOF
- #Minecraft server properties
- server-port=25565
- level-name=world
- gamemode=survival
- difficulty=normal
- allow-nether=true
- max-players=20
- online-mode=true
- white-list=false
- spawn-protection=16
- motd=Welcome to your Minecraft Server!
- EOF
- fi
- success "Server configuration created"
- }
- # Create start script
- create_start_script() {
- log "Creating server start script..."
- cd "$SERVER_DIR"
- # Find the forge server jar
- FORGE_SERVER_JAR=$(find . -name "forge-*-${MINECRAFT_VERSION}-${FORGE_VERSION}.jar" | head -1)
- if [ -z "$FORGE_SERVER_JAR" ]; then
- FORGE_SERVER_JAR="forge-${MINECRAFT_VERSION}-${FORGE_VERSION}.jar"
- fi
- cat > start_server.sh << EOF
- #!/bin/bash
- # Minecraft Server Start Script
- cd "$SERVER_DIR"
- # Check if Forge server exists, otherwise use vanilla
- if [ -f "$FORGE_SERVER_JAR" ]; then
- echo "Starting Forge server..."
- java -Xmx${SERVER_RAM} -Xms1G -jar "$FORGE_SERVER_JAR" nogui
- else
- echo "Starting vanilla server..."
- java -Xmx${SERVER_RAM} -Xms1G -jar "$SERVER_JAR" nogui
- fi
- EOF
- chmod +x start_server.sh
- success "Start script created"
- }
- # Backup function
- backup_server() {
- log "Creating server backup..."
- BACKUP_NAME="minecraft-backup-$(date +%Y%m%d-%H%M%S).tar.gz"
- cd "$SERVER_DIR/.."
- tar -czf "minecraft-server/backups/$BACKUP_NAME" \
- --exclude='minecraft-server/backups' \
- --exclude='minecraft-server/logs' \
- minecraft-server/
- success "Backup created: $BACKUP_NAME"
- }
- # Update server
- update_server() {
- log "Updating Minecraft server..."
- # Create backup before updating
- backup_server
- # Update server jar (this would need version checking logic)
- warn "Server updates require manual version checking"
- warn "Check https://minecraft.net for the latest version"
- success "Update check completed"
- }
- # Show server status
- server_status() {
- log "Checking server status..."
- if pgrep -f "minecraft.*server" > /dev/null; then
- success "Minecraft server is running"
- echo "PID: $(pgrep -f 'minecraft.*server')"
- else
- warn "Minecraft server is not running"
- fi
- }
- # Display help
- show_help() {
- echo "Minecraft Server Management Script"
- echo ""
- echo "Usage: $0 [COMMAND]"
- echo ""
- echo "Commands:"
- echo " install - Install Java, download server, and set up mods"
- echo " start - Start the Minecraft server"
- echo " stop - Stop the Minecraft server"
- echo " restart - Restart the Minecraft server"
- echo " status - Show server status"
- echo " backup - Create a server backup"
- echo " update - Update the server"
- echo " mods - Show recommended mods list"
- echo " menu - Show interactive menu"
- echo " help - Show this help message"
- echo ""
- echo "Server directory: $SERVER_DIR"
- }
- # Clear screen function
- clear_screen() {
- clear
- }
- # Press any key to continue
- press_any_key() {
- echo ""
- echo -e "${YELLOW}Press any key to continue...${NC}"
- read -n 1 -s
- }
- # Display main menu
- show_menu() {
- while true; do
- clear_screen
- echo -e "${BLUE}╔══════════════════════════════════════════════════════╗${NC}"
- echo -e "${BLUE}║${NC} ${GREEN}Minecraft Server Management Menu${NC} ${BLUE}║${NC}"
- echo -e "${BLUE}╠══════════════════════════════════════════════════════╣${NC}"
- echo -e "${BLUE}║${NC} ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}1)${NC} Install Server & Mods ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}2)${NC} Start Server ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}3)${NC} Stop Server ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}4)${NC} Restart Server ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}5)${NC} Server Status ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}6)${NC} Create Backup ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}7)${NC} Update Server ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}8)${NC} View Recommended Mods ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}9)${NC} Server Configuration ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}10)${NC} View Server Logs ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${YELLOW}11)${NC} Server Information ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${RED}0)${NC} Exit ${BLUE}║${NC}"
- echo -e "${BLUE}║${NC} ${BLUE}║${NC}"
- echo -e "${BLUE}╚══════════════════════════════════════════════════════╝${NC}"
- echo ""
- # Show current server status in menu
- if pgrep -f "minecraft.*server" > /dev/null; then
- echo -e "${GREEN}● Server Status: RUNNING${NC} (PID: $(pgrep -f 'minecraft.*server'))"
- else
- echo -e "${RED}● Server Status: STOPPED${NC}"
- fi
- if [ -d "$SERVER_DIR" ]; then
- echo -e "${GREEN}● Server Directory: EXISTS${NC} ($SERVER_DIR)"
- else
- echo -e "${RED}● Server Directory: NOT FOUND${NC}"
- fi
- echo ""
- echo -n -e "${YELLOW}Enter your choice [0-11]: ${NC}"
- read choice
- case $choice in
- 1)
- clear_screen
- log "Starting server installation..."
- install_java
- setup_directories
- download_server
- install_forge
- download_mods
- create_server_config
- create_start_script
- success "Installation completed!"
- echo ""
- echo "Next steps:"
- echo "1. Download mods from the recommended_mods.txt file"
- echo "2. Place mod files in $SERVER_DIR/mods/"
- echo "3. Start the server from the menu"
- press_any_key
- ;;
- 2)
- clear_screen
- start_server
- press_any_key
- ;;
- 3)
- clear_screen
- stop_server
- press_any_key
- ;;
- 4)
- clear_screen
- log "Restarting server..."
- stop_server
- sleep 2
- start_server
- press_any_key
- ;;
- 5)
- clear_screen
- server_status
- if [ -d "$SERVER_DIR" ]; then
- echo ""
- echo "Server Directory: $SERVER_DIR"
- if [ -f "$SERVER_DIR/server.properties" ]; then
- echo "Server Port: $(grep '^server-port' $SERVER_DIR/server.properties | cut -d'=' -f2)"
- echo "Max Players: $(grep '^max-players' $SERVER_DIR/server.properties | cut -d'=' -f2)"
- echo "Game Mode: $(grep '^gamemode' $SERVER_DIR/server.properties | cut -d'=' -f2)"
- fi
- fi
- press_any_key
- ;;
- 6)
- clear_screen
- if [ ! -d "$SERVER_DIR" ]; then
- error "Server not installed. Please install first."
- else
- backup_server
- echo ""
- echo -e "${GREEN}Available backups:${NC}"
- ls -la "$SERVER_DIR/backups/" 2>/dev/null | grep ".tar.gz" || echo "No backups found"
- fi
- press_any_key
- ;;
- 7)
- clear_screen
- update_server
- press_any_key
- ;;
- 8)
- clear_screen
- if [ -f "$SERVER_DIR/recommended_mods.txt" ]; then
- cat "$SERVER_DIR/recommended_mods.txt"
- echo ""
- echo -e "${YELLOW}Mod Installation Instructions:${NC}"
- echo "1. Visit https://www.curseforge.com/minecraft/mc-mods"
- echo "2. Search for each mod by name"
- echo "3. Download the .jar files for Minecraft $MINECRAFT_VERSION"
- echo "4. Place all .jar files in: $SERVER_DIR/mods/"
- else
- error "Mods list not found. Please install server first."
- fi
- press_any_key
- ;;
- 9)
- clear_screen
- show_config_menu
- ;;
- 10)
- clear_screen
- show_logs_menu
- ;;
- 11)
- clear_screen
- show_server_info
- press_any_key
- ;;
- 0)
- clear_screen
- echo -e "${GREEN}Thank you for using Minecraft Server Manager!${NC}"
- echo -e "${BLUE}Server directory: $SERVER_DIR${NC}"
- exit 0
- ;;
- *)
- clear_screen
- error "Invalid option. Please choose 0-11."
- sleep 2
- ;;
- esac
- done
- }
- # Configuration menu
- show_config_menu() {
- while true; do
- clear_screen
- echo -e "${BLUE}╔══════════════════════════════════════════════════════╗${NC}"
- echo -e "${BLUE}║${NC} ${GREEN}Server Configuration Menu${NC} ${BLUE}║${NC}"
- echo -e "${BLUE}╚══════════════════════════════════════════════════════╝${NC}"
- echo ""
- if [ -f "$SERVER_DIR/server.properties" ]; then
- echo -e "${GREEN}Current Configuration:${NC}"
- echo "Server Port: $(grep '^server-port' $SERVER_DIR/server.properties | cut -d'=' -f2)"
- echo "Max Players: $(grep '^max-players' $SERVER_DIR/server.properties | cut -d'=' -f2)"
- echo "Game Mode: $(grep '^gamemode' $SERVER_DIR/server.properties | cut -d'=' -f2)"
- echo "Difficulty: $(grep '^difficulty' $SERVER_DIR/server.properties | cut -d'=' -f2)"
- echo "MOTD: $(grep '^motd' $SERVER_DIR/server.properties | cut -d'=' -f2)"
- echo ""
- else
- warn "Server not installed or configuration not found."
- echo ""
- fi
- echo -e "${YELLOW}1)${NC} Edit Server Properties File"
- echo -e "${YELLOW}2)${NC} Change Server Port"
- echo -e "${YELLOW}3)${NC} Change Max Players"
- echo -e "${YELLOW}4)${NC} Change Game Mode"
- echo -e "${YELLOW}5)${NC} Change Server MOTD"
- echo -e "${YELLOW}6)${NC} Reset to Default Configuration"
- echo -e "${RED}0)${NC} Back to Main Menu"
- echo ""
- echo -n -e "${YELLOW}Enter your choice [0-6]: ${NC}"
- read config_choice
- case $config_choice in
- 1)
- if command -v nano &> /dev/null; then
- nano "$SERVER_DIR/server.properties"
- elif command -v vim &> /dev/null; then
- vim "$SERVER_DIR/server.properties"
- else
- error "No text editor found. Please install nano or vim."
- press_any_key
- fi
- ;;
- 2)
- echo -n "Enter new server port (default 25565): "
- read new_port
- if [[ "$new_port" =~ ^[0-9]+$ ]] && [ "$new_port" -ge 1024 ] && [ "$new_port" -le 65535 ]; then
- sed -i "s/^server-port=.*/server-port=$new_port/" "$SERVER_DIR/server.properties"
- success "Server port changed to $new_port"
- else
- error "Invalid port number. Must be between 1024 and 65535."
- fi
- press_any_key
- ;;
- 3)
- echo -n "Enter max players (1-100): "
- read max_players
- if [[ "$max_players" =~ ^[0-9]+$ ]] && [ "$max_players" -ge 1 ] && [ "$max_players" -le 100 ]; then
- sed -i "s/^max-players=.*/max-players=$max_players/" "$SERVER_DIR/server.properties"
- success "Max players changed to $max_players"
- else
- error "Invalid number. Must be between 1 and 100."
- fi
- press_any_key
- ;;
- 4)
- echo "Game modes:"
- echo "1) Survival"
- echo "2) Creative"
- echo "3) Adventure"
- echo "4) Spectator"
- echo -n "Choose game mode [1-4]: "
- read gamemode_choice
- case $gamemode_choice in
- 1) gamemode="survival" ;;
- 2) gamemode="creative" ;;
- 3) gamemode="adventure" ;;
- 4) gamemode="spectator" ;;
- *) error "Invalid choice"; press_any_key; continue ;;
- esac
- sed -i "s/^gamemode=.*/gamemode=$gamemode/" "$SERVER_DIR/server.properties"
- success "Game mode changed to $gamemode"
- press_any_key
- ;;
- 5)
- echo -n "Enter new MOTD: "
- read new_motd
- sed -i "s/^motd=.*/motd=$new_motd/" "$SERVER_DIR/server.properties"
- success "MOTD changed to: $new_motd"
- press_any_key
- ;;
- 6)
- echo -n "Reset configuration to defaults? [y/N]: "
- read confirm
- if [[ "$confirm" =~ ^[Yy]$ ]]; then
- create_server_config
- success "Configuration reset to defaults"
- else
- log "Configuration reset cancelled"
- fi
- press_any_key
- ;;
- 0)
- break
- ;;
- *)
- error "Invalid option. Please choose 0-6."
- sleep 2
- ;;
- esac
- done
- }
- # Logs menu
- show_logs_menu() {
- while true; do
- clear_screen
- echo -e "${BLUE}╔══════════════════════════════════════════════════════╗${NC}"
- echo -e "${BLUE}║${NC} ${GREEN}Server Logs Menu${NC} ${BLUE}║${NC}"
- echo -e "${BLUE}╚══════════════════════════════════════════════════════╝${NC}"
- echo ""
- echo -e "${YELLOW}1)${NC} View Live Server Log (last 50 lines)"
- echo -e "${YELLOW}2)${NC} View Full Server Log"
- echo -e "${YELLOW}3)${NC} View Latest Crash Report"
- echo -e "${YELLOW}4)${NC} Clear Server Logs"
- echo -e "${YELLOW}5)${NC} Monitor Live Server Output"
- echo -e "${RED}0)${NC} Back to Main Menu"
- echo ""
- echo -n -e "${YELLOW}Enter your choice [0-5]: ${NC}"
- read logs_choice
- case $logs_choice in
- 1)
- clear_screen
- if [ -f "$SERVER_DIR/logs/server.log" ]; then
- echo -e "${GREEN}Last 50 lines of server log:${NC}"
- echo "----------------------------------------"
- tail -n 50 "$SERVER_DIR/logs/server.log"
- else
- warn "Server log not found. Server may not have been started yet."
- fi
- press_any_key
- ;;
- 2)
- if [ -f "$SERVER_DIR/logs/server.log" ]; then
- less "$SERVER_DIR/logs/server.log"
- else
- warn "Server log not found."
- press_any_key
- fi
- ;;
- 3)
- clear_screen
- crash_report=$(find "$SERVER_DIR" -name "crash-*" -type f 2>/dev/null | head -1)
- if [ -n "$crash_report" ]; then
- echo -e "${GREEN}Latest crash report:${NC}"
- echo "----------------------------------------"
- cat "$crash_report"
- else
- success "No crash reports found!"
- fi
- press_any_key
- ;;
- 4)
- echo -n "Clear all server logs? [y/N]: "
- read confirm
- if [[ "$confirm" =~ ^[Yy]$ ]]; then
- rm -f "$SERVER_DIR/logs/"*.log 2>/dev/null
- rm -f "$SERVER_DIR/"crash-*.txt 2>/dev/null
- success "Server logs cleared"
- else
- log "Log clearing cancelled"
- fi
- press_any_key
- ;;
- 5)
- if pgrep -f "minecraft.*server" > /dev/null; then
- clear_screen
- echo -e "${GREEN}Monitoring live server output. Press Ctrl+C to stop.${NC}"
- echo "----------------------------------------"
- tail -f "$SERVER_DIR/logs/server.log" 2>/dev/null || echo "Log file not found"
- else
- error "Server is not running"
- press_any_key
- fi
- ;;
- 0)
- break
- ;;
- *)
- error "Invalid option. Please choose 0-5."
- sleep 2
- ;;
- esac
- done
- }
- # Show server information
- show_server_info() {
- echo -e "${BLUE}╔══════════════════════════════════════════════════════╗${NC}"
- echo -e "${BLUE}║${NC} ${GREEN}Server Information${NC} ${BLUE}║${NC}"
- echo -e "${BLUE}╚══════════════════════════════════════════════════════╝${NC}"
- echo ""
- echo -e "${GREEN}System Information:${NC}"
- echo "Java Version: $(java -version 2>&1 | head -n1 | cut -d'"' -f2)"
- echo "Operating System: $(uname -s) $(uname -r)"
- echo "Available Memory: $(free -h | grep '^Mem:' | awk '{print $2}')"
- echo "Free Disk Space: $(df -h $HOME | tail -1 | awk '{print $4}')"
- echo ""
- echo -e "${GREEN}Server Configuration:${NC}"
- echo "Minecraft Version: $MINECRAFT_VERSION"
- echo "Forge Version: $FORGE_VERSION"
- echo "Server RAM Allocation: $SERVER_RAM"
- echo "Server Directory: $SERVER_DIR"
- echo ""
- if [ -d "$SERVER_DIR" ]; then
- echo -e "${GREEN}Installation Status:${NC}"
- [ -f "$SERVER_DIR/$SERVER_JAR" ] && echo "✓ Minecraft Server: Installed" || echo "✗ Minecraft Server: Not Found"
- [ -f "$SERVER_DIR/forge-${MINECRAFT_VERSION}-${FORGE_VERSION}.jar" ] && echo "✓ Forge: Installed" || echo "✗ Forge: Not Found"
- [ -d "$SERVER_DIR/mods" ] && echo "✓ Mods Directory: Created ($(ls $SERVER_DIR/mods/*.jar 2>/dev/null | wc -l) mods installed)" || echo "✗ Mods Directory: Not Found"
- [ -f "$SERVER_DIR/server.properties" ] && echo "✓ Configuration: Created" || echo "✗ Configuration: Not Found"
- echo ""
- echo -e "${GREEN}Directory Size:${NC}"
- du -sh "$SERVER_DIR" 2>/dev/null | awk '{print "Total Size: " $1}'
- else
- echo -e "${RED}Server not installed${NC}"
- fi
- }
- # Stop server
- stop_server() {
- log "Stopping Minecraft server..."
- if pgrep -f "minecraft.*server" > /dev/null; then
- pkill -f "minecraft.*server"
- sleep 5
- if pgrep -f "minecraft.*server" > /dev/null; then
- warn "Forcefully killing server..."
- pkill -9 -f "minecraft.*server"
- fi
- success "Server stopped"
- else
- warn "Server is not running"
- fi
- }
- # Start server
- start_server() {
- log "Starting Minecraft server..."
- if pgrep -f "minecraft.*server" > /dev/null; then
- warn "Server is already running"
- return 1
- fi
- cd "$SERVER_DIR"
- if [ -f "start_server.sh" ]; then
- nohup ./start_server.sh > logs/server.log 2>&1 &
- success "Server started in background. Check logs/server.log for output"
- else
- error "Start script not found. Run 'install' first."
- return 1
- fi
- }
- # Main script logic
- case "${1:-menu}" in
- install)
- log "Installing Minecraft server..."
- install_java
- setup_directories
- download_server
- install_forge
- download_mods
- create_server_config
- create_start_script
- success "Installation completed!"
- echo ""
- echo "Next steps:"
- echo "1. Download mods from the recommended_mods.txt file"
- echo "2. Place mod files in $SERVER_DIR/mods/"
- echo "3. Run '$0 start' to start the server"
- ;;
- start)
- start_server
- ;;
- stop)
- stop_server
- ;;
- restart)
- stop_server
- sleep 2
- start_server
- ;;
- status)
- server_status
- ;;
- backup)
- backup_server
- ;;
- update)
- update_server
- ;;
- mods)
- if [ -f "$SERVER_DIR/recommended_mods.txt" ]; then
- cat "$SERVER_DIR/recommended_mods.txt"
- else
- error "Mods list not found. Run 'install' first."
- fi
- ;;
- menu)
- show_menu
- ;;
- help|--help|-h)
- show_help
- ;;
- *)
- show_menu
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement