Skip to content

Commit

Permalink
Enable Xonotic fps game deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored May 20, 2024
2 parents 33ae3ff + 9317d9a commit ec2875b
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions scripts/usecases/xonotic/startServer.sh
Original file line number Diff line number Diff line change
@@ -1,63 +1,71 @@
#!/bin/bash

# This script should be run as root, so we check for root privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi

echo "[Start Xonotic FPS Game Server Installation]"

SECONDS=0

serverName=${1:-Xonotic-0.8.5-by-Cloud-Barista}
serverName=${1:-Xonotic-0.8.6-Cloud-Barista}
serverPort=${2:-26000}
numBot=${3:-2}
numMaxUser=32
FILE="xonotic-0.8.5.zip"
DIR="/root/Xonotic"
INSTALL_PATH="/root"
SERVICE_FILE="/etc/systemd/system/xonotic.service"
LOG_DIR="/var/log/xonotic"
FILE="xonotic-0.8.6.zip"
DOWNLOADLINK="https://dl.unvanquished.net/share/xonotic/release/xonotic-0.8.6.zip"
DIR="$HOME/Xonotic"
INSTALL_PATH="$HOME"
SERVICE_FILE="$HOME/.config/systemd/user/xonotic.service"
LOG_DIR="$HOME/.xonotic/logs"
XONOTIC_BINARY="xonotic-linux64-dedicated"
CONFIG_DIR="$INSTALL_PATH/.xonotic/data"
CONFIG_DIR="$HOME/.xonotic/data"

# Create necessary directories
mkdir -p "$INSTALL_PATH" "$DIR" "$LOG_DIR" "$CONFIG_DIR"

# Download and unzip Xonotic if it's not already present
if [ ! -f "$INSTALL_PATH/$FILE" ]; then
apt-get update > /dev/null
wget -O "$INSTALL_PATH/$FILE" "https://github.com/garymoon/xonotic/releases/download/xonotic-v0.8.5/$FILE"
sudo apt-get update > /dev/null
sudo apt install unzip -y
wget -O "$INSTALL_PATH/$FILE" "$DOWNLOADLINK"
chmod +x "$INSTALL_PATH/$FILE"
fi

if [ ! -d "$DIR" ]; then
apt install unzip -y
unzip "$INSTALL_PATH/$FILE" -d "$INSTALL_PATH"
unzip "$INSTALL_PATH/$FILE"


# Ensure the binary exists and is executable
if [ ! -f "$DIR/$XONOTIC_BINARY" ]; then
echo "Xonotic binary not found at $DIR/$XONOTIC_BINARY"
exit 1
fi
chmod +x "$DIR/$XONOTIC_BINARY"

# Create configuration file with user inputs
appendConfig="port $serverPort\nhostname \"$serverName\"\nmaxplayers $numMaxUser\nbot_number $numBot"
mkdir -p "$CONFIG_DIR"
cp "$DIR/server/server.cfg" "$CONFIG_DIR"
if [ -f "$DIR/server/server.cfg" ]; then
cp "$DIR/server/server.cfg" "$CONFIG_DIR"
else
echo "server.cfg not found at $DIR/server/server.cfg"
exit 1
fi
echo -e "${appendConfig}" >> "$CONFIG_DIR/server.cfg"

# Create systemd service file
echo "Creating systemd service file for Xonotic Server"
mkdir -p "$(dirname $SERVICE_FILE)"
cat <<EOF > $SERVICE_FILE
[Unit]
Description=Xonotic Dedicated Server
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=$DIR/$XONOTIC_BINARY -dedicated
WorkingDirectory=$DIR
StandardOutput=file:$LOG_DIR/server.log
StandardError=file:$LOG_DIR/error.log
SyslogIdentifier=xonotic
[Install]
WantedBy=multi-user.target
WantedBy=default.target
EOF

# Create log directory
Expand All @@ -84,4 +92,4 @@ PID=$(pgrep -f xonotic-linux64-dedicated)
# Display the server information
echo "[Start Xonotic: complete] PID=$PID"
echo "Access to $IP:$serverPort by using your Xonotic Client"
echo "Hostname: $serverName"
echo "Hostname: $serverName"

0 comments on commit ec2875b

Please sign in to comment.