Skip to content

Instantly share code, notes, and snippets.

@yddlef

yddlef/README.md Secret

Last active October 25, 2023 18:44
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 25 You must be signed in to fork a gist
  • Save yddlef/df54ee1bbca93095a71d75cd15e216eb to your computer and use it in GitHub Desktop.
Save yddlef/df54ee1bbca93095a71d75cd15e216eb to your computer and use it in GitHub Desktop.
Plutonium patch script for the felddy/foundryvtt container.

Plutonium backend support for felddy/foundryvtt

The Docker container can be patched to support Plutonium by setting the CONTAINER_PATCH_URLS environment variable to contain URL the of the plutonium.sh file below.

CONTAINER_PATCH_URLS=https://gist.githubusercontent.com/yddlef/df54ee1bbca93095a71d75cd15e216eb/raw/plutonium-0.8.x.sh

docker-compose usage

Create the following directory structure containing the docker-compose.yml below.

└── foundry
    ├── data
    └── docker-compose.yml

While in the foundry directiory, start up the container with the command: docker-compose up --detach

See the project README for additional configuration details.

version: "3.8"
services:
foundry:
image: felddy/foundryvtt:release
hostname: my_foundry_host
init: true
restart: "unless-stopped"
volumes:
- type: bind
source: ./data
target: /data
environment:
- CONTAINER_CACHE=/data/container_cache
- CONTAINER_PATCH_URLS=
https://gist.githubusercontent.com/yddlef/df54ee1bbca93095a71d75cd15e216eb/raw/plutonium-0.8.x.sh
- FOUNDRY_PASSWORD=<your_password>
- FOUNDRY_USERNAME=<your_username>
- FOUNDRY_ADMIN_KEY=atr0p0s
ports:
- target: "30000"
published: "30000"
protocol: tcp
mode: host
#!/bin/sh
# This patch script is for use with the felddy/foundryvtt Docker container.
# See: https://github.com/felddy/foundryvtt-docker#readme
# Installs the Plutonium module if it is not yet installed, and then patches the
# Foundry server to call the Plutonium backend.
MAIN_JS="${FOUNDRY_HOME}/resources/app/main.mjs"
MODULE_BACKEND_JS="/data/Data/modules/plutonium/server/${FOUNDRY_VERSION:0:3}.x/plutonium-backend.mjs"
MODULE_DIR="/data/Data/modules"
MODULE_DOC_URL="https://wiki.5e.tools/index.php/FoundryTool_Install"
MODULE_URL="https://raw.githubusercontent.com/TheGiddyLimit/plutonium-next/master/plutonium-foundry08.zip"
SUPPORTED_VERSIONS="0.8.6 0.8.7 0.8.8"
WORKDIR=$(mktemp -d)
ZIP_FILE="${WORKDIR}/plutonium.zip"
log "Installing Plutonium module and backend."
log "See: ${MODULE_DOC_URL}"
if [ -z "${SUPPORTED_VERSIONS##*$FOUNDRY_VERSION*}" ] ; then
log "This patch has been tested with Foundry Virtual Tabletop ${FOUNDRY_VERSION}"
else
log_warn "This patch has not been tested with Foundry Virtual Tabletop ${FOUNDRY_VERSION}"
fi
if [ ! -f $MODULE_BACKEND_JS ]; then
log "Downloading Plutonium module."
curl --output "${ZIP_FILE}" "${MODULE_URL}" 2>&1 | tr "\r" "\n"
log "Ensuring module directory exists."
mkdir -p "${MODULE_DIR}"
log "Installing Plutonium module."
unzip -o "${ZIP_FILE}" -d "${MODULE_DIR}"
fi
log "Installing Plutonium backend."
cp "${MODULE_BACKEND_JS}" "${FOUNDRY_HOME}/resources/app/"
log "Patching ${MAIN_JS} to use plutonium-backend."
apk add patch
patch --backup --quiet --batch ${MAIN_JS} << PATCH_FILE
26c26
< init.default({
---
> await init.default({
31c31,32
< })
---
> });
> (await import("./plutonium-backend.mjs")).Plutonium.init();
PATCH_FILE
patch_result=$?
if [ $patch_result = 0 ]; then
log "Plutonium backend patch was applied successfully."
log "Plutonium art and media tools will be enabled."
else
log_error "Plutonium backend patch could not be applied."
log_error "main.js did not contain the expected source lines."
log_warn "Foundry Virtual Tabletop will still operate without the art and media tools enabled."
log_warn "Update this patch file to a version that supports Foundry Virtual Tabletop ${FOUNDRY_VERSION}."
mv "${MAIN_JS}.orig" "${MAIN_JS}"
fi
log "Cleaning up."
rm -r ${WORKDIR}
#!/bin/sh
# This patch script is for use with the felddy/foundryvtt Docker container.
# See: https://github.com/felddy/foundryvtt-docker#readme
# Installs the Plutonium module if it is not yet installed, and then patches the
# Foundry server to call the Plutonium backend.
MAIN_JS="${FOUNDRY_HOME}/resources/app/main.js"
MODULE_BACKEND_JS="/data/Data/modules/plutonium/server/${FOUNDRY_VERSION:0:3}.x/plutonium-backend.js"
MODULE_DIR="/data/Data/modules"
MODULE_URL="https://get.5e.tools/plutonium/plutonium.zip"
MODULE_DOC_URL="https://wiki.5e.tools/index.php/FoundryTool_Install"
NEW_PATCH_SCRIPT_URL="https://gist.githubusercontent.com/yddlef/df54ee1bbca93095a71d75cd15e216eb/raw/plutonium-0.8.x.sh"
SUPPORTED_VERSIONS="0.6.5 0.6.6 0.7.1 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.7.10"
WORKDIR=$(mktemp -d)
ZIP_FILE="${WORKDIR}/plutonium.zip"
log "Installing Plutonium module and backend."
log "See: ${MODULE_DOC_URL}"
if [ "${FOUNDRY_VERSION:0:3}" == "0.8" ]; then
log_warn "A new patch script is available with FoundryVTT 0.8.x support."
log_warn "Please change your patch URL to: ${NEW_PATCH_SCRIPT_URL}"
else
if [ -z "${SUPPORTED_VERSIONS##*$FOUNDRY_VERSION*}" ] ; then
log "This patch has been tested with Foundry Virtual Tabletop ${FOUNDRY_VERSION}"
else
log_warn "This patch has not been tested with Foundry Virtual Tabletop ${FOUNDRY_VERSION}"
fi
if [ ! -f $MODULE_BACKEND_JS ]; then
log "Downloading Plutonium module."
curl --output "${ZIP_FILE}" "${MODULE_URL}" 2>&1 | tr "\r" "\n"
log "Ensuring module directory exists."
mkdir -p "${MODULE_DIR}"
log "Installing Plutonium module."
unzip -o "${ZIP_FILE}" -d "${MODULE_DIR}"
fi
log "Installing Plutonium backend."
cp "${MODULE_BACKEND_JS}" "${FOUNDRY_HOME}/resources/app/"
log "Patching main.js to use plutonium-backend."
sed --file=- --in-place=.orig ${MAIN_JS} << SED_SCRIPT
s/^\(require(\"init\").*\);\
/\1.then(() => {require(\"plutonium-backend\").init();});/g\
w plutonium_patchlog.txt
SED_SCRIPT
if [ -s plutonium_patchlog.txt ]; then
log "Plutonium backend patch was applied successfully."
log "Plutonium art and media tools will be enabled."
else
log_error "Plutonium backend patch could not be applied."
log_error "main.js did not contain the expected source lines."
log_warn "Foundry Virtual Tabletop will still operate without the art and media tools enabled."
log_warn "Update this patch file to a version that supports Foundry Virtual Tabletop ${FOUNDRY_VERSION}."
fi
log "Cleaning up."
rm -r ${WORKDIR}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment