Fix Docker setup - download GMod at runtime

- Dockerfile now only installs SteamCMD, server downloaded on first run
- Entrypoint handles full server installation including addons
- Fixed volume configuration for persistence
- Added AUTO_UPDATE environment variable
This commit is contained in:
Vish
2026-01-19 06:44:41 +00:00
parent ce7fc9f39c
commit 82ad91ea4e
3 changed files with 126 additions and 68 deletions

View File

@@ -3,8 +3,9 @@
# Garry's Mod PropHunt Server - Docker Entrypoint
#===============================================================================
SERVER_DIR="${GMOD_INSTALL_DIR:-/home/gmod}/serverfiles"
STEAMCMD_DIR="${GMOD_INSTALL_DIR:-/home/gmod}/steamcmd"
SERVER_DIR="/home/gmod/serverfiles"
STEAMCMD_DIR="/home/gmod/steamcmd"
CFG_TEMPLATE="/home/gmod/cfg-template"
RED='\033[0;31m'
GREEN='\033[0;32m'
@@ -15,6 +16,7 @@ NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
echo -e "${GREEN}"
echo "╔═══════════════════════════════════════════════════════════════╗"
@@ -22,16 +24,105 @@ echo "║ 🎮 Garry's Mod PropHunt Server Starting 🎮 ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
# Update server if AUTO_UPDATE is set
if [[ "${AUTO_UPDATE:-false}" == "true" ]]; then
log_info "Checking for server updates..."
# Check if server is installed
install_server() {
log_info "Installing/Updating Garry's Mod server..."
cd "$STEAMCMD_DIR"
./steamcmd.sh +force_install_dir "$SERVER_DIR" \
./steamcmd.sh +@sSteamCmdForcePlatformType linux \
+force_install_dir "$SERVER_DIR" \
+login anonymous \
+app_update 4020 \
+app_update 4020 validate \
+quit
if [[ $? -ne 0 ]]; then
log_error "Failed to install server. Retrying..."
./steamcmd.sh +@sSteamCmdForcePlatformType linux \
+force_install_dir "$SERVER_DIR" \
+login anonymous \
+app_update 4020 \
+quit
fi
}
install_addons() {
log_info "Installing MetaMod, SourceMod, and ULX..."
cd /tmp
# Install MetaMod
METAMOD_VER=$(curl -s "https://mms.alliedmods.net/mmsdrop/1.11/" | grep -oP 'mmsource-[\d.]+-git\d+-linux\.tar\.gz' | tail -1)
if [[ -n "$METAMOD_VER" ]]; then
wget -q "https://mms.alliedmods.net/mmsdrop/1.11/${METAMOD_VER}" -O metamod.tar.gz
tar -xzf metamod.tar.gz -C "$SERVER_DIR/garrysmod/"
rm -f metamod.tar.gz
log_success "MetaMod installed."
fi
# Install SourceMod
SOURCEMOD_VER=$(curl -s "https://sm.alliedmods.net/smdrop/1.11/" | grep -oP 'sourcemod-[\d.]+-git\d+-linux\.tar\.gz' | tail -1)
if [[ -n "$SOURCEMOD_VER" ]]; then
wget -q "https://sm.alliedmods.net/smdrop/1.11/${SOURCEMOD_VER}" -O sourcemod.tar.gz
tar -xzf sourcemod.tar.gz -C "$SERVER_DIR/garrysmod/"
rm -f sourcemod.tar.gz
log_success "SourceMod installed."
fi
# Install ULib
if [[ ! -d "$SERVER_DIR/garrysmod/addons/ulib" ]]; then
wget -q "https://github.com/TeamUlysses/ulib/archive/refs/heads/master.zip" -O ulib.zip
unzip -q ulib.zip -d "$SERVER_DIR/garrysmod/addons/"
mv "$SERVER_DIR/garrysmod/addons/ulib-master" "$SERVER_DIR/garrysmod/addons/ulib"
rm -f ulib.zip
log_success "ULib installed."
fi
# Install ULX
if [[ ! -d "$SERVER_DIR/garrysmod/addons/ulx" ]]; then
wget -q "https://github.com/TeamUlysses/ulx/archive/refs/heads/master.zip" -O ulx.zip
unzip -q ulx.zip -d "$SERVER_DIR/garrysmod/addons/"
mv "$SERVER_DIR/garrysmod/addons/ulx-master" "$SERVER_DIR/garrysmod/addons/ulx"
rm -f ulx.zip
log_success "ULX installed."
fi
}
apply_configs() {
log_info "Applying configuration files..."
# Copy default configs if they don't exist
if [[ -d "$CFG_TEMPLATE" ]]; then
mkdir -p "$SERVER_DIR/garrysmod/cfg"
for file in "$CFG_TEMPLATE"/*; do
if [[ -f "$file" ]]; then
filename=$(basename "$file")
if [[ ! -f "$SERVER_DIR/garrysmod/cfg/$filename" ]]; then
cp "$file" "$SERVER_DIR/garrysmod/cfg/"
fi
fi
done
fi
log_success "Configuration applied."
}
# Check if server needs installation
if [[ ! -f "$SERVER_DIR/srcds_run" ]]; then
log_info "Server not found. Installing..."
install_server
install_addons
apply_configs
elif [[ "${AUTO_UPDATE:-true}" == "true" ]]; then
log_info "Checking for updates..."
install_server
fi
# Ensure addons are installed
if [[ ! -d "$SERVER_DIR/garrysmod/addons/ulx" ]]; then
install_addons
fi
apply_configs
cd "$SERVER_DIR"
# Build command line arguments
@@ -78,10 +169,18 @@ echo ""
log_info "Starting server..."
# Handle shutdown signals
trap 'log_info "Shutting down server..."; kill -SIGTERM $SERVER_PID; wait $SERVER_PID' SIGTERM SIGINT
cleanup() {
log_info "Shutting down server..."
if [[ -n "$SERVER_PID" ]]; then
kill -SIGTERM $SERVER_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null
fi
exit 0
}
trap cleanup SIGTERM SIGINT
# Start the server
exec ./srcds_run $ARGS &
./srcds_run $ARGS &
SERVER_PID=$!
# Wait for the server process