Skip to content

Instantly share code, notes, and snippets.

@felddy
Last active August 16, 2024 01:36
Show Gist options
  • Save felddy/a02d66c3817f8223652d96febe580153 to your computer and use it in GitHub Desktop.
Save felddy/a02d66c3817f8223652d96febe580153 to your computer and use it in GitHub Desktop.
A container patch for foundryvtt-docker to check module compatibility.
#!/bin/sh
# shellcheck shell=dash
# This script checks the compatibility of all modules in the modules directory with the specified FoundryVTT version.
# Constants
MODULES_DIR="/data/Data/modules"
TARGET_VERSION="12.331"
TARGET_VERSION_MAJOR=$(echo "$TARGET_VERSION" | cut -d. -f1)
log "Checking module compatibility with FoundryVTT version $TARGET_VERSION"
# Ensure the semver package is installed
if ! command -v semver >/dev/null 2>&1; then
log "Installing semver package"
npm install --global --no-update-notifier semver >/dev/null
fi
check_compatibility() {
local latest_title latest_version verified_version maximum_version minimum_version
manifest_url="$1"
latest_module_json=$(curl -sL "$manifest_url")
if [ -n "$latest_module_json" ]; then
parsed_vars=$(echo "$latest_module_json" | jq -r '
@sh "latest_title=\(.title)",
@sh "latest_version=\(.version)",
@sh "verified_version=\(.compatibility.verified)",
@sh "maximum_version=\(.compatibility.maximum // "")",
@sh "minimum_version=\(.compatibility.minimum // "")"'
)
eval "$parsed_vars"
if [ -n "$maximum_version" ] && ! semver --coerce --range "<=$maximum_version" "$TARGET_VERSION" >/dev/null; then
log "❌ $latest_title ($latest_version), UNSUPPORTED: maximum version: $maximum_version"
elif [ -n "$minimum_version" ] && ! semver --coerce --range ">=$minimum_version" "$TARGET_VERSION" >/dev/null; then
log "❌ $latest_title ($latest_version), UNSUPPORTED: minimum version: $minimum_version"
elif semver --coerce --range "$verified_version" "$TARGET_VERSION" >/dev/null; then
log "✅ $latest_title ($latest_version), Verified: $verified_version"
elif semver --coerce --range "$TARGET_VERSION_MAJOR" "$verified_version" >/dev/null; then
log "⚠️ $latest_title ($latest_version), Compatibility risk: last verified for version $verified_version"
else
log "🟠 $latest_title ($latest_version), Compatibility risk: last verified for version $verified_version"
fi
else
log_error "Failed to fetch manifest from $manifest_url"
fi
}
for module_dir in "$MODULES_DIR"/*; do
if [ -d "$module_dir" ]; then
module_json="$module_dir/module.json"
if [ -f "$module_json" ]; then
manifest_url=$(jq -r '.manifest' "$module_json")
if [ -n "$manifest_url" ]; then
check_compatibility "$manifest_url" &
else
log_warn "Manifest URL not found in $module_json"
fi
fi
fi
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment