From 3fe87de753ca81142bf2f541011bdf87879f6b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Fern=C3=A1ndez=20Guerra?= Date: Wed, 13 Dec 2023 15:41:17 +0100 Subject: [PATCH] Feature/add user mod download (#226) * feat: Initial mod download from URL --- Dockerfile | 9 +---- docs/mods_support.md | 16 ++++++++ docs/parameters.md | 6 +++ docs/usage.md | 2 + scripts/Mods/mods_downloader.sh | 67 +++++++++++++++++++++++++++++++++ scripts/Mods/mods_install.sh | 4 ++ scripts/Mods/mods_update.sh | 5 +++ 7 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 scripts/Mods/mods_downloader.sh diff --git a/Dockerfile b/Dockerfile index 198e162..67fc28b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -25,6 +25,7 @@ RUN dpkg --add-architecture i386 && \ bzip2 \ gzip \ unzip \ + unrar \ bsdmainutils \ python3 \ util-linux \ @@ -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 diff --git a/docs/mods_support.md b/docs/mods_support.md index a197bc1..098ebd7 100644 --- a/docs/mods_support.md +++ b/docs/mods_support.md @@ -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. diff --git a/docs/parameters.md b/docs/parameters.md index 989b4da..7ede5d8 100644 --- a/docs/parameters.md +++ b/docs/parameters.md @@ -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 diff --git a/docs/usage.md b/docs/usage.md index ce031cc..85c9fc3 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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 \ @@ -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 diff --git a/scripts/Mods/mods_downloader.sh b/scripts/Mods/mods_downloader.sh new file mode 100644 index 0000000..f93ff1f --- /dev/null +++ b/scripts/Mods/mods_downloader.sh @@ -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." diff --git a/scripts/Mods/mods_install.sh b/scripts/Mods/mods_install.sh index 2232b6c..185d5ea 100644 --- a/scripts/Mods/mods_install.sh +++ b/scripts/Mods/mods_install.sh @@ -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 diff --git a/scripts/Mods/mods_update.sh b/scripts/Mods/mods_update.sh index 32f842d..c5ae74b 100644 --- a/scripts/Mods/mods_update.sh +++ b/scripts/Mods/mods_update.sh @@ -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"