Skip to content

Instantly share code, notes, and snippets.

@CraigWilsonOZ
Last active July 8, 2025 09:50
Show Gist options
  • Select an option

  • Save CraigWilsonOZ/95363586f833070073c4760c32c32fb2 to your computer and use it in GitHub Desktop.

Select an option

Save CraigWilsonOZ/95363586f833070073c4760c32c32fb2 to your computer and use it in GitHub Desktop.
Minecraft Fabric Server Setup Script (Local Workstation Edition)
#!/bin/bash
#==============================================================================
# Minecraft Fabric Server Setup Script (Local Workstation Edition)
#
# Original Author: Craig Wilson
# Modified for Local Use
# Version: 2.1-local
# Last Modified: 2025-07-08
#
# Description:
# This script sets up a Minecraft Fabric server for local play on a
# Linux workstation. It installs all server files under the current user's
# home directory.
#
#==============================================================================
# --- Script Configuration and Preamble ---
# Exit immediately if a command exits with a non-zero status.
set -euo pipefail
# --- Function Definitions ---
#
# Displays the help message for the script.
#
display_help() {
cat << EOF
Minecraft Fabric Server Setup Script - v2.1-local
This script automates the setup of a local Minecraft Fabric server.
It is rerunnable and will skip steps that are already completed.
Usage:
./setup-fabric-local.sh
Options:
-h, --help Display this help message and exit.
Before running, ensure you have installed the required dependencies:
openjdk-21-jre-headless, git, build-essential, wget
EOF
}
# === Configuration ===
INSTALL_DIR="$HOME/minecraft-fabric-server"
SERVER_DIR="$INSTALL_DIR/server"
TOOLS_DIR="$INSTALL_DIR/tools"
LOGS_DIR="$INSTALL_DIR/logs"
BACKUP_DIR="$INSTALL_DIR/backup"
MCRCON_DIR="$TOOLS_DIR/mcrcon"
# --- Fabric & Minecraft Configuration ---
# These three versions are linked. Get compatible versions from https://fabricmc.net/use/server/
MINECRAFT_VERSION="1.21.7"
FABRIC_LOADER_VERSION="0.16.14"
FABRIC_INSTALLER_VERSION="1.1.0"
# This URL is now built from the versions above using the official Fabric Meta API.
FABRIC_INSTALLER_URL="https://meta.fabricmc.net/v2/versions/loader/${MINECRAFT_VERSION}/${FABRIC_LOADER_VERSION}/${FABRIC_INSTALLER_VERSION}/server/jar"
FABRIC_INSTALLER_JAR="fabric-installer.jar"
FABRIC_SERVER_JAR="fabric-server-launch.jar"
# --- General Server Configuration ---
PASSWORD=$(date +%s | sha256sum | base64 | head -c 32 ; echo)
MAX_MEMORY="8192M"
MIN_MEMORY="8192M"
MINECRAFT_PORT="25565"
RCON_PORT="25575"
MAX_PLAYERS="20"
JDK_VERSION="openjdk-21-jre-headless"
# --- Script Execution ---
# Parse command-line options for help flag
if [[ "${1-}" =~ ^(-h|--help)$ ]]; then
display_help
exit 0
fi
echo "[+] Starting Local Minecraft Fabric Server Setup"
# === Install Dependencies ===
echo "▶ Please ensure the following dependencies are installed:"
echo " - $JDK_VERSION"
echo " - git"
echo " - build-essential"
echo " - wget"
echo "You can typically install them with: sudo apt-get update && sudo apt-get install -y $JDK_VERSION git build-essential wget"
echo ""
echo "Running the following commands will install the required dependencies:"
echo ""
echo " sudo apt-get update"
echo " sudo apt-get install -y $JDK_VERSION git build-essential cron wget"
echo ""
echo "Press Enter to continue..."
read -r
# === Create Directories ===
echo "▶ Ensuring directories exist in '$INSTALL_DIR'..."
mkdir -p "$SERVER_DIR" "$TOOLS_DIR" "$BACKUP_DIR" "$LOGS_DIR"
# === Accept EULA ===
echo "▶ Ensuring EULA is accepted..."
tee "$SERVER_DIR/eula.txt" > /dev/null <<EOF
eula=true
EOF
# === Install Fabric Server ===
if [ ! -f "$SERVER_DIR/$FABRIC_SERVER_JAR" ]; then
echo "▶ Fabric server not found. Starting installation..."
echo "▶ Downloading Fabric Installer for Minecraft $MINECRAFT_VERSION..."
wget --content-disposition -O "$SERVER_DIR/$FABRIC_INSTALLER_JAR" "$FABRIC_INSTALLER_URL"
echo "▶ Running Fabric installer..."
(cd "$SERVER_DIR" && /usr/bin/java -jar "$FABRIC_INSTALLER_JAR" server -mcversion "$MINECRAFT_VERSION" -loader "$FABRIC_LOADER_VERSION" -downloadMinecraft)
else
echo "✔ Fabric server JAR already exists. Skipping installation."
fi
# === Create Server Properties ===
echo "▶ Creating/updating server.properties..."
tee "$SERVER_DIR/server.properties" > /dev/null <<EOF
#Minecraft server properties
accepts-transfers=false
allow-flight=false
allow-nether=true
broadcast-console-to-ops=true
broadcast-rcon-to-ops=true
bug-report-link=
difficulty=easy
enable-command-block=false
enable-jmx-monitoring=false
enable-query=false
enable-rcon=true
enable-status=true
enforce-secure-profile=true
enforce-whitelist=false
entity-broadcast-range-percentage=100
force-gamemode=false
function-permission-level=2
gamemode=survival
generate-structures=true
generator-settings={}
hardcore=false
hide-online-players=false
initial-disabled-packs=
initial-enabled-packs=vanilla
level-name=world
level-seed=
level-type=minecraft\:normal
log-ips=true
max-chained-neighbor-updates=1000000
max-players=$MAX_PLAYERS
max-tick-time=60000
max-world-size=29999984
motd=A Local Minecraft Server
network-compression-threshold=256
online-mode=true
op-permission-level=4
pause-when-empty-seconds=60
player-idle-timeout=0
prevent-proxy-connections=false
pvp=true
query.port=$MINECRAFT_PORT
rate-limit=0
rcon.password=$PASSWORD
rcon.port=$RCON_PORT
region-file-compression=deflate
require-resource-pack=false
resource-pack=
resource-pack-id=
resource-pack-prompt=
resource-pack-sha1=
server-ip=
server-port=$MINECRAFT_PORT
simulation-distance=10
spawn-monsters=true
spawn-protection=16
sync-chunk-writes=true
text-filtering-config=
text-filtering-version=0
use-native-transport=true
view-distance=10
white-list=false
EOF
# === Install and Build MCRCON ===
if [ ! -d "$MCRCON_DIR" ]; then
echo "▶ Cloning and building mcrcon..."
git clone https://github.com/Tiiffi/mcrcon.git "$MCRCON_DIR"
(cd "$MCRCON_DIR" && gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c)
else
echo "✔ mcrcon directory already exists. Skipping clone and build."
fi
# === Create Helper Scripts ===
echo "▶ Creating/updating helper scripts..."
tee "$TOOLS_DIR/connect-mcrcon.sh" > /dev/null <<EOF
#!/bin/bash
$MCRCON_DIR/mcrcon -H 127.0.0.1 -P $RCON_PORT -p "$PASSWORD" -t
EOF
tee "$TOOLS_DIR/backup-minecraft.sh" > /dev/null <<EOF
#!/bin/bash
function rcon {
"$MCRCON_DIR/mcrcon" -H 127.0.0.1 -P $RCON_PORT -p "$PASSWORD" "\$1"
}
echo "Running Minecraft backup..."
rcon "save-off"; rcon "save-all"; sleep 10
tar -cvpzf "$BACKUP_DIR/server-\$(date +%F-%H-%M).tar.gz" "$SERVER_DIR"
rcon "save-on"
echo "Backup complete."
find "$BACKUP_DIR" -type f -mtime +31 -name '*.gz' -delete
EOF
tee "$TOOLS_DIR/start-minecraft.sh" > /dev/null <<EOF
#!/bin/bash
cd "$SERVER_DIR" || exit
/usr/bin/java -Xmx$MAX_MEMORY -Xms$MIN_MEMORY -jar "$FABRIC_INSTALLER_JAR" nogui
EOF
# Make all shell scripts executable
chmod +x $TOOLS_DIR/*.sh
echo ""
echo "[+] Setup Complete. Your Fabric server is ready to be started."
echo "[+] All files are located in: $INSTALL_DIR"
echo "[+] To start your server, run: $TOOLS_DIR/start-minecraft.sh"
echo "[+] To add mods, place your .jar files in: $SERVER_DIR/mods"
echo "[*] To connect to the server console (while it's running), run: $TOOLS_DIR/connect-mcrcon.sh"
echo "[*] To manually back up your server, run: $TOOLS_DIR/backup-minecraft.sh"
echo "[*] Your RCON password is: $PASSWORD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment