gitea, zomboid updates, ssh key fixes
This commit is contained in:
@@ -1,103 +1,89 @@
|
||||
#!/bin/bash
|
||||
# Project Zomboid Build 42 Server Entrypoint
|
||||
# Based on IndifferentBroccoli/projectzomboid-server-docker
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
INSTALL_DIR="/project-zomboid"
|
||||
CONFIG_DIR="/project-zomboid-config"
|
||||
STEAMCMD="/home/steam/steamcmd/steamcmd.sh"
|
||||
INSTALL_DIR="/home/steam/pzserver"
|
||||
DATA_DIR="/home/steam/Zomboid"
|
||||
SERVER_NAME="${SERVER_NAME:-zomboid}"
|
||||
MIN_RAM="${MIN_RAM:-8g}"
|
||||
MAX_RAM="${MAX_RAM:-24g}"
|
||||
PUID="${PUID:-1000}"
|
||||
PGID="${PGID:-1000}"
|
||||
MIN_RAM="${MIN_RAM:-4g}"
|
||||
MAX_RAM="${MAX_RAM:-8g}"
|
||||
|
||||
echo "=== Project Zomboid Build 42 Server ==="
|
||||
echo "Server Name: ${SERVER_NAME}"
|
||||
echo "RAM: ${MIN_RAM} - ${MAX_RAM}"
|
||||
|
||||
# Fix ownership of mounted volumes (container runs as steam user, UID 1000)
|
||||
echo "=== Fixing volume permissions ==="
|
||||
chown -R steam:steam "${INSTALL_DIR}" || true
|
||||
chown -R steam:steam "${DATA_DIR}" || true
|
||||
chmod -R 755 "${INSTALL_DIR}" || true
|
||||
chmod -R 755 "${DATA_DIR}" || true
|
||||
# Set user permissions (IndifferentBroccoli approach)
|
||||
echo "=== Setting file permissions ==="
|
||||
usermod -o -u "${PUID}" steam
|
||||
groupmod -o -g "${PGID}" steam
|
||||
chown -R steam:steam "${INSTALL_DIR}" "${CONFIG_DIR}"
|
||||
# Only chown writable parts of /home/steam (not read-only mounts)
|
||||
chown steam:steam /home/steam
|
||||
chown -R steam:steam /home/steam/steamcmd 2>/dev/null || true
|
||||
chown -R steam:steam /home/steam/Steam 2>/dev/null || true
|
||||
|
||||
# Create required subdirectories with correct ownership
|
||||
mkdir -p "${DATA_DIR}/Server"
|
||||
mkdir -p "${DATA_DIR}/Saves/Multiplayer"
|
||||
mkdir -p "${DATA_DIR}/db"
|
||||
chown -R steam:steam "${DATA_DIR}"
|
||||
|
||||
# Ensure steam user has proper home directory setup
|
||||
export HOME=/home/steam
|
||||
|
||||
# Initialize SteamCMD if needed (creates config directories)
|
||||
if [ ! -d "/home/steam/Steam" ]; then
|
||||
echo "=== Initializing SteamCMD ==="
|
||||
su -c "${STEAMCMD} +quit" steam || true
|
||||
fi
|
||||
# Create required directories
|
||||
mkdir -p "${CONFIG_DIR}/Server"
|
||||
mkdir -p "${CONFIG_DIR}/Saves"
|
||||
mkdir -p "${CONFIG_DIR}/db"
|
||||
|
||||
# Update/Install PZ dedicated server with Build 42 unstable branch
|
||||
if [ "${AUTO_UPDATE:-true}" = "true" ]; then
|
||||
echo "=== Updating Project Zomboid Server (Build 42 unstable) ==="
|
||||
# Run steamcmd as steam user with proper quoting for beta flag
|
||||
su -c "${STEAMCMD} +force_install_dir ${INSTALL_DIR} +login anonymous +app_update 380870 -beta unstable validate +quit" steam
|
||||
su -c "${STEAMCMD} +runscript /home/steam/install.scmd" steam
|
||||
echo "=== Update complete ==="
|
||||
fi
|
||||
|
||||
# Ensure data directories exist (created earlier with correct permissions)
|
||||
# Configure JVM memory settings in ProjectZomboid64.json (Build 42 uses JSON config)
|
||||
configure_memory() {
|
||||
local json_file="${INSTALL_DIR}/ProjectZomboid64.json"
|
||||
|
||||
# Configure server settings on first run
|
||||
SERVER_INI="${DATA_DIR}/Server/${SERVER_NAME}.ini"
|
||||
if [ ! -f "${SERVER_INI}" ]; then
|
||||
echo "=== First run detected, server will generate default config ==="
|
||||
fi
|
||||
if [ ! -f "$json_file" ]; then
|
||||
echo "=== ProjectZomboid64.json not found, skipping memory config ==="
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Handle admin password for first run
|
||||
# PZ requires interactive password input on first run, so we create a db file
|
||||
ADMIN_DB="${DATA_DIR}/db/${SERVER_NAME}.db"
|
||||
if [ ! -f "${ADMIN_DB}" ] && [ -n "${ADMIN_PASSWORD}" ]; then
|
||||
echo "=== Setting up admin account ==="
|
||||
mkdir -p "${DATA_DIR}/db"
|
||||
# The server will prompt for password on first run
|
||||
# We'll use expect-like behavior or let it use defaults
|
||||
fi
|
||||
echo "=== Configuring JVM memory: Xms=${MIN_RAM}, Xmx=${MAX_RAM} ==="
|
||||
|
||||
# Modify memory settings in ProjectZomboid64.json (Build 42 uses JSON config)
|
||||
PZ_JSON="${INSTALL_DIR}/ProjectZomboid64.json"
|
||||
if [ -f "${PZ_JSON}" ]; then
|
||||
echo "=== Setting JVM memory: Xms=${MIN_RAM}, Xmx=${MAX_RAM} ==="
|
||||
# Add -Xms if not present, otherwise update it
|
||||
if grep -q "\-Xms" "${PZ_JSON}"; then
|
||||
sed -i "s/-Xms[0-9]*[gGmM]*/-Xms${MIN_RAM}/g" "${PZ_JSON}"
|
||||
# Update Xmx
|
||||
sed -i "s/-Xmx[0-9]*[gGmM]*/-Xmx${MAX_RAM}/g" "$json_file"
|
||||
|
||||
# Update or add Xms
|
||||
if grep -q "\-Xms" "$json_file"; then
|
||||
sed -i "s/-Xms[0-9]*[gGmM]*/-Xms${MIN_RAM}/g" "$json_file"
|
||||
else
|
||||
# Insert -Xms before -Xmx
|
||||
sed -i "s/\"-Xmx/\"-Xms${MIN_RAM}\",\n\t\t\"-Xmx/g" "${PZ_JSON}"
|
||||
sed -i "s/\"-Xmx/\"-Xms${MIN_RAM}\",\n\t\t\"-Xmx/g" "$json_file"
|
||||
fi
|
||||
sed -i "s/-Xmx[0-9]*[gGmM]*/-Xmx${MAX_RAM}/g" "${PZ_JSON}"
|
||||
|
||||
echo "=== Memory configuration complete ==="
|
||||
}
|
||||
configure_memory
|
||||
|
||||
# Check if first run (no admin DB)
|
||||
ADMIN_DB="${CONFIG_DIR}/db/${SERVER_NAME}.db"
|
||||
|
||||
# Build server arguments
|
||||
# Note: -modfolders is NOT used - mods are configured via INI only
|
||||
# Reference: IndifferentBroccoli/projectzomboid-server-docker
|
||||
SERVER_ARGS="-cachedir=${CONFIG_DIR} -servername ${SERVER_NAME}"
|
||||
|
||||
# Add admin password for first run
|
||||
if [ ! -f "${ADMIN_DB}" ] && [ -n "${ADMIN_PASSWORD}" ]; then
|
||||
echo "=== First run: setting admin password ==="
|
||||
SERVER_ARGS="${SERVER_ARGS} -adminpassword ${ADMIN_PASSWORD}"
|
||||
fi
|
||||
|
||||
# If server password is set, we'll need to configure it in the ini after first run
|
||||
# For now, store it for later configuration
|
||||
if [ -n "${SERVER_PASSWORD}" ]; then
|
||||
echo "${SERVER_PASSWORD}" > "${DATA_DIR}/.server_password"
|
||||
fi
|
||||
# Note: Server password is set via INI file, not command line args
|
||||
|
||||
if [ -n "${ADMIN_PASSWORD}" ]; then
|
||||
echo "${ADMIN_PASSWORD}" > "${DATA_DIR}/.admin_password"
|
||||
fi
|
||||
|
||||
# Change to install directory and start server
|
||||
# Start server
|
||||
cd "${INSTALL_DIR}"
|
||||
|
||||
echo "=== Starting Project Zomboid Server ==="
|
||||
echo "Connect to: home.bdebyl.net:16261"
|
||||
|
||||
# Start server - on first run this will prompt for admin password
|
||||
# We handle this by providing input via stdin if password file exists
|
||||
if [ -f "${DATA_DIR}/.admin_password" ] && [ ! -f "${ADMIN_DB}" ]; then
|
||||
# First run with admin password
|
||||
ADMIN_PASS=$(cat "${DATA_DIR}/.admin_password")
|
||||
echo "=== First run: setting admin password ==="
|
||||
printf "%s\n%s\n" "${ADMIN_PASS}" "${ADMIN_PASS}" | su -c "bash start-server.sh -servername ${SERVER_NAME}" steam
|
||||
else
|
||||
# Normal run
|
||||
exec su -c "bash start-server.sh -servername ${SERVER_NAME}" steam
|
||||
fi
|
||||
exec su -c "export LD_LIBRARY_PATH=${INSTALL_DIR}/jre64/lib:\${LD_LIBRARY_PATH} && ./start-server.sh ${SERVER_ARGS}" steam
|
||||
|
||||
Reference in New Issue
Block a user