Skip to content

Commit

Permalink
Feature/add user mod download (#226)
Browse files Browse the repository at this point in the history
* feat: Initial mod download from URL
  • Loading branch information
vinanrra authored Dec 13, 2023
1 parent 6ec9bc7 commit 3fe87de
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 7 deletions.
9 changes: 2 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ STOPSIGNAL SIGTERM

####Labels####
LABEL maintainer="vinanrra"
LABEL build_version="version: 0.6.2"
LABEL build_version="version: 0.7.0"

####Environments ####
ENV TimeZone=Europe/Madrid HOME=/home/sdtdserver LANG=en_US.utf8 TERM=xterm DEBIAN_FRONTEND=noninteractive
Expand All @@ -25,6 +25,7 @@ RUN dpkg --add-architecture i386 && \
bzip2 \
gzip \
unzip \
unrar \
bsdmainutils \
python3 \
util-linux \
Expand Down Expand Up @@ -58,12 +59,6 @@ RUN curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh; \
./nsolid_setup_deb.sh 21; \
apt-get install nodejs -y

# Install NodeJS
RUN curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh \
chmod 500 nsolid_setup_deb.sh \
./nsolid_setup_deb.sh 21 \
apt-get install nodejs -y

# Install gamedig
RUN npm install -g gamedig

Expand Down
16 changes: 16 additions & 0 deletions docs/mods_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ Remember that some mods can't be installed with others, if you have problems wit
- [War of the Walkers Mod](https://community.7daystodie.com/topic/4098-war-of-the-walkers-mod/) (Planned)
- [Age of Oblivion](https://community.7daystodie.com/topic/23943-age-of-oblivion-alpha-401-a20/) (Planned)

## Automatic user mods

⚠️ **This only support zip and rar files**
⚠️ **If you remove an URL, you will need to MANUALLY remove the folder at the mods folder**

You can use the following docker variable `MODS_URLS`, where you can place the URLs of the mods and the script will automatically download, uncompress, install and remove leftovers, here it's an example:
Place the URLs and separate each one with `,`.

**Example:**
`MODS_URLS="URL1,URL2"`

**Real world usage:**
`MODS_URLS="https://github.com/ErrorNull0/enZombies/archive/refs/heads/main.zip,https://github.com/ErrorNull0/enZombiesSnufkinAddon/archive/refs/heads/main.zip"`

If something fails you will see a message at the logs, open a [github ticket](https://github.com/vinanrra/Docker-7DaysToDie/issues) if a mod isn't automatically installing and I will check it.

## Manual Mods

Just drop the mods inside the Mods folder in `/path/to/ServerFiles/Mods`, restart the container and the server will automatically load them.
6 changes: 6 additions & 0 deletions docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
| :---: | --- | :---: |
| `UPDATE_MODS=NO` | Allow mods to be update before server start must be used with each mod XXX_UPDATE=YES **optional** | YES, NO |

### Provided user mods

| Parameter | Function | Values |
| :---: | --- | :---: |
| `MODS_URLS=""` | Allow mods to be installed from URL, support zip and rar **optional** | "URL1,URL2" |

### Overhaul mods

#### Undead Legacy
Expand Down
2 changes: 2 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ docker run -d \
-e VERSION=stable \
-e TEST_ALERT=NO \
-e UPDATE_MODS=NO \
-e - MODS_URLS="" \
-e ALLOC_FIXES=NO \
-e ALLOC_FIXES_UPDATE=NO \
-e UNDEAD_LEGACY=NO \
Expand Down Expand Up @@ -65,6 +66,7 @@ services:
- TimeZone=Europe/Madrid # Optional - Change Timezone
- TEST_ALERT=NO # Optional - Send a test alert
- UPDATE_MODS=NO # Optional - This will allow mods to be update on start, each mod also need to have XXXX_UPDATE=YES to update on start
- MODS_URLS="" # Optional - Mods urls to install, must be ZIP or RAR.
- ALLOC_FIXES=NO # Optional - Install ALLOC FIXES
- ALLOC_FIXES_UPDATE # Optional - Update Allocs Fixes before server start
- UNDEAD_LEGACY=NO # Optional - Install Undead Legacy mod, if DARKNESS_FALLS it's enable will not install anything
Expand Down
67 changes: 67 additions & 0 deletions scripts/Mods/mods_downloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

# Set the MODS_FOLDER
MODS_FOLDER="/home/sdtdserver/serverfiles/Mods"

# Create the Mods folder if it doesn't exist
mkdir -p "$MODS_FOLDER"
mkdir -p "$MODS_FOLDER/tmp"

# Remove quotes and potential leading/trailing whitespace from MODS_URLS
MODS_URLS=$(echo "$MODS_URLS" | sed -e 's/^ *//;s/ *$//' | tr -d '"')

# Split the comma-separated URLs into an array
IFS=', ' read -r -a urls <<< "$MODS_URLS"

# Iterate over the URLs and download/extract/copy each file
for url in "${urls[@]}"; do
# Extract filename from URL
filename=$(basename "$url")

# Download the file
echo "INFO: Downloading $filename from $url..."
curl "$url" -SsL -o "${filename}"

# Check if the download was successful
if [ $? -eq 0 ]; then
echo "INFO: Download successful: $filename"

# Check the file extension and extract accordingly
if [[ $filename == *.zip ]]; then
echo "INFO: Extracting $filename using unzip..."
unzip -q "$filename" -d "$MODS_FOLDER/tmp/$(basename "$filename" .zip)"
rm "$filename" # Remove the original zip file
elif [[ $filename == *.rar ]]; then
echo "INFO: Extracting $filename using unrar..."
unrar x -o+ "$filename" "$MODS_FOLDER"
rm "$filename" # Remove the original rar file
else
echo "WARNING: Unsupported file type. No extraction performed."
fi

# Find the folder containing Modinfo.xml case-insensitive
mod_folder=$(find "$MODS_FOLDER/tmp" -type f -iname "Modinfo.xml" -exec dirname {} \;)
# Get the folder name
mod_folder_name=$(basename "$mod_folder")

if [ -n "$mod_folder" ]; then
# Remove the old mod version, check if not empty to avoid removing Mods folder
if [ -n "$mod_folder_name" ]; then
rm -rf $MODS_FOLDER/"$mod_folder_name"
fi
# Move the folder to MODS_FOLDER
mv "$mod_folder" "$MODS_FOLDER"
echo "INFO: Mod $mod_folder_name folder moved to $MODS_FOLDER"
else
echo "ERROR: Modinfo.xml not found in the extracted files."
echo "INFO: Aborting $filename from $url"
fi
# Remove the extracted files
rm -rf "$MODS_FOLDER/tmp/$filename"
else
echo "ERROR: Failed to download $filename from $url"
fi
done

rm -rf "$MODS_FOLDER/tmp"
echo "All downloads, extractions, and folder movements completed."
4 changes: 4 additions & 0 deletions scripts/Mods/mods_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ if [ "${BEPINEX,,}" == 'yes' ] && [ "${UNDEAD_LEGACY,,}" == 'no' ]
then
source $scriptsDir/Mods/bepinex.sh
fi

if [ "$MODS_URLS" != "" ]; then
source $scriptsDir/Mods/mods_downloader.sh
fi
5 changes: 5 additions & 0 deletions scripts/Mods/mods_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ if [ "${BEPINEX,,}" == 'yes' ] && [ "${BEPINEX_UPDATE,,}" == 'yes' ] && [ "${UND
source $scriptsDir/Mods/bepinex.sh
fi

if [ "$MODS_URLS" != "" ]; then
echo "INFO: Updating custom mods from URLs"
source $scriptsDir/Mods/mods_downloader.sh
fi

echo "[INFO] Updating/Installing mods finished"

0 comments on commit 3fe87de

Please sign in to comment.