CM2Walki / Squad

Dockerfile for automated build of a Squad gameserver: https://hub.docker.com/r/cm2network/squad/
https://CM2.Network
MIT License
36 stars 20 forks source link

Add Mod Support #22

Closed TheDelta closed 2 years ago

TheDelta commented 2 years ago

Would be great if the image could add mod support. I don't have time right now for the PR, but the current way I do is this:

#!/bin/sh

APPID=403240
WORKSHOPID=393380
MODPATH="${STEAMAPPDIR}/SquadGame/Plugins/Mods"

MODS=(2818478721)

# Ensure game is up-2-date
"${STEAMCMDDIR}/steamcmd.sh" +force_install_dir $STEAMAPPDIR +login anonymous +app_update $APPID validate +quit

# Install each mod
for MODID in ${MODS[@]}; do
    echo "Installing mod ${MODID}"
    "${STEAMCMDDIR}/steamcmd.sh" +force_install_dir $STEAMAPPDIR +login anonymous +workshop_download_item $WORKSHOPID $MODID +quit

    # Remove previous installed mod content from server
    rm -r "${MODPATH}/${MODID}" 2>/dev/null

    # Copy mod content
    cp -R "${STEAMAPPDIR}/steamapps/workshop/content/${WORKSHOPID}/${MODID}" "${MODPATH}/${MODID}" 2>/dev/null
done

(based on https://squad.fandom.com/wiki/Uploading_a_mod_to_a_dedicated_server)

Would be great to have this built into the init script and expose an env var MODS to enter specific mod ids.

CM2Walki commented 2 years ago

I like it. I'll see if I have time on the weekend to make it happen.

TheDelta commented 2 years ago

One thing to keep in mind: If you want to remove mods, etc. you must manually delete it with the script above.

So it most likely makes sense to remove all mods on start with this line before the for loop:

# list all folders / files; filter out non numeric items; remove the items
ls $MODPATH | grep -P "\d+" | xargs -d"\n" rm -R  2>/dev/null

Regex is needed, because Squad Devs put also their own mods there, like CanadianArmedForces. It should be save, because I doubt the devs will name their mod numeric only, because that's reserved for workshop items.

This would also make the "Remove previous installed mod content from server"-line in the for loop obsolete.

Also eventually the cp line could be replaced with a link to save storage. I did not tested this. (the linked doc was more windows specific)

TheDelta commented 2 years ago

@CM2Walki will this happen or should I work on a PR? :)

CM2Walki commented 2 years ago

Unfortunately, I haven't had time to look into it. So if you want to take care of it feel free to do so :).