From 516ee4778d279e107b65814d25c5c2ec38621c22 Mon Sep 17 00:00:00 2001 From: David Katz Date: Sat, 6 May 2023 14:06:30 -0700 Subject: [PATCH] Improve file detection when looking up older pack versions --- .../minecraft/java/curseforge/egg-curse-forge-generic.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game_eggs/minecraft/java/curseforge/egg-curse-forge-generic.json b/game_eggs/minecraft/java/curseforge/egg-curse-forge-generic.json index 22cb0625..85d44a74 100644 --- a/game_eggs/minecraft/java/curseforge/egg-curse-forge-generic.json +++ b/game_eggs/minecraft/java/curseforge/egg-curse-forge-generic.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": null }, - "exported_at": "2023-05-06T12:13:41-07:00", + "exported_at": "2023-05-06T14:04:53-07:00", "name": "CurseForge Generic", "author": "contact@chromozone.dev", "description": "A generic egg for a CurseForge modpack.", @@ -29,7 +29,7 @@ }, "scripts": { "installation": { - "script": "#!\/bin\/bash\r\n# shellcheck disable=SC2155\r\n#\r\n# CurseForge Installation Script\r\n#\r\n# Server Files: \/mnt\/server\r\n\r\n: \"${SERVER_DIR:=\/mnt\/server}\"\r\n: \"${PROJECT_ID:=}\"\r\n: \"${VERSION_ID:=}\"\r\n: \"${API_KEY:=}\"\r\n\r\nif [[ ! -d $SERVER_DIR ]]; then\r\n mkdir -p \"$SERVER_DIR\"\r\nfi\r\n\r\nif ! cd \"$SERVER_DIR\"; then\r\n echo -e \"Failed to change directory to ${SERVER_DIR}\"\r\n exit 1\r\nfi\r\n\r\nfunction install_required {\r\n echo -e \"Installing required packages...\"\r\n echo -e \"\\tRunning apt update\"\r\n apt update > \/dev\/null 2>&1 || { echo \"apt update failed!\"; exit 1; }\r\n echo -e \"\\tRunning apt install\"\r\n apt install -y wget jq unzip > \/dev\/null 2>&1 || { echo \"apt install failed!\"; exit 1; }\r\n}\r\n\r\nCURSEFORGE_API_URL=\"https:\/\/api.curseforge.com\/v1\/mods\/\"\r\nCURSEFORGE_API_HEADERS=(\"--header=Accept: application\/json\" \"--header=x-api-key: ${API_KEY}\")\r\n\r\nfunction get_download {\r\n echo -e \"Retrieving CurseForge project information...\"\r\n local PROJECT_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\" -O -)\r\n local PROJECT_TITLE=$(echo \"$PROJECT_DATA\" | jq -r '.data.name \/\/ empty')\r\n\r\n if [[ -z \"${PROJECT_DATA}\" ]]; then\r\n echo -e \"\\tERROR: Failed to retrieve project data for project id '${PROJECT_ID}'\"\r\n exit 1\r\n fi\r\n\r\n local IS_SERVER_PACK=false\r\n\r\n if [[ -z \"${VERSION_ID}\" || \"${VERSION_ID}\" == \"latest\" ]]; then\r\n echo -e \"\\tNo version ID specified, using latest version\"\r\n VERSION_ID=$(echo \"$PROJECT_DATA\" | jq -r '.data.mainFileId \/\/ empty')\r\n\r\n local VERSION_SERVER_PACK=\"$(echo -e \"${PROJECT_DATA}\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[] | select(.id|tostring==$VERSION_ID) | .isServerPack')\"\r\n local VERSION_SERVER_ID=\"$(echo -e \"${PROJECT_DATA}\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[] | select(.id|tostring==$VERSION_ID) | .serverPackFileId')\"\r\n\r\n if [[ \"${VERSION_SERVER_PACK}\" == \"false\" && -n \"${VERSION_SERVER_ID}\" ]]; then\r\n echo -e \"\\tFound server pack version id '${VERSION_SERVER_ID}'\"\r\n VERSION_ID=$VERSION_SERVER_ID\r\n IS_SERVER_PACK=true\r\n elif [[ \"${VERSION_SERVER_PACK}\" == \"true\" ]]; then\r\n IS_SERVER_PACK=true\r\n fi\r\n else\r\n echo -e \"\\tChecking if provided version id '${VERSION_ID}' exists\"\r\n\r\n local VERSION_SERVER_PACK=\"$(echo -e \"${PROJECT_DATA}\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[]? | select(.serverPackFileId|tostring==$VERSION_ID) | .serverPackFileId')\"\r\n local VERSION_SERVER_ID;\r\n if [[ -n \"${VERSION_SERVER_PACK}\" ]]; then\r\n VERSION_ID=$VERSION_SERVER_PACK\r\n IS_SERVER_PACK=true\r\n elif [[ $(echo \"$PROJECT_DATA\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[]? | select(.id|tostring == $VERSION_ID) | .id') == \"${VERSION_ID}\" ]]; then\r\n VERSION_SERVER_PACK=\"$(echo -e \"${PROJECT_DATA}\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[] | select(.id|tostring==$VERSION_ID) | .isServerPack')\"\r\n VERSION_SERVER_ID=\"$(echo -e \"${PROJECT_DATA}\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[] | select(.id|tostring==$VERSION_ID) | .serverPackFileId')\"\r\n\r\n if [[ \"${VERSION_SERVER_PACK}\" == \"false\" && -n \"${VERSION_SERVER_ID}\" ]]; then\r\n echo -e \"\\tFound server pack version id '${VERSION_SERVER_ID}'\"\r\n VERSION_ID=$VERSION_SERVER_ID\r\n IS_SERVER_PACK=true\r\n elif [[ \"${VERSION_SERVER_PACK}\" == \"true\" ]]; then\r\n IS_SERVER_PACK=true\r\n fi\r\n else\r\n echo -e \"\\tERROR: Version id '${VERSION_ID}' not found for project '${PROJECT_TITLE}'\"\r\n exit 1\r\n fi\r\n fi\r\n\r\n # Check if version id is unset or empty string\r\n if [[ -z \"${VERSION_ID}\" ]]; then\r\n echo -e \"\\tERROR: No version id found for project '${PROJECT_TITLE}'\"\r\n exit 1\r\n fi\r\n\r\n if [[ \"${IS_SERVER_PACK}\" == \"false\" ]]; then\r\n echo -e \"\\tWARNING: Version id '${VERSION_ID}' is not a server pack, attempting to use client files\"\r\n fi\r\n\r\n # get json data to work with\r\n echo -e \"\\tRetrieving version information for '${VERSION_ID}'\"\r\n local JSON_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\/files\/${VERSION_ID}\/download-url\" -O -)\r\n\r\n if [[ -z \"${JSON_DATA}\" ]]; then\r\n echo -e \"\\tERROR: Failed to retrieve version data for version id '${VERSION_ID}'\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tParsing CurseForge pack download url\"\r\n\r\n local DOWNLOAD_URL=$(echo -e \"$JSON_DATA\" | jq -r '.data \/\/ empty')\r\n if [[ -z \"${DOWNLOAD_URL}\" ]]; then\r\n echo -e \"\\tERROR: No download url found for version ${VERSION_ID}\"\r\n exit 1\r\n fi\r\n\r\n # download modpack files\r\n echo -e \"\\tDownloading ${DOWNLOAD_URL}\"\r\n if ! wget -q \"${DOWNLOAD_URL}\" -O server.zip; then\r\n echo -e \"Download failed!\"\r\n exit 1\r\n fi\r\n}\r\n\r\nfunction get_loader {\r\n echo -e \"Retrieving loader information...\"\r\n\r\n local PROJECT_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\" -O -)\r\n if [[ -z \"${PROJECT_DATA}\" ]]; then\r\n echo -e \"\\tERROR: Failed to retrieve project data for project id '${PROJECT_ID}'\"\r\n exit 1\r\n fi\r\n\r\n local CLIENT_VERSION_ID;\r\n if [[ $(echo \"$PROJECT_DATA\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[]? | select(.id|tostring == $VERSION_ID) | .id') != \"${VERSION_ID}\" ]]; then\r\n # Check if the provided version id is a server pack\r\n VERSION_CLIENT_PACK=\"$(echo -e \"${PROJECT_DATA}\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[]? | select(.serverPackFileId|tostring==$VERSION_ID) | .id')\"\r\n\r\n if [[ -n \"${VERSION_CLIENT_PACK}\" ]]; then\r\n CLIENT_VERSION_ID=$VERSION_CLIENT_PACK\r\n else\r\n echo -e \"\\tERROR: Version id '${VERSION_ID}' not found for project '${PROJECT_TITLE}'\"\r\n exit 1\r\n fi\r\n else\r\n CLIENT_VERSION_ID=$VERSION_ID\r\n fi\r\n\r\n echo -e \"\\tRetrieving version information for '${CLIENT_VERSION_ID}'\"\r\n local JSON_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\/files\/${CLIENT_VERSION_ID}\/download-url\" -O -)\r\n\r\n echo -e \"\\tParsing CurseForge pack download url\"\r\n\r\n local DOWNLOAD_URL=$(echo -e \"$JSON_DATA\" | jq -r '.data \/\/ empty')\r\n\r\n if [[ -z \"${DOWNLOAD_URL}\" ]]; then\r\n echo -e \"\\tERROR: No download url found for version ${CLIENT_VERSION_ID}\"\r\n exit 1\r\n fi\r\n\r\n # download modpack files\r\n echo -e \"\\tDownloading ${DOWNLOAD_URL}\"\r\n wget -q \"${DOWNLOAD_URL}\" -O client.zip\r\n\r\n echo -e \"\\tUnpacking client manifest\"\r\n unzip -jo client.zip manifest.json -d \"${SERVER_DIR}\"\r\n mv \"${SERVER_DIR}\/manifest.json\" \"${SERVER_DIR}\/client.manifest.json\" # rename to avoid conflicts with main manifest\r\n rm -rf client.zip\r\n\r\n echo -e \"\\tParsing client manifest\"\r\n local MANIFEST=\"${SERVER_DIR}\/client.manifest.json\"\r\n\r\n LOADER_ID=$(jq -r '.minecraft.modLoaders[]? | select(.primary == true) | .id' \"${MANIFEST}\")\r\n LOADER_NAME=$(echo \"${LOADER_ID}\" | cut -d'-' -f1)\r\n LOADER_VERSION=$(echo \"${LOADER_ID}\" | cut -d'-' -f2)\r\n\r\n if [[ -z \"${LOADER_NAME}\" || -z \"${LOADER_VERSION}\" ]]; then\r\n echo -e \"\\tERROR: No loader found in client manifest!\"\r\n exit 1\r\n fi\r\n\r\n MINECRAFT_VERSION=$(jq -r '.minecraft.version \/\/ empty' \"${MANIFEST}\")\r\n\r\n if [[ -z \"${MINECRAFT_VERSION}\" ]]; then\r\n echo -e \"\\tERROR: No minecraft version found in client manifest!\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tFound loader ${LOADER_NAME} ${LOADER_VERSION} for Minecraft ${MINECRAFT_VERSION}\"\r\n}\r\n\r\nfunction unzip-strip() (\r\n set -u\r\n\r\n local archive=$1\r\n local destdir=${2:-}\r\n shift; shift || :\r\n echo -e \"\\tUnpacking ${archive} to ${destdir}\"\r\n\r\n echo -e \"\\tCreating temporary directory\"\r\n local tmpdir=\/mnt\/server\/tmp\r\n if ! mkdir -p \"${tmpdir}\"; then\r\n echo -e \"\\tERROR: mkdir failed to create temporary directory\"\r\n return 1\r\n fi\r\n\r\n trap 'rm -rf -- \"$tmpdir\"' EXIT\r\n\r\n echo -e \"\\tUnpacking archive\"\r\n\r\n if ! unzip -q \"$archive\" -d \"$tmpdir\"; then\r\n echo -e \"\\tERROR: unzip failed to unpack archive\"\r\n return 1\r\n fi\r\n\r\n echo -e \"\\tSetting glob settings\"\r\n\r\n shopt -s dotglob\r\n\r\n echo -e \"\\tCleaning up directory structure\"\r\n\r\n local files=(\"$tmpdir\"\/*) name i=1\r\n\r\n if (( ${#files[@]} == 1 )) && [[ -d \"${files[0]}\" ]]; then\r\n name=$(basename \"${files[0]}\")\r\n files=(\"$tmpdir\"\/*\/*)\r\n else\r\n name=$(basename \"$archive\"); name=${archive%.*}\r\n files=(\"$tmpdir\"\/*)\r\n fi\r\n\r\n if [[ -z \"$destdir\" ]]; then\r\n destdir=.\/\"$name\"\r\n fi\r\n\r\n while [[ -f \"$destdir\" ]]; do\r\n destdir=${destdir}-$((i++));\r\n done\r\n\r\n echo -e \"\\tCopying files to ${destdir}\"\r\n\r\n mkdir -p \"$destdir\"\r\n cp -ar \"$@\" -t \"$destdir\" -- \"${files[@]}\"\r\n rm -rf \"$tmpdir\"\r\n)\r\n\r\nfunction unpack_zip {\r\n echo -e \"Unpacking server files...\"\r\n unzip-strip server.zip \"${SERVER_DIR}\"\r\n rm -rf server.zip\r\n}\r\n\r\nfunction json_download_mods {\r\n echo \"Downloading mods...\"\r\n\r\n local MANIFEST=\"${SERVER_DIR}\/manifest.json\"\r\n jq -c '.files[]? | select(.required == true) | {project: .projectID, file: .fileID}' \"${MANIFEST}\" | while read -r mod; do\r\n local MOD_PROJECT_ID=$(echo \"${mod}\" | jq -r '.project \/\/ empty')\r\n local MOD_FILE_ID=$(echo \"${mod}\" | jq -r '.file \/\/ empty')\r\n\r\n if [[ -z \"${MOD_PROJECT_ID}\" || -z \"${MOD_FILE_ID}\" ]]; then\r\n echo -e \"\\tERROR: Failed to parse project id or file id for mod '${mod}'\"\r\n exit 1\r\n fi\r\n\r\n local FILE_URL=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${MOD_PROJECT_ID}\/files\/${MOD_FILE_ID}\/download-url\" -O - | jq -r '.data \/\/ empty')\r\n\r\n if [[ -z \"${FILE_URL}\" ]]; then\r\n echo -e \"\\tERROR: No download url found for mod ${MOD_PROJECT_ID} ${MOD_FILE_ID}\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tDownloading ${FILE_URL}\"\r\n\r\n if ! wget -q \"${FILE_URL}\" -P \"${SERVER_DIR}\/mods\"; then\r\n echo -e \"\\tERROR: Failed to download mod ${MOD_PROJECT_ID} ${MOD_FILE_ID}\"\r\n exit 1\r\n fi\r\n done\r\n}\r\n\r\nfunction json_download_overrides {\r\n echo \"Copying overrides...\"\r\n if [[ -d \"${SERVER_DIR}\/overrides\" ]]; then\r\n cp -r \"${SERVER_DIR}\/overrides\/\"* \"${SERVER_DIR}\"\r\n rm -r \"${SERVER_DIR}\/overrides\"\r\n fi\r\n}\r\n\r\nFORGE_INSTALLER_URL=\"https:\/\/maven.minecraftforge.net\/net\/minecraftforge\/forge\/\"\r\n\r\nfunction json_download_forge {\r\n echo \"Downloading Forge...\"\r\n\r\n local MC_VERSION=$MINECRAFT_VERSION\r\n local FORGE_VERSION=$LOADER_VERSION\r\n\r\n FORGE_VERSION=\"${MC_VERSION}-${FORGE_VERSION}\"\r\n if [[ \"${MC_VERSION}\" == \"1.7.10\" || \"${MC_VERSION}\" == \"1.8.9\" ]]; then\r\n FORGE_VERSION=\"${FORGE_VERSION}-${MC_VERSION}\"\r\n fi\r\n\r\n local FORGE_JAR=\"forge-${FORGE_VERSION}.jar\"\r\n if [[ \"${MC_VERSION}\" == \"1.7.10\" ]]; then\r\n FORGE_JAR=\"forge-${FORGE_VERSION}-universal.jar\"\r\n fi\r\n\r\n local FORGE_URL=\"${FORGE_INSTALLER_URL}${FORGE_VERSION}\/forge-${FORGE_VERSION}\"\r\n\r\n echo -e \"\\tUsing Forge ${FORGE_VERSION} from ${FORGE_URL}\"\r\n\r\n local FORGE_INSTALLER=\"${FORGE_URL}-installer.jar\"\r\n echo -e \"\\tDownloading Forge Installer ${FORGE_VERSION} from ${FORGE_INSTALLER}\"\r\n\r\n if ! wget -q -O forge-installer.jar \"${FORGE_INSTALLER}\"; then\r\n echo -e \"\\tERROR: Failed to download Forge Installer ${FORGE_VERSION}\"\r\n exit 1\r\n fi\r\n\r\n # Remove old Forge files so we can safely update\r\n rm -rf libraries\/net\/minecraftforge\/forge\/\r\n rm -f unix_args.txt\r\n\r\n echo -e \"\\tInstalling Forge Server ${FORGE_VERSION}\"\r\n if ! java -jar forge-installer.jar --installServer > \/dev\/null 2>&1; then\r\n echo -e \"\\tERROR: Failed to install Forge Server ${FORGE_VERSION}\"\r\n exit 1\r\n fi\r\n\r\n if [[ $MC_VERSION =~ ^1\\.(17|18|19|20|21|22|23) || $FORGE_VERSION =~ ^1\\.(17|18|19|20|21|22|23) ]]; then\r\n echo -e \"\\tDetected Forge 1.17 or newer version. Setting up Forge Unix arguments\"\r\n ln -sf libraries\/net\/minecraftforge\/forge\/*\/unix_args.txt unix_args.txt\r\n else\r\n mv \"$FORGE_JAR\" forge-server-launch.jar\r\n echo \"forge-server-launch.jar\" > \".serverjar\"\r\n fi\r\n\r\n rm -f forge-installer.jar\r\n}\r\n\r\nFABRIC_INSTALLER_URL=\"https:\/\/meta.fabricmc.net\/v2\/versions\/installer\"\r\n\r\nfunction json_download_fabric {\r\n echo \"Downloading Fabric...\"\r\n\r\n local MC_VERSION=$MINECRAFT_VERSION\r\n local FABRIC_VERSION=$LOADER_VERSION\r\n\r\n local INSTALLER_JSON=$(wget -q -O - ${FABRIC_INSTALLER_URL} )\r\n local INSTALLER_VERSION=$(echo \"$INSTALLER_JSON\" | jq -r '.[0].version \/\/ empty')\r\n local INSTALLER_URL=$(echo \"$INSTALLER_JSON\" | jq -r '.[0].url \/\/ empty')\r\n\r\n if [[ -z \"${INSTALLER_VERSION}\" ]]; then\r\n echo -e \"\\tERROR: No Fabric installer version found\"\r\n exit 1\r\n fi\r\n\r\n if [[ -z \"${INSTALLER_URL}\" ]]; then\r\n echo -e \"\\tERROR: No Fabric installer url found\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tDownloading Fabric Installer ${MC_VERSION}-${FABRIC_VERSION} (${INSTALLER_VERSION}) from ${INSTALLER_URL}\"\r\n\r\n if ! wget -q -O fabric-installer.jar \"${INSTALLER_URL}\"; then\r\n echo -e \"\\tERROR: Failed to download Fabric Installer ${MC_VERSION}-${FABRIC_VERSION} (${INSTALLER_VERSION})\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tInstalling Fabric Server ${MC_VERSION}-${FABRIC_VERSION} (${INSTALLER_VERSION})\"\r\n if ! java -jar fabric-installer.jar server -mcversion \"${MC_VERSION}\" -loader \"${FABRIC_VERSION}\" -downloadMinecraft; then\r\n echo -e \"\\tERROR: Failed to install Fabric Server ${MC_VERSION}-${FABRIC_VERSION} (${INSTALLER_VERSION})\"\r\n exit 1\r\n fi\r\n\r\n echo \"fabric-server-launch.jar\" > \".serverjar\"\r\n\r\n rm -f fabric-installer.jar\r\n}\r\n\r\nQUILT_INSTALLER_URL=\"https:\/\/meta.quiltmc.org\/v3\/versions\/installer\"\r\n\r\nfunction json_download_quilt {\r\n echo \"Downloading Quilt...\"\r\n\r\n local MC_VERSION=$MINECRAFT_VERSION\r\n local QUILT_VERSION=$LOADER_VERSION\r\n\r\n local INSTALLER_JSON=$(wget -q -O - ${QUILT_INSTALLER_URL} )\r\n local INSTALLER_VERSION=$(echo \"$INSTALLER_JSON\" | jq -r '.[0].version \/\/ empty')\r\n local INSTALLER_URL=$(echo \"$INSTALLER_JSON\" | jq -r '.[0].url \/\/ empty')\r\n\r\n if [[ -z \"${INSTALLER_VERSION}\" ]]; then\r\n echo -e \"\\tERROR: No Quilt installer version found\"\r\n exit 1\r\n fi\r\n\r\n if [[ -z \"${INSTALLER_URL}\" ]]; then\r\n echo -e \"\\tERROR: No Quilt installer URL found\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tDownloading Quilt Installer ${MC_VERSION}-${QUILT_VERSION} (${INSTALLER_VERSION}) from ${INSTALLER_URL}\"\r\n\r\n if ! wget -q -O quilt-installer.jar \"${INSTALLER_URL}\"; then\r\n echo -e \"\\tERROR: Failed to download Quilt Installer ${MC_VERSION}-${QUILT_VERSION} (${INSTALLER_VERSION})\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tInstalling Quilt Server ${MC_VERSION}-${QUILT_VERSION} (${INSTALLER_VERSION})\"\r\n if ! java -jar quilt-installer.jar install server \"${MC_VERSION}\" \"${QUILT_VERSION}\" --download-server --install-dir=.\/; then\r\n echo -e \"\\tERROR: Failed to install Quilt Server ${MC_VERSION}-${QUILT_VERSION} (${INSTALLER_VERSION})\"\r\n exit 1\r\n fi\r\n\r\n echo \"quilt-server-launch.jar\" > \".serverjar\"\r\n\r\n rm quilt-installer.jar\r\n}\r\n\r\ninstall_required\r\n\r\nif [[ -z \"${PROJECT_ID}\" ]]; then\r\n echo \"ERROR: You must specify a PROJECT_ID environment variable!\"\r\n exit 1\r\nfi\r\n\r\nif [[ ! \"${PROJECT_ID}\" = \"zip\" ]]; then\r\n\tget_download\r\nfi\r\n\r\nget_loader\r\nunpack_zip\r\n\r\nif [[ -f \"${SERVER_DIR}\/manifest.json\" ]]; then\r\n echo \"Found manifest.json, installing mods\"\r\n json_download_mods\r\n json_download_overrides\r\nfi\r\n\r\nif [[ -f \"${SERVER_DIR}\/client.manifest.json\" ]]; then\r\n MANIFEST=\"${SERVER_DIR}\/client.manifest.json\"\r\n\r\n if [[ $LOADER_NAME == \"forge\" ]]; then\r\n json_download_forge\r\n fi\r\n\r\n if [[ $LOADER_NAME == \"fabric\" ]]; then\r\n json_download_fabric\r\n fi\r\n\r\n if [[ $LOADER_NAME == \"quilt\" ]]; then\r\n json_download_quilt\r\n fi\r\nfi\r\n\r\necho -e \"\\nInstall completed succesfully, enjoy!\"", + "script": "#!\/bin\/bash\r\n# shellcheck disable=SC2155\r\n#\r\n# CurseForge Installation Script\r\n#\r\n# Server Files: \/mnt\/server\r\n\r\n: \"${SERVER_DIR:=\/mnt\/server}\"\r\n: \"${PROJECT_ID:=}\"\r\n: \"${VERSION_ID:=}\"\r\n: \"${API_KEY:=}\"\r\n\r\nif [[ ! -d $SERVER_DIR ]]; then\r\n mkdir -p \"$SERVER_DIR\"\r\nfi\r\n\r\nif ! cd \"$SERVER_DIR\"; then\r\n echo -e \"Failed to change directory to ${SERVER_DIR}\"\r\n exit 1\r\nfi\r\n\r\nfunction install_required {\r\n echo -e \"Installing required packages...\"\r\n echo -e \"\\tRunning apt update\"\r\n apt update > \/dev\/null 2>&1 || { echo \"apt update failed!\"; exit 1; }\r\n echo -e \"\\tRunning apt install\"\r\n apt install -y wget jq unzip > \/dev\/null 2>&1 || { echo \"apt install failed!\"; exit 1; }\r\n}\r\n\r\nCURSEFORGE_API_URL=\"https:\/\/api.curseforge.com\/v1\/mods\/\"\r\nCURSEFORGE_API_HEADERS=(\"--header=Accept: application\/json\" \"--header=x-api-key: ${API_KEY}\")\r\n\r\nfunction get_download {\r\n echo -e \"Retrieving CurseForge project information...\"\r\n local PROJECT_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\" -O -)\r\n local PROJECT_TITLE=$(echo \"$PROJECT_DATA\" | jq -r '.data.name \/\/ empty')\r\n\r\n if [[ -z \"${PROJECT_DATA}\" ]]; then\r\n echo -e \"\\tERROR: Failed to retrieve project data for project id '${PROJECT_ID}'\"\r\n exit 1\r\n fi\r\n\r\n local IS_SERVER_PACK=false\r\n\r\n if [[ -z \"${VERSION_ID}\" || \"${VERSION_ID}\" == \"latest\" ]]; then\r\n echo -e \"\\tNo file ID specified, using latest file\"\r\n VERSION_ID=$(echo \"$PROJECT_DATA\" | jq -r '.data.mainFileId \/\/ empty')\r\n\r\n local VERSION_SERVER_PACK=\"$(echo -e \"${PROJECT_DATA}\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[] | select(.id|tostring==$VERSION_ID) | .isServerPack')\"\r\n local VERSION_SERVER_ID=\"$(echo -e \"${PROJECT_DATA}\" | jq -r --arg VERSION_ID \"$VERSION_ID\" '.data.latestFiles[] | select(.id|tostring==$VERSION_ID) | .serverPackFileId')\"\r\n\r\n if [[ \"${VERSION_SERVER_PACK}\" == \"false\" && -n \"${VERSION_SERVER_ID}\" ]]; then\r\n echo -e \"\\tFound server pack file id '${VERSION_SERVER_ID}'\"\r\n VERSION_ID=$VERSION_SERVER_ID\r\n IS_SERVER_PACK=true\r\n elif [[ \"${VERSION_SERVER_PACK}\" == \"true\" ]]; then\r\n IS_SERVER_PACK=true\r\n fi\r\n else\r\n echo -e \"\\tChecking if provided file id '${VERSION_ID}' exists\"\r\n\r\n local FILE_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\/files\/${VERSION_ID}\" -O -)\r\n\r\n if [[ -z \"${FILE_DATA}\" ]]; then\r\n echo -e \"\\tERROR: File id '${VERSION_ID}' not found for project '${PROJECT_TITLE}'\"\r\n exit 1\r\n fi\r\n\r\n IS_SERVER_PACK=$(echo -e \"${FILE_DATA}\" | jq -r '.data.isServerPack \/\/ \"false\"')\r\n\r\n if [[ \"${IS_SERVER_PACK}\" == \"false\" ]]; then\r\n local VERSION_SERVER_PACK=\"$(echo -e \"${FILE_DATA}\" | jq -r '.data.serverPackFileId \/\/ empty')\"\r\n if [[ -n \"${VERSION_SERVER_PACK}\" ]]; then\r\n echo -e \"\\tFound server pack file id '${VERSION_SERVER_PACK}'\"\r\n VERSION_ID=$VERSION_SERVER_PACK\r\n IS_SERVER_PACK=true\r\n fi\r\n else\r\n IS_SERVER_PACK=true\r\n fi\r\n fi\r\n\r\n # Check if version id is unset or empty string\r\n if [[ -z \"${VERSION_ID}\" ]]; then\r\n echo -e \"\\tERROR: No file id found for project '${PROJECT_TITLE}'\"\r\n exit 1\r\n fi\r\n\r\n if [[ \"${IS_SERVER_PACK}\" == \"false\" ]]; then\r\n echo -e \"\\tWARNING: File id '${VERSION_ID}' is not a server pack, attempting to use client files\"\r\n fi\r\n\r\n # get json data to work with\r\n echo -e \"\\tRetrieving version information for '${VERSION_ID}'\"\r\n local JSON_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\/files\/${VERSION_ID}\/download-url\" -O -)\r\n\r\n if [[ -z \"${JSON_DATA}\" ]]; then\r\n echo -e \"\\tERROR: Failed to retrieve file data for file id '${VERSION_ID}'\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tParsing CurseForge pack download url\"\r\n\r\n local DOWNLOAD_URL=$(echo -e \"$JSON_DATA\" | jq -r '.data \/\/ empty')\r\n if [[ -z \"${DOWNLOAD_URL}\" ]]; then\r\n echo -e \"\\tERROR: No download url found for file ${VERSION_ID}\"\r\n exit 1\r\n fi\r\n\r\n # download modpack files\r\n echo -e \"\\tDownloading ${DOWNLOAD_URL}\"\r\n if ! wget -q \"${DOWNLOAD_URL}\" -O server.zip; then\r\n echo -e \"Download failed!\"\r\n exit 1\r\n fi\r\n}\r\n\r\nfunction get_loader {\r\n echo -e \"Retrieving loader information...\"\r\n\r\n local PROJECT_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\" -O -)\r\n local PROJECT_TITLE=$(echo \"$PROJECT_DATA\" | jq -r '.data.name \/\/ empty')\r\n if [[ -z \"${PROJECT_DATA}\" ]]; then\r\n echo -e \"\\tERROR: Failed to retrieve project data for project id '${PROJECT_ID}'\"\r\n exit 1\r\n fi\r\n\r\n local FILE_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\/files\/${VERSION_ID}\" -O -)\r\n\r\n if [[ -z \"${FILE_DATA}\" ]]; then\r\n echo -e \"\\tERROR: File id '${VERSION_ID}' not found for project '${PROJECT_TITLE}'\"\r\n exit 1\r\n fi\r\n\r\n local IS_SERVER_PACK=$(echo -e \"${FILE_DATA}\" | jq -r '.data.isServerPack \/\/ \"false\"')\r\n local CLIENT_VERSION_ID;\r\n\r\n if [[ \"${IS_SERVER_PACK}\" == \"true\" ]]; then\r\n CLIENT_VERSION_ID=\"$(echo -e \"${FILE_DATA}\" | jq -r '.data.parentProjectFileId \/\/ empty')\"\r\n else\r\n CLIENT_VERSION_ID=$VERSION_ID\r\n fi\r\n\r\n if [[ -z \"${CLIENT_VERSION_ID}\" ]]; then\r\n echo -e \"\\tERROR: File id '${VERSION_ID}' not found for project '${PROJECT_TITLE}'\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tRetrieving file information for '${CLIENT_VERSION_ID}'\"\r\n local JSON_DATA=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${PROJECT_ID}\/files\/${CLIENT_VERSION_ID}\/download-url\" -O -)\r\n\r\n echo -e \"\\tParsing CurseForge pack download url\"\r\n\r\n local DOWNLOAD_URL=$(echo -e \"$JSON_DATA\" | jq -r '.data \/\/ empty')\r\n\r\n if [[ -z \"${DOWNLOAD_URL}\" ]]; then\r\n echo -e \"\\tERROR: No download url found for file id ${CLIENT_VERSION_ID}\"\r\n exit 1\r\n fi\r\n\r\n # download modpack files\r\n echo -e \"\\tDownloading ${DOWNLOAD_URL}\"\r\n wget -q \"${DOWNLOAD_URL}\" -O client.zip\r\n\r\n echo -e \"\\tUnpacking client manifest\"\r\n unzip -jo client.zip manifest.json -d \"${SERVER_DIR}\"\r\n mv \"${SERVER_DIR}\/manifest.json\" \"${SERVER_DIR}\/client.manifest.json\" # rename to avoid conflicts with main manifest\r\n rm -rf client.zip\r\n\r\n echo -e \"\\tParsing client manifest\"\r\n local MANIFEST=\"${SERVER_DIR}\/client.manifest.json\"\r\n\r\n LOADER_ID=$(jq -r '.minecraft.modLoaders[]? | select(.primary == true) | .id' \"${MANIFEST}\")\r\n LOADER_NAME=$(echo \"${LOADER_ID}\" | cut -d'-' -f1)\r\n LOADER_VERSION=$(echo \"${LOADER_ID}\" | cut -d'-' -f2)\r\n\r\n if [[ -z \"${LOADER_NAME}\" || -z \"${LOADER_VERSION}\" ]]; then\r\n echo -e \"\\tERROR: No loader found in client manifest!\"\r\n exit 1\r\n fi\r\n\r\n MINECRAFT_VERSION=$(jq -r '.minecraft.version \/\/ empty' \"${MANIFEST}\")\r\n\r\n if [[ -z \"${MINECRAFT_VERSION}\" ]]; then\r\n echo -e \"\\tERROR: No minecraft version found in client manifest!\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tFound loader ${LOADER_NAME} ${LOADER_VERSION} for Minecraft ${MINECRAFT_VERSION}\"\r\n}\r\n\r\nfunction unzip-strip() (\r\n set -u\r\n\r\n local archive=$1\r\n local destdir=${2:-}\r\n shift; shift || :\r\n echo -e \"\\tUnpacking ${archive} to ${destdir}\"\r\n\r\n echo -e \"\\tCreating temporary directory\"\r\n local tmpdir=\/mnt\/server\/tmp\r\n if ! mkdir -p \"${tmpdir}\"; then\r\n echo -e \"\\tERROR: mkdir failed to create temporary directory\"\r\n return 1\r\n fi\r\n\r\n trap 'rm -rf -- \"$tmpdir\"' EXIT\r\n\r\n echo -e \"\\tUnpacking archive\"\r\n\r\n if ! unzip -q \"$archive\" -d \"$tmpdir\"; then\r\n echo -e \"\\tERROR: unzip failed to unpack archive\"\r\n return 1\r\n fi\r\n\r\n echo -e \"\\tSetting glob settings\"\r\n\r\n shopt -s dotglob\r\n\r\n echo -e \"\\tCleaning up directory structure\"\r\n\r\n local files=(\"$tmpdir\"\/*) name i=1\r\n\r\n if (( ${#files[@]} == 1 )) && [[ -d \"${files[0]}\" ]]; then\r\n name=$(basename \"${files[0]}\")\r\n files=(\"$tmpdir\"\/*\/*)\r\n else\r\n name=$(basename \"$archive\"); name=${archive%.*}\r\n files=(\"$tmpdir\"\/*)\r\n fi\r\n\r\n if [[ -z \"$destdir\" ]]; then\r\n destdir=.\/\"$name\"\r\n fi\r\n\r\n while [[ -f \"$destdir\" ]]; do\r\n destdir=${destdir}-$((i++));\r\n done\r\n\r\n echo -e \"\\tCopying files to ${destdir}\"\r\n\r\n mkdir -p \"$destdir\"\r\n cp -ar \"$@\" -t \"$destdir\" -- \"${files[@]}\"\r\n rm -rf \"$tmpdir\"\r\n)\r\n\r\nfunction unpack_zip {\r\n echo -e \"Unpacking server files...\"\r\n unzip-strip server.zip \"${SERVER_DIR}\"\r\n rm -rf server.zip\r\n}\r\n\r\nfunction json_download_mods {\r\n echo \"Downloading mods...\"\r\n\r\n local MANIFEST=\"${SERVER_DIR}\/manifest.json\"\r\n jq -c '.files[]? | select(.required == true) | {project: .projectID, file: .fileID}' \"${MANIFEST}\" | while read -r mod; do\r\n local MOD_PROJECT_ID=$(echo \"${mod}\" | jq -r '.project \/\/ empty')\r\n local MOD_FILE_ID=$(echo \"${mod}\" | jq -r '.file \/\/ empty')\r\n\r\n if [[ -z \"${MOD_PROJECT_ID}\" || -z \"${MOD_FILE_ID}\" ]]; then\r\n echo -e \"\\tERROR: Failed to parse project id or file id for mod '${mod}'\"\r\n exit 1\r\n fi\r\n\r\n local FILE_URL=$(wget -q \"${CURSEFORGE_API_HEADERS[@]}\" \"${CURSEFORGE_API_URL}${MOD_PROJECT_ID}\/files\/${MOD_FILE_ID}\/download-url\" -O - | jq -r '.data \/\/ empty')\r\n\r\n if [[ -z \"${FILE_URL}\" ]]; then\r\n echo -e \"\\tERROR: No download url found for mod ${MOD_PROJECT_ID} ${MOD_FILE_ID}\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tDownloading ${FILE_URL}\"\r\n\r\n if ! wget -q \"${FILE_URL}\" -P \"${SERVER_DIR}\/mods\"; then\r\n echo -e \"\\tERROR: Failed to download mod ${MOD_PROJECT_ID} ${MOD_FILE_ID}\"\r\n exit 1\r\n fi\r\n done\r\n}\r\n\r\nfunction json_download_overrides {\r\n echo \"Copying overrides...\"\r\n if [[ -d \"${SERVER_DIR}\/overrides\" ]]; then\r\n cp -r \"${SERVER_DIR}\/overrides\/\"* \"${SERVER_DIR}\"\r\n rm -r \"${SERVER_DIR}\/overrides\"\r\n fi\r\n}\r\n\r\nFORGE_INSTALLER_URL=\"https:\/\/maven.minecraftforge.net\/net\/minecraftforge\/forge\/\"\r\n\r\nfunction json_download_forge {\r\n echo \"Downloading Forge...\"\r\n\r\n local MC_VERSION=$MINECRAFT_VERSION\r\n local FORGE_VERSION=$LOADER_VERSION\r\n\r\n FORGE_VERSION=\"${MC_VERSION}-${FORGE_VERSION}\"\r\n if [[ \"${MC_VERSION}\" == \"1.7.10\" || \"${MC_VERSION}\" == \"1.8.9\" ]]; then\r\n FORGE_VERSION=\"${FORGE_VERSION}-${MC_VERSION}\"\r\n fi\r\n\r\n local FORGE_JAR=\"forge-${FORGE_VERSION}.jar\"\r\n if [[ \"${MC_VERSION}\" == \"1.7.10\" ]]; then\r\n FORGE_JAR=\"forge-${FORGE_VERSION}-universal.jar\"\r\n fi\r\n\r\n local FORGE_URL=\"${FORGE_INSTALLER_URL}${FORGE_VERSION}\/forge-${FORGE_VERSION}\"\r\n\r\n echo -e \"\\tUsing Forge ${FORGE_VERSION} from ${FORGE_URL}\"\r\n\r\n local FORGE_INSTALLER=\"${FORGE_URL}-installer.jar\"\r\n echo -e \"\\tDownloading Forge Installer ${FORGE_VERSION} from ${FORGE_INSTALLER}\"\r\n\r\n if ! wget -q -O forge-installer.jar \"${FORGE_INSTALLER}\"; then\r\n echo -e \"\\tERROR: Failed to download Forge Installer ${FORGE_VERSION}\"\r\n exit 1\r\n fi\r\n\r\n # Remove old Forge files so we can safely update\r\n rm -rf libraries\/net\/minecraftforge\/forge\/\r\n rm -f unix_args.txt\r\n\r\n echo -e \"\\tInstalling Forge Server ${FORGE_VERSION}\"\r\n if ! java -jar forge-installer.jar --installServer > \/dev\/null 2>&1; then\r\n echo -e \"\\tERROR: Failed to install Forge Server ${FORGE_VERSION}\"\r\n exit 1\r\n fi\r\n\r\n if [[ $MC_VERSION =~ ^1\\.(17|18|19|20|21|22|23) || $FORGE_VERSION =~ ^1\\.(17|18|19|20|21|22|23) ]]; then\r\n echo -e \"\\tDetected Forge 1.17 or newer version. Setting up Forge Unix arguments\"\r\n ln -sf libraries\/net\/minecraftforge\/forge\/*\/unix_args.txt unix_args.txt\r\n else\r\n mv \"$FORGE_JAR\" forge-server-launch.jar\r\n echo \"forge-server-launch.jar\" > \".serverjar\"\r\n fi\r\n\r\n rm -f forge-installer.jar\r\n}\r\n\r\nFABRIC_INSTALLER_URL=\"https:\/\/meta.fabricmc.net\/v2\/versions\/installer\"\r\n\r\nfunction json_download_fabric {\r\n echo \"Downloading Fabric...\"\r\n\r\n local MC_VERSION=$MINECRAFT_VERSION\r\n local FABRIC_VERSION=$LOADER_VERSION\r\n\r\n local INSTALLER_JSON=$(wget -q -O - ${FABRIC_INSTALLER_URL} )\r\n local INSTALLER_VERSION=$(echo \"$INSTALLER_JSON\" | jq -r '.[0].version \/\/ empty')\r\n local INSTALLER_URL=$(echo \"$INSTALLER_JSON\" | jq -r '.[0].url \/\/ empty')\r\n\r\n if [[ -z \"${INSTALLER_VERSION}\" ]]; then\r\n echo -e \"\\tERROR: No Fabric installer version found\"\r\n exit 1\r\n fi\r\n\r\n if [[ -z \"${INSTALLER_URL}\" ]]; then\r\n echo -e \"\\tERROR: No Fabric installer url found\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tDownloading Fabric Installer ${MC_VERSION}-${FABRIC_VERSION} (${INSTALLER_VERSION}) from ${INSTALLER_URL}\"\r\n\r\n if ! wget -q -O fabric-installer.jar \"${INSTALLER_URL}\"; then\r\n echo -e \"\\tERROR: Failed to download Fabric Installer ${MC_VERSION}-${FABRIC_VERSION} (${INSTALLER_VERSION})\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tInstalling Fabric Server ${MC_VERSION}-${FABRIC_VERSION} (${INSTALLER_VERSION})\"\r\n if ! java -jar fabric-installer.jar server -mcversion \"${MC_VERSION}\" -loader \"${FABRIC_VERSION}\" -downloadMinecraft; then\r\n echo -e \"\\tERROR: Failed to install Fabric Server ${MC_VERSION}-${FABRIC_VERSION} (${INSTALLER_VERSION})\"\r\n exit 1\r\n fi\r\n\r\n echo \"fabric-server-launch.jar\" > \".serverjar\"\r\n\r\n rm -f fabric-installer.jar\r\n}\r\n\r\nQUILT_INSTALLER_URL=\"https:\/\/meta.quiltmc.org\/v3\/versions\/installer\"\r\n\r\nfunction json_download_quilt {\r\n echo \"Downloading Quilt...\"\r\n\r\n local MC_VERSION=$MINECRAFT_VERSION\r\n local QUILT_VERSION=$LOADER_VERSION\r\n\r\n local INSTALLER_JSON=$(wget -q -O - ${QUILT_INSTALLER_URL} )\r\n local INSTALLER_VERSION=$(echo \"$INSTALLER_JSON\" | jq -r '.[0].version \/\/ empty')\r\n local INSTALLER_URL=$(echo \"$INSTALLER_JSON\" | jq -r '.[0].url \/\/ empty')\r\n\r\n if [[ -z \"${INSTALLER_VERSION}\" ]]; then\r\n echo -e \"\\tERROR: No Quilt installer version found\"\r\n exit 1\r\n fi\r\n\r\n if [[ -z \"${INSTALLER_URL}\" ]]; then\r\n echo -e \"\\tERROR: No Quilt installer URL found\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tDownloading Quilt Installer ${MC_VERSION}-${QUILT_VERSION} (${INSTALLER_VERSION}) from ${INSTALLER_URL}\"\r\n\r\n if ! wget -q -O quilt-installer.jar \"${INSTALLER_URL}\"; then\r\n echo -e \"\\tERROR: Failed to download Quilt Installer ${MC_VERSION}-${QUILT_VERSION} (${INSTALLER_VERSION})\"\r\n exit 1\r\n fi\r\n\r\n echo -e \"\\tInstalling Quilt Server ${MC_VERSION}-${QUILT_VERSION} (${INSTALLER_VERSION})\"\r\n if ! java -jar quilt-installer.jar install server \"${MC_VERSION}\" \"${QUILT_VERSION}\" --download-server --install-dir=.\/; then\r\n echo -e \"\\tERROR: Failed to install Quilt Server ${MC_VERSION}-${QUILT_VERSION} (${INSTALLER_VERSION})\"\r\n exit 1\r\n fi\r\n\r\n echo \"quilt-server-launch.jar\" > \".serverjar\"\r\n\r\n rm quilt-installer.jar\r\n}\r\n\r\ninstall_required\r\n\r\nif [[ -z \"${PROJECT_ID}\" ]]; then\r\n echo \"ERROR: You must specify a PROJECT_ID environment variable!\"\r\n exit 1\r\nfi\r\n\r\nif [[ ! \"${PROJECT_ID}\" = \"zip\" ]]; then\r\n\tget_download\r\nfi\r\n\r\nget_loader\r\nunpack_zip\r\n\r\nif [[ -f \"${SERVER_DIR}\/manifest.json\" ]]; then\r\n echo \"Found manifest.json, installing mods\"\r\n json_download_mods\r\n json_download_overrides\r\nfi\r\n\r\nif [[ -f \"${SERVER_DIR}\/client.manifest.json\" ]]; then\r\n MANIFEST=\"${SERVER_DIR}\/client.manifest.json\"\r\n\r\n if [[ $LOADER_NAME == \"forge\" ]]; then\r\n json_download_forge\r\n fi\r\n\r\n if [[ $LOADER_NAME == \"fabric\" ]]; then\r\n json_download_fabric\r\n fi\r\n\r\n if [[ $LOADER_NAME == \"quilt\" ]]; then\r\n json_download_quilt\r\n fi\r\nfi\r\n\r\necho -e \"\\nInstall completed succesfully, enjoy!\"", "container": "openjdk:8-jdk-slim", "entrypoint": "bash" }