initial commit

This commit is contained in:
Djeeberjr 2022-08-27 14:24:17 +02:00
commit 9bc59e83b1
5 changed files with 222 additions and 0 deletions

28
Dockerfile Normal file
View File

@ -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

11
README.md Normal file
View File

@ -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

35
docker-compose.yml Normal file
View File

@ -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

61
downloadMods.sh Executable file
View File

@ -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 <<EOF
set -e
WORKSHOP_DIR="/home/steam/Steam/steamapps/workshop/content"
mkdir -p \$WORKSHOP_DIR
rm -rf \$WORKSHOP_DIR/content
ln -s /home/steam/mount "\$WORKSHOP_DIR/107410"
echo -n "Username: "
read username
echo "Perform initial login. Exit after successfull login. To login type login username"
/home/steam/steamcmd/steamcmd.sh +login \$username +quit
tmpFile=$(mktemp)
for mod_id in \$(curl -s "https://steamcommunity.com/sharedfiles/filedetails/?id=$1" | grep -E 'id="sharedfile_[0-9]+"' | sed 's/.*id="sharedfile_\([0-9]\+\)".*/\1/')
do
{
echo "// autogenerated DONT TOUCH";
echo -e "@ShutdownOnFailedCommand 1";
echo -e "@NoPromptForPassword 1"
echo "login \$username";
echo "workshop_download_item 107410 \$mod_id validate";
echo "quit";
} > "\$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"

87
entrypoint.sh Executable file
View File

@ -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}