From 9317d9ae36ab7a8f8fe8b1800ac5d9bfc83a86e9 Mon Sep 17 00:00:00 2001 From: Seokho Son Date: Mon, 20 May 2024 21:52:06 +0900 Subject: [PATCH] Enable Xonotic fps game deploy script --- scripts/usecases/xonotic/startServer.sh | 56 ++++++++++++++----------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/scripts/usecases/xonotic/startServer.sh b/scripts/usecases/xonotic/startServer.sh index 8f7d54ad2..2c2650184 100644 --- a/scripts/usecases/xonotic/startServer.sh +++ b/scripts/usecases/xonotic/startServer.sh @@ -1,46 +1,56 @@ #!/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 < $SERVICE_FILE [Unit] Description=Xonotic Dedicated Server @@ -48,8 +58,6 @@ After=network.target [Service] Type=simple -User=root -Group=root ExecStart=$DIR/$XONOTIC_BINARY -dedicated WorkingDirectory=$DIR StandardOutput=file:$LOG_DIR/server.log @@ -57,7 +65,7 @@ StandardError=file:$LOG_DIR/error.log SyslogIdentifier=xonotic [Install] -WantedBy=multi-user.target +WantedBy=default.target EOF # Create log directory @@ -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" \ No newline at end of file +echo "Hostname: $serverName"