From 9bc59e83b10bb14bbb7d1741a7d22d41106843bf Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Sat, 27 Aug 2022 14:24:17 +0200 Subject: [PATCH] initial commit --- Dockerfile | 28 +++++++++++++++ README.md | 11 ++++++ docker-compose.yml | 35 +++++++++++++++++++ downloadMods.sh | 61 ++++++++++++++++++++++++++++++++ entrypoint.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 222 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100755 downloadMods.sh create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4b5e239 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM cm2network/steamcmd:latest + +LABEL org.opencontainers.image.source=https://git.kapelle.org/niklas/arma3-docker + +COPY entrypoint.sh /home/steam/entrypoint.sh + +RUN mkdir -p /home/steam/server && \ + chown steam:steam /home/steam/server && \ + bash -c 'mkdir -p /home/steam/volumes/{config,missions,mods,servermods}' && \ + chown steam:steam -R /home/steam/volumes/ + +USER steam + +VOLUME /home/steam/server +VOLUME /home/steam/volumes/config +VOLUME /home/steam/volumes/missions +VOLUME /home/steam/volumes/mods +VOLUME /home/steam/volumes/servermods + +WORKDIR /home/steam/server + +EXPOSE 2302/udp +EXPOSE 2303/udp +EXPOSE 2304/udp +EXPOSE 2305/udp +EXPOSE 2306/udp + +ENTRYPOINT /home/steam/entrypoint.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..6e98fcd --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +Arma 3 server image. + +# Download mods + +Use the `downloadMods.sh` to download mods to a volume. + +# Environment variables + +`STEAM_USER` - Steam username +`STEAM_PASSWORD` - Steam password +`WORKSHOP_COLLECTION` - id of a steam workshop collection. Used to load mods diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7a91dc2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,35 @@ +version: "3" + +services: + arma3: + build: . + image: djeeberjr/arma3 + environment: + STEAM_USER: testo + STEAM_PASSWORD: testo + WORKSHOP_COLLECTION: 1400118996 + volumes: + - arma3_dev_game:/home/steam/server + - arma3_dev_mods:/home/steam/volumes/mods + - arma3_dev_servermods:/home/steam/volumes/servermods + - arma3_dev_config:/home/steam/volumes/config + - arma3_dev_missions:/home/steam/volumes/missions + ports: + - 2302:2302/udp + - 2303:2303/udp + - 2304:2304/udp + - 2305:2305/udp + - 2306:2306/udp + stdin_open: true + tty: true +volumes: + arma3_dev_game: + name: arma3_dev_game + arma3_dev_mods: + name: arma3_dev_mods + arma3_dev_servermods: + name: arma3_dev_servermods + arma3_dev_config: + name: arma3_dev_config + arma3_dev_missions: + name: arma3_dev_missions diff --git a/downloadMods.sh b/downloadMods.sh new file mode 100755 index 0000000..ecd5dca --- /dev/null +++ b/downloadMods.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +ARMA_MOD_VOLUME="arma3_dev_mods" + +# Check if argument is given +if [ -z "$1" ]; then + echo "No argument given. Use workshop id as argument. e.g. 1400118996" + exit 1 +fi + + +PAYLOAD=$(cat < "\$tmpFile" + + echo "Downloading mod \$mod_id" + + until /home/steam/steamcmd/steamcmd.sh +runscript "\$tmpFile"; do echo -e "###\nLets try that again\n###"; done + + echo -e "###\nDownload finished\n###" +done + +# for f in \$(find /home/steam/mount -type f -name '*.pbo' -o -type f -name '*.bisign'); do mv -v "\$f" "\$(echo \$f | tr '[A-Z]' '[a-z]')"; done + +EOF +) + +docker run \ + -it \ + --rm \ + --name=arma3_mods \ + -v "$ARMA_MOD_VOLUME":/home/steam/mount \ + cm2network/steamcmd \ + bash -c "$PAYLOAD" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..b3c350a --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +set -eo pipefail + +VOLUME_HOME="/home/steam/volumes" + +# +# STEAM/INSTALL GAME +# + +# If STEAM_USER or STEAM_PASSWORD is not set +if [ -z "$STEAM_USER" ] || [ -z "$STEAM_PASSWORD" ]; then + echo "STEAM_USER or STEAM_PASSWORD is not set. Its recommended to create a new steam user for the server." + exit 1 +fi + +# Update or install Arma 3 +echo "Updating or installing Arma 3..." + +# https://developer.valvesoftware.com/wiki/SteamCMD +/home/steam/steamcmd/steamcmd.sh +force_install_dir /home/steam/server +login "$STEAM_USER" "$STEAM_PASSWORD" +app_update 233780 +quit + +# +# PREPARE GAME +# + +# Check if config file exists +if [ ! -f "$VOLUME_HOME/config/config.cfg" ]; then + echo "Config file not found, creating..." + # TODO: Create config file + touch "$VOLUME_HOME/config/config.cfg" +fi + +# https://community.bistudio.com/wiki/Arma_3:_Startup_Parameters#Server_Options +SERVER_ARGS="-name server -config=$VOLUME_HOME/config/config.cfg -profiles=$VOLUME_HOME/config/profiles" + +if [ -n "$A3_LIMIT_FPS" ]; then + SERVER_ARGS="${SERVER_ARGS} -limitFPS=${A3_LIMIT_FPS}" +fi + +if [ -n "$A3_PORT" ]; then + SERVER_ARGS="${SERVER_ARGS} -port=${A3_PORT}" +fi + +# +# PREAPRE MODS +# + +MOD_LINK_DIR="/tmp/arma3mods" +mkdir -p "$MOD_LINK_DIR" +rm -f "$MOD_LINK_DIR"/* + +MODS_TO_LOAD="" + +for mod_id in $(curl -s "https://steamcommunity.com/sharedfiles/filedetails/?id=$WORKSHOP_COLLECTION" | grep -E 'id="sharedfile_[0-9]+"' | sed 's/.*id="sharedfile_\([0-9]\+\)".*/\1/') +do + # Check if directory exists + if [ ! -d "$VOLUME_HOME/mods/$mod_id" ]; then + echo "Could not find mod directory for $mod_id" + echo "Try to download it first" + exit 1 + fi + + ln -s "$VOLUME_HOME/mods/$mod_id" "$MOD_LINK_DIR/$mod_id" + MODS_TO_LOAD="${MODS_TO_LOAD}$MOD_LINK_DIR/${mod_id};" +done + +# MODS_TO_LOAD="$VOLUME_HOME/mods/463939057" + +if [ -n "$MODS_TO_LOAD" ]; then + SERVER_ARGS="${SERVER_ARGS} -mod=${MODS_TO_LOAD}" +fi + + +# SERVER_ARGS="${SERVER_ARGS} -serverMod=${SERVER_MODS}" + +# +# RUN GAME +# + + +echo "Starting server with args: " +echo "$SERVER_ARGS" + +# Start the server +echo "Starting the server..." +/home/steam/server/arma3server ${SERVER_ARGS}