├── .github ├── .gitignore ├── workflows │ └── release.yml └── README.md ├── get-game-versions.ps1 ├── secrets.ps1 ├── settings.ps1 ├── LICENSE └── modpack-uploader.ps1 /.github/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*.*.*' 7 | 8 | jobs: 9 | release: 10 | runs-on: "ubuntu-latest" 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | 15 | - name: Zip Files 16 | run: tar cf ModpackUploader.zip modpack-uploader.ps1 settings.ps1 secrets.ps1 get-game-versions.ps1 LICENSE 17 | 18 | - name: Release 19 | uses: softprops/action-gh-release@v1 20 | with: 21 | generate_release_notes: true 22 | fail_on_unmatched_files: true 23 | token: ${{ secrets.GITHUB_TOKEN }} 24 | files: ModpackUploader.zip 25 | -------------------------------------------------------------------------------- /get-game-versions.ps1: -------------------------------------------------------------------------------- 1 | $secretsFile = "secrets.ps1" 2 | 3 | function Validate-SecretsFile { 4 | if (!(Test-Path "$PSScriptRoot/$secretsFile")) { 5 | Write-Host "You need a valid CurseForge API Token in a $secretsFile file" -ForegroundColor Red 6 | Write-Host "Creating $secretsFile" -ForegroundColor Cyan 7 | New-Item -Path $PSScriptRoot -ItemType File -Name $secretsFile -Value "# To generate an API token go to: https://authors.curseforge.com/account/api-tokens `n $CURSEFORGE_TOKEN = `"your-curseforge-token-here`"" 8 | } 9 | } 10 | 11 | . "$PSScriptRoot/$secretsFile" 12 | 13 | if ($null -eq $IsWindows -or $IsWindows) { 14 | # The script is running on Windows, use curl.exe 15 | $curl = "curl.exe" 16 | } 17 | else { 18 | $curl = "curl" 19 | } 20 | 21 | & $curl -H X-Api-Token:$CURSEFORGE_TOKEN https://minecraft.curseforge.com/api/game/versions >> game-versions.json 22 | -------------------------------------------------------------------------------- /secrets.ps1: -------------------------------------------------------------------------------- 1 | # Secret settings for the ModpackUploader 2 | # For details/help see: https://github.com/NillerMedDild/ModpackUploader 3 | 4 | # =====================================================================// 5 | # CURSEFORGE ACCOUNT SETTINGS 6 | # =====================================================================// 7 | 8 | # Get one here: https://authors.curseforge.com/account/api-tokens 9 | $CURSEFORGE_TOKEN = "My-Token" 10 | 11 | # =====================================================================// 12 | # GITHUB COMPATIBILITY SETTINGS 13 | # =====================================================================// 14 | 15 | # Example for this repo: 16 | # https://github.com/EnigmaticaModpacks/ModpackUploader 17 | # https://github.com/$GITHUB_NAME/$GITHUB_REPOSITORY 18 | # $GITHUB_NAME = "EnigmaticaModpacks" 19 | # $GITHUB_REPOSITORY = "ModpackUploader" 20 | 21 | $GITHUB_NAME = "MyGitHubUsername" 22 | 23 | $GITHUB_REPOSITORY = "MyModpack" 24 | 25 | $GITHUB_TOKEN = "$GITHUB_NAME`:MY-SECRET-GITHUB-TOKEN" -------------------------------------------------------------------------------- /.github/README.md: -------------------------------------------------------------------------------- 1 | # ⏫ Modpack Uploader 2 | 3 | Modpack Uploader is a script that can automatically upload modpacks to CurseForge. 4 | 5 | Almost everything can be toggled on/off in the settings. 6 | 7 | # 🚧 Getting Started 8 | 9 | 1. Download the latest release, and unzip it into your modpack instance. 10 | - You can place it in a subfolder, but you need to change the `$INSTANCE_ROOT` in the `settings.ps1` file. 11 | 2. Fill in the `settings.ps1` file with your modpack information. 12 | 3. Fill in the `secrets.ps1` file with your CurseForge Upload API Token. 13 | 4. Run the `modpack-uploader.ps1` when you're ready to upload your modpack. 14 | 15 | # ✔️Features 16 | 17 | - Client ZIP file creation and upload with the `CLIENT_FILE_MODULE` and `MODPACK_UPLOADER_MODULE` ✔️ On by default 18 | - Server ZIP file creation and upload with the `SERVER_FILE_MODULE` and `MODPACK_UPLOADER_MODULE` ✔️ On by default 19 | - Automatic updating of `modpackUrl` in ServerStarter's `server-setup-config.yaml` ❌ _Off by default_ 20 | - Grab the changelogs of all the mods updated in your new release with the `CHANGELOG_GENERATOR_MODULE` ❌ _Off by default_ 21 | - Make a modlist complete with links to the mods and authors with the `MODLIST_CREATOR_MODULE` ✔️ _On by default_ 22 | - Make a new GitHub release when you upload your modpack with the `GITHUB_RELEASE_MODULE` ❌ _Off by default_ 23 | 24 | # ➕ Dependencies 25 | 26 | - [cURL](https://curl.haxx.se/download.html) 27 | - [7-Zip](https://www.7-zip.org/download.html) 28 | - [PowerShell](https://docs.microsoft.com/en-us/powershell/) 29 | - Windows comes with Powershell pre-installed. 30 | - [Linux Download Instructions](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux) 31 | - [Mac Download Instructions](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-macos) 32 | 33 | # ❤️ Special Thanks 34 | 35 | - [TheRandomLabs](https://github.com/TheRandomLabs), for their [Changelog Generator](https://github.com/TheRandomLabs/ChangelogGenerator), which allows this project to incoorperate the changelogs of the mods that are updated. 36 | 37 | - [UnicorNora](https://github.com/UnicorNora), for their help in improving this tool while making it easier to use. 38 | 39 | - [ModdingX](https://github.com/ModdingX) for their project [Modlist Creator](https://github.com/ModdingX/ModListCreator), which allows this project to create nice looking modlists. 40 | -------------------------------------------------------------------------------- /settings.ps1: -------------------------------------------------------------------------------- 1 | # Settings for the ModpackUploader 2 | # For details/help see: https://github.com/NillerMedDild/ModpackUploader 3 | 4 | # The path to the main modpack folder. (the same folder as the mods folder is in) 5 | # Running the modpack uploader from the main modpack folder: ("$PSScriptRoot" | Resolve-Path) 6 | # Running the modpacker uploader from a subfolder: ("$PSScriptRoot/.." | Resolve-Path) 7 | $INSTANCE_ROOT = ("$PSScriptRoot" | Resolve-Path) 8 | 9 | # =====================================================================// 10 | # CURSEFORGE ACCOUNT SETTINGS 11 | # =====================================================================// 12 | 13 | $CURSEFORGE_USER = "MyCurseForgeUsername" 14 | 15 | # For details see: https://www.curseforge.com/account/api-tokens 16 | # Defined in secrets.ps1 17 | # $CURSEFORGE_TOKEN = 18 | 19 | # ProjectID can be found on the modpack's Curseforge Projects page, under "About This Project" 20 | $CURSEFORGE_PROJECT_ID = 123456 21 | 22 | # =====================================================================// 23 | # MAIN MODPACK SETTINGS 24 | # =====================================================================// 25 | 26 | # This is the modpack name as seen in it's CurseForge url: https://www.curseforge.com/minecraft/modpacks/[enigmatica6] 27 | $MODPACK_NAME = "MyModpack" 28 | 29 | # Name of the Modpack in the ZIP File 30 | $CLIENT_NAME = "MyModpack" 31 | 32 | # Version Of The Modpack 33 | $MODPACK_VERSION = "1.0.1" 34 | 35 | # Last Version Of The Modpack 36 | # Needed For Changelog Parsing 37 | # Should be "$null" if this is the first release 38 | $LAST_MODPACK_VERSION = "1.0.0" 39 | 40 | # Which modloader the modpack uses 41 | # Can be "forge" or "fabric" 42 | # default: "forge" 43 | $MODLOADER = "forge" 44 | 45 | # =====================================================================// 46 | # CHANGELOG SETTINGS 47 | # =====================================================================// 48 | 49 | # Changelog Type 50 | # Can be "markdown", "text" or "html" 51 | $CLIENT_CHANGELOG_TYPE = "markdown" 52 | 53 | # Changelog 54 | # Must be a single string. 55 | $CLIENT_CHANGELOG = "The Changelog is currently being written." 56 | 57 | # =====================================================================// 58 | # CURSEFORGE PROJECT SETTINGS 59 | # =====================================================================// 60 | 61 | # Modpack's Minecraft Version 62 | # @(6756) - is Minecraft 1.12.2 63 | # @(8203) - is Minecraft 1.16.5 64 | # More can be found by running GetGameVersions 65 | $GAME_VERSIONS = @(8203) 66 | 67 | # Can be "alpha", "beta" or "release" 68 | $CLIENT_RELEASE_TYPE = "beta" 69 | 70 | #=====================================================================// 71 | # DEPENDENCIES 72 | #=====================================================================// 73 | 74 | # File name of the latest https://github.com/ModdingX/ModListCreator/releases 75 | $CHANGELOG_GENERATOR_JAR = "ModListCreator-4.0.3-fatjar.jar" 76 | 77 | # File name of the latest https://github.com/ModdingX/ModListCreator/releases 78 | $MODLIST_CREATOR_JAR = "ModListCreator-4.0.3-fatjar.jar" 79 | 80 | #=====================================================================// 81 | # CLIENT FILE SETTINGS 82 | #=====================================================================// 83 | 84 | $CLIENT_FILE_AUTHOR = "MyName" 85 | 86 | $FOLDERS_TO_INCLUDE_IN_CLIENT_FILES = @( 87 | "config", 88 | "defaultconfigs", 89 | "kubejs", 90 | "local", 91 | "packmenu") 92 | 93 | $CONFIGS_TO_REMOVE_FROM_CLIENT_FILES = @() 94 | 95 | $FOLDERS_TO_REMOVE_FROM_CLIENT_FILES = @("local/ftbutilities", "resourcepacks") 96 | 97 | # Example: 98 | # $FILES_TO_INCLUDE_IN_MODS_FOLDER_IN_CLIENT_FILES = @("mods/Apotheosis-1.19.2-6.2.1.jar", "mods/create-1.19.2-0.5.1.b.jar") 99 | $FILES_TO_INCLUDE_IN_MODS_FOLDER_IN_CLIENT_FILES = @() 100 | 101 | #=====================================================================// 102 | # SERVER FILE SETTINGS 103 | #=====================================================================// 104 | 105 | $SERVER_FILES_FOLDER = "$INSTANCE_ROOT/server_files" 106 | 107 | $SERVER_SETUP_CONFIG_PATH = "$SERVER_FILES_FOLDER/server-setup-config.yaml" 108 | 109 | # =====================================================================// 110 | # MODULES 111 | # =====================================================================// 112 | 113 | # Toggle automatic building of the manifest zip on/off 114 | # Default: $true 115 | $ENABLE_CLIENT_FILE_MODULE = $true 116 | 117 | # Toggle the modpack uploader on/off 118 | # Setting this to $false will also disable the Server File and Changelog Generator Modules. 119 | # Default: $true 120 | $ENABLE_MODPACK_UPLOADER_MODULE = $true 121 | 122 | # Toggle server file feature on/off 123 | # Default: $true 124 | $ENABLE_SERVER_FILE_MODULE = $true 125 | 126 | # Toggle serverstarter compatibility on/off 127 | # This will update the "modpackUrl" in the file found at $SERVER_SETUP_CONFIG_PATH 128 | # to point to your newly created client files on the CurseForge CDN. 129 | # Default: $false 130 | $ENABLE_SERVERSTARTER_MODULE = $false 131 | 132 | # Toggle automatic changelog generator on/off 133 | # This module requires an older modpack manifest zip to be present, 134 | # $LAST_MODPACK_VERSION must be set, and the manifest naming must be consistent. 135 | # Default: $false 136 | $ENABLE_CHANGELOG_GENERATOR_MODULE = $false 137 | # Path to the ChangelogGenerator's output file 138 | $CHANGELOG_PATH = "$INSTANCE_ROOT/changelogs/changelog_mods_$MODPACK_VERSION.md" 139 | 140 | # Toggle creation of a modlist file on/off 141 | # Default: $true 142 | $ENABLE_MODLIST_CREATOR_MODULE = $true 143 | # Path to the ModListCreator's output file 144 | $MODLIST_PATH = "$INSTANCE_ROOT/changelogs/modlist_$MODPACK_VERSION.md" 145 | 146 | # Toggle removal and re-download of jars on/off. 147 | # Setting this to true will ensure that you always have the latest 148 | # Twitch Export Builder and ChangelogGenerator, but increases the 149 | # amount of time this script takes to execute. 150 | # Default: $false 151 | $ENABLE_ALWAYS_UPDATE_JARS = $false 152 | 153 | # Toggles github release integration on/off. 154 | # This will create a new release on your issue-tracker when using the modpack uploader. 155 | # See below link for info: 156 | # Default: $false 157 | $ENABLE_GITHUB_RELEASE_MODULE = $false 158 | 159 | 160 | # =====================================================================// 161 | # ADVANCED 162 | # Do not change anything unless you 163 | # know what you are doing! 164 | # =====================================================================// 165 | 166 | # Syntax of the Client ZIP File 167 | $CLIENT_ZIP_NAME = "$CLIENT_NAME-$MODPACK_VERSION" 168 | 169 | # Syntax of the Previous Versions Client ZIP File 170 | $LAST_MODPACK_ZIP_NAME = "$CLIENT_NAME-$LAST_MODPACK_VERSION" 171 | 172 | # Default: "$CLIENT_NAME $MODPACK_VERSION" 173 | $CLIENT_FILE_DISPLAY_NAME = "MyModpack $MODPACK_VERSION" 174 | 175 | # Can be "markdown", "text" or "html" 176 | # Default: $CLIENT_CHANGELOG_TYPE 177 | $SERVER_CHANGELOG_TYPE = $CLIENT_CHANGELOG_TYPE 178 | 179 | # Must be a single string. Use Powershell escaping for new lines etc. New line is `n and indent is `t 180 | # Default: $CLIENT_CHANGELOG 181 | $SERVER_CHANGELOG = $CLIENT_CHANGELOG 182 | 183 | # Can be "alpha", "beta" or "release" 184 | # Default: $CLIENT_RELEASE_TYPE 185 | $SERVER_RELEASE_TYPE = $CLIENT_RELEASE_TYPE 186 | 187 | # Default: "$CLIENT_NAME Server $MODPACK_VERSION" 188 | $SERVER_ZIP_NAME = "$CLIENT_NAME`Server-$MODPACK_VERSION" 189 | 190 | # Default: $SERVER_FILENAME 191 | $SERVER_FILE_DISPLAY_NAME = "MyModpack Server $MODPACK_VERSION" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /modpack-uploader.ps1: -------------------------------------------------------------------------------- 1 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 2 | 3 | $manifest = "manifest.json" 4 | $minecraftInstanceFile = "minecraftinstance.json" 5 | $overridesFolder = "overrides" 6 | $secretsFile = "secrets.ps1" 7 | 8 | function Validate-SecretsFile { 9 | if (!(Test-Path "$PSScriptRoot/$secretsFile")) { 10 | Write-Host "You need a valid CurseForge API Token in a $secretsFile file" -ForegroundColor Red 11 | Write-Host "Creating $secretsFile" -ForegroundColor Cyan 12 | New-Item -Path $PSScriptRoot -ItemType File -Name $secretsFile -Value "# To generate an API token go to: https://authors.curseforge.com/account/api-tokens `n $CURSEFORGE_TOKEN = `"your-curseforge-token-here`"" 13 | } 14 | } 15 | 16 | . "$PSScriptRoot/settings.ps1" 17 | . "$PSScriptRoot/$secretsFile" 18 | 19 | 20 | function Get-GitHubRelease { 21 | param( 22 | [parameter(Mandatory = $true)] 23 | [string] 24 | $repo, 25 | [parameter(Mandatory = $true)] 26 | [string] 27 | $file 28 | ) 29 | 30 | $response = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases" 31 | 32 | $matchingRelease = $response.assets -match $file 33 | if ($matchingRelease) { 34 | $downloadUrl = $matchingRelease.browser_download_url 35 | 36 | Remove-Item $file -ErrorAction SilentlyContinue 37 | 38 | Write-Host "Dowloading $file..." 39 | 40 | Invoke-RestMethod $downloadUrl -Out $file 41 | } 42 | else { 43 | Write-Error "Found no files matching '$file' in the repository '$repo'" 44 | } 45 | } 46 | 47 | function Test-ForDependencies { 48 | $is7zAvailable = Get-Command 7z 49 | if (-not $is7zAvailable) { 50 | Clear-Host 51 | Write-Host 52 | Write-Host "Install 7zip and add it's folder to the environment variable 'Path'`n" -ForegroundColor Red 53 | Write-Host "7zip can be downloaded here: " -NoNewline 54 | Write-Host "https://www.7-zip.org/download.html" -ForegroundColor Blue 55 | Write-Host 56 | Write-Host "When you're done, rerun this script.`n" 57 | 58 | throw "7zip not command available. Please follow the instructions above." 59 | } 60 | 61 | $isCurlAvailable = Get-Command $curl 62 | 63 | if (-not $isCurlAvailable) { 64 | Clear-Host 65 | Write-Host 66 | Write-Host "Install Curl and add it's folder to the environment variable 'Path'`n" -ForegroundColor Red 67 | Write-Host "Curl can be downloaded here: " -NoNewline 68 | Write-Host "https://curl.se/download.html" -ForegroundColor Blue 69 | Write-Host "To install it, simply unzip the folder somewhere and point path to it." 70 | Write-Host 71 | Write-Host "When you're done, rerun this script.`n" 72 | 73 | throw "curl not available. Please follow the instructions above." 74 | } 75 | } 76 | 77 | function New-ClientFiles { 78 | if ($ENABLE_CLIENT_FILE_MODULE) { 79 | Write-Host 80 | Write-Host "Creating Client Files..." -ForegroundColor Cyan 81 | Write-Host 82 | 83 | $clientZip = "$CLIENT_ZIP_NAME.zip" 84 | 85 | Remove-Item $clientZip -Recurse -Force -ErrorAction SilentlyContinue 86 | 87 | 88 | New-ManifestJson 89 | 90 | if (Test-Path -PathType Container $overridesFolder) { 91 | Write-Host "The folder 'overrides' will be removed by manifest generation." -ForegroundColor Red 92 | Write-Host "Press any key to proceed, CTRL + C To cancel." 93 | pause 94 | } 95 | 96 | Remove-Item $overridesFolder -Force -Recurse -ErrorAction SilentlyContinue 97 | New-Item -ItemType Directory $overridesFolder 98 | 99 | $FOLDERS_TO_INCLUDE_IN_CLIENT_FILES | ForEach-Object { 100 | Write-Host "Adding " -ForegroundColor Cyan -NoNewline 101 | Write-Host $_ -ForegroundColor Blue -NoNewline 102 | Write-Host " to client files." -ForegroundColor Cyan 103 | $destinationFolder = "$overridesFolder/$_" | Split-Path 104 | if (!(Test-Path -Path $destinationFolder)) { 105 | New-Item $destinationFolder -Type Directory 106 | } 107 | Copy-Item -Path $_ -Destination "$overridesFolder/$_" -Recurse 108 | } 109 | 110 | $destinationFolder = "$overridesFolder/mods" 111 | if (!(Test-Path -Path $destinationFolder)) { 112 | New-Item $destinationFolder -Type Directory 113 | } 114 | $FILES_TO_INCLUDE_IN_MODS_FOLDER_IN_CLIENT_FILES | ForEach-Object { 115 | Write-Host "Adding " -ForegroundColor Cyan -NoNewline 116 | Write-Host $_ -ForegroundColor Blue -NoNewline 117 | Write-Host " to the mods folder in the client files." -ForegroundColor Cyan 118 | Copy-Item -Path $_ -Destination "$overridesFolder/$_" -Recurse 119 | } 120 | 121 | Remove-BlacklistedFiles 122 | 123 | # Zipping up the newly created overrides folder and $manifest 124 | 7z a $clientZip ($overridesFolder, $manifest) -r -sdel 125 | 126 | Remove-Item $manifest -Force -Recurse -ErrorAction SilentlyContinue 127 | Write-Host "Client files $clientZip created!" -ForegroundColor Green 128 | 129 | } 130 | } 131 | 132 | function New-ManifestJson { 133 | if (!(Test-Path $minecraftInstanceFile)) { 134 | Write-Host "Generating a $manifest requires a $minecraftInstanceFile file." -ForegroundColor Red 135 | } 136 | 137 | $minecraftInstanceJson = Get-Content $minecraftInstanceFile | ConvertFrom-Json 138 | 139 | $mods = [System.Collections.ArrayList]@() 140 | foreach ($addon in $minecraftInstanceJson.installedAddons) { 141 | $mods.Add(@{ 142 | required = $true 143 | projectID = $addon.addonID 144 | fileID = $addon.installedFile.id 145 | downloadUrl = $addon.installedFile.downloadUrl 146 | }) > $null 147 | } 148 | 149 | $modloaderId = $minecraftInstanceJson.baseModLoader.name 150 | 151 | if ($MODLOADER -eq "fabric") { 152 | # Example output: "fabric-0.13.3-1.18.1" 153 | $splitModloaderId = $modloaderId -split "-" 154 | # Only keep "fabric-0.13.3" 155 | $modloaderId = $splitModloaderId[0] + "-" + $splitModloaderId[1] 156 | } 157 | 158 | $jsonOutput = @{ 159 | minecraft = @{ 160 | version = $minecraftInstanceJson.baseModLoader.minecraftVersion 161 | modLoaders = @(@{ 162 | id = $modloaderId 163 | primary = $true 164 | }) 165 | } 166 | manifestType = "minecraftModpack" 167 | manifestVersion = 1 168 | name = $MODPACK_NAME 169 | version = $MODPACK_VERSION 170 | author = $CLIENT_FILE_AUTHOR 171 | files = $mods 172 | overrides = "overrides" 173 | } 174 | 175 | Remove-Item $manifest -Force -Recurse -ErrorAction SilentlyContinue 176 | $jsonString = $jsonOutput | ConvertTo-Json -Depth 3 177 | $outfile = "$INSTANCE_ROOT/$manifest" 178 | [System.IO.File]::WriteAllLines($outfile, $jsonString) 179 | Write-Host "$manifest created!" -ForegroundColor Green 180 | } 181 | 182 | function Remove-BlacklistedFiles { 183 | if ($ENABLE_CLIENT_FILE_MODULE -or $ENABLE_SERVER_FILE_MODULE) { 184 | $FOLDERS_TO_REMOVE_FROM_CLIENT_FILES | ForEach-Object { 185 | Write-Host "Removing overrides/$_" 186 | Remove-Item -Path "overrides/$_" -Recurse -ErrorAction SilentlyContinue 187 | } 188 | 189 | $CONFIGS_TO_REMOVE_FROM_CLIENT_FILES | ForEach-Object { 190 | Write-Host "Removing overrides/config/$_" 191 | Remove-Item -Path "overrides/config/$_" -Recurse -ErrorAction SilentlyContinue 192 | } 193 | 194 | Write-Host "Removing all .bak files from overrides" -ForegroundColor Cyan 195 | Get-ChildItem "overrides/*.bak" | ForEach-Object { 196 | Write-Host "Removing $($_.FullName)" 197 | Remove-Item -Path $_.FullName -Force -ErrorAction SilentlyContinue 198 | } 199 | } 200 | } 201 | 202 | function New-Changelog { 203 | if ($ENABLE_CHANGELOG_GENERATOR_MODULE ` 204 | -and $null -ne $MODPACK_VERSION ` 205 | -and $null -ne $LAST_MODPACK_VERSION ` 206 | -and (Test-Path "$INSTANCE_ROOT/$LAST_MODPACK_ZIP_NAME.zip") ` 207 | -and (Test-Path "$INSTANCE_ROOT/$CLIENT_ZIP_NAME.zip") 208 | ) { 209 | if (-not (Test-Path $CHANGELOG_GENERATOR_JAR) -or $ENABLE_ALWAYS_UPDATE_JARS) { 210 | Remove-Item $CHANGELOG_GENERATOR_JAR -Recurse -Force -ErrorAction SilentlyContinue 211 | Get-GitHubRelease -repo "ModdingX/ModListCreator" -file $CHANGELOG_GENERATOR_JAR 212 | } 213 | Write-Host 214 | Write-Host "Generating mod changelog..." -ForegroundColor Cyan 215 | Write-Host 216 | 217 | Remove-Item $CHANGELOG_PATH -ErrorAction SilentlyContinue 218 | 219 | java -jar $CHANGELOG_GENERATOR_JAR ` 220 | changelog ` 221 | --output $CHANGELOG_PATH ` 222 | --new "$CLIENT_ZIP_NAME.zip" ` 223 | --old "$LAST_MODPACK_ZIP_NAME.zip" 224 | 225 | Write-Host "Mod changelog generated!" -ForegroundColor Green 226 | } 227 | } 228 | 229 | function Push-ClientFiles { 230 | if ($ENABLE_MODPACK_UPLOADER_MODULE) { 231 | 232 | if ($ENABLE_CLIENT_FILE_MODULE -eq $false) { 233 | Remove-BlacklistedFiles 234 | } 235 | 236 | # This ugly json seems to be a necessity, 237 | # I have yet to get @{} and ConvertTo-Json to work with the CurseForge Upload API 238 | $CLIENT_METADATA = 239 | "{ 240 | changelog: `'$CLIENT_CHANGELOG`', 241 | changelogType: `'$CLIENT_CHANGELOG_TYPE`', 242 | displayName: `'$CLIENT_FILE_DISPLAY_NAME`', 243 | gameVersions: [$GAME_VERSIONS], 244 | releaseType: `'$CLIENT_RELEASE_TYPE`' 245 | }" 246 | 247 | Write-Host 248 | Write-Host "Client Metadata:" -ForegroundColor Cyan 249 | Write-Host 250 | Write-Host $CLIENT_METADATA -ForegroundColor Blue 251 | 252 | Write-Host 253 | Write-Host "Uploading client files to https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" -ForegroundColor Green 254 | Write-Host 255 | 256 | $response = & $curl ` 257 | --url "https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" ` 258 | --user "$CURSEFORGE_USER`:$CURSEFORGE_TOKEN" ` 259 | -H "Accept: application/json" ` 260 | -H X-Api-Token:$CURSEFORGE_TOKEN ` 261 | -F metadata=$CLIENT_METADATA ` 262 | -F file=@"$CLIENT_ZIP_NAME.zip" ` 263 | --progress-bar | ConvertFrom-Json 264 | 265 | 266 | $clientFileReturnId = $response.id 267 | 268 | if (-not $response.id) { 269 | Write-Host "Failed to upload client files: $response" -ForegroundColor Red 270 | throw "Failed to upload client files: $response" 271 | } 272 | 273 | Write-Host 274 | Write-Host "Uploaded modpack!" -ForegroundColor Green 275 | Write-Host 276 | Write-Host "Return Id: $clientFileReturnId" -ForegroundColor Cyan 277 | Write-Host 278 | 279 | if ($ENABLE_SERVERSTARTER_MODULE) { 280 | Update-FileLinkInServerFiles -ClientFileReturnId $clientFileReturnId 281 | } 282 | } 283 | } 284 | 285 | function Update-FileLinkInServerFiles { 286 | param( 287 | [int]$ClientFileReturnId 288 | ) 289 | if ($clientFileReturnId) { 290 | $clientFileIdString = $clientFileReturnId.toString() 291 | $idPart1 = $clientFileIdString.Substring(0, 4) 292 | $idPart1 = Remove-LeadingZero -text $idPart1 293 | $idPart2 = $clientFileIdString.Substring(4, $clientFileIdString.length - 4) 294 | $idPart2 = Remove-LeadingZero -text $idPart2 295 | # CurseForge replaces whitespace in filenames with + in their CDN urls 296 | $sanitizedClientZipName = $CLIENT_ZIP_NAME.Replace(" ", "+") 297 | $curseForgeCdnUrl = "https://edge.forgecdn.net/files/$idPart1/$idPart2/$sanitizedClientZipName.zip" 298 | $content = (Get-Content -Path $SERVER_SETUP_CONFIG_PATH) -replace "https://edge.forgecdn.net/files/\d+/\d+/.*.zip", $curseForgeCdnUrl 299 | [System.IO.File]::WriteAllLines(($SERVER_SETUP_CONFIG_PATH | Resolve-Path), $content) 300 | 301 | if ($ENABLE_SERVER_FILE_MODULE) { 302 | New-ServerFiles -ClientFileReturnId $clientFileReturnId 303 | } 304 | } 305 | } 306 | 307 | function New-ServerFiles { 308 | param( 309 | [int]$ClientFileReturnId 310 | ) 311 | if ($ENABLE_SERVER_FILE_MODULE) { 312 | $serverZip = "$SERVER_ZIP_NAME.zip" 313 | Remove-Item $serverZip -Force -ErrorAction SilentlyContinue 314 | Write-Host 315 | Write-Host "Creating server files..." -ForegroundColor Cyan 316 | Write-Host 317 | 7z a -tzip $serverZip "$SERVER_FILES_FOLDER/*" 318 | Move-Item -Path "automation/$serverZip" -Destination $serverZip -ErrorAction SilentlyContinue 319 | Write-Host "Server files created!" -ForegroundColor Green 320 | 321 | if ($ENABLE_MODPACK_UPLOADER_MODULE) { 322 | Push-ServerFiles -clientFileReturnId $clientFileReturnId 323 | } 324 | } 325 | } 326 | 327 | function Push-ServerFiles { 328 | param( 329 | [int]$clientFileReturnId 330 | ) 331 | if ($ENABLE_SERVER_FILE_MODULE -and $ENABLE_MODPACK_UPLOADER_MODULE) { 332 | $serverFilePath = "$SERVER_ZIP_NAME.zip" 333 | 334 | $SERVER_METADATA = 335 | "{ 336 | 'changelog': `'$SERVER_CHANGELOG`', 337 | 'changelogType': `'$SERVER_CHANGELOG_TYPE`', 338 | 'displayName': `'$SERVER_FILE_DISPLAY_NAME`', 339 | 'parentFileId': $clientFileReturnId, 340 | 'releaseType': `'$SERVER_RELEASE_TYPE`' 341 | }" 342 | 343 | Write-Host 344 | Write-Host "Uploading server files..." -ForegroundColor Cyan 345 | Write-Host 346 | 347 | $serverFileResponse = & $curl ` 348 | --url "https://minecraft.curseforge.com/api/projects/$CURSEFORGE_PROJECT_ID/upload-file" ` 349 | --user "$CURSEFORGE_USER`:$CURSEFORGE_TOKEN" ` 350 | -H "Accept: application/json" ` 351 | -H X-Api-Token:$CURSEFORGE_TOKEN ` 352 | -F metadata=$SERVER_METADATA ` 353 | -F file=@$serverFilePath ` 354 | --progress-bar | ConvertFrom-Json 355 | 356 | if ($serverFileResponse.errorCode) { 357 | throw "Failed to upload server files: $serverFileResponse" 358 | } 359 | 360 | if ($serverFileResponse.id) { 361 | Write-Host "Uploaded server files!" -ForegroundColor Green 362 | } 363 | } 364 | } 365 | 366 | function New-GitHubRelease { 367 | if ($ENABLE_GITHUB_RELEASE_MODULE) { 368 | 369 | $Base64Token = [System.Convert]::ToBase64String([char[]]$GITHUB_TOKEN); 370 | $Uri = "https://api.github.com/repos/$GITHUB_NAME/$GITHUB_REPOSITORY/releases?access_token=$GITHUB_TOKEN" 371 | 372 | $Headers = @{ 373 | Authorization = 'Basic {0}' -f $Base64Token; 374 | }; 375 | 376 | $Body = @{ 377 | tag_name = $MODPACK_VERSION 378 | name = $MODPACK_VERSION 379 | generate_release_notes = $true 380 | } | ConvertTo-Json 381 | 382 | 383 | Write-Host 384 | Write-Host "Making GitHub Release..." -ForegroundColor Green 385 | Write-Host 386 | 387 | Invoke-RestMethod -Headers $Headers -Uri $Uri -Body $Body -Method Post 388 | 389 | Start-Process Powershell.exe -Argument "-NoProfile -Command github_changelog_generator" 390 | } 391 | } 392 | 393 | function Update-Modlist { 394 | if ($ENABLE_MODLIST_CREATOR_MODULE) { 395 | if (-not (Test-Path $MODLIST_CREATOR_JAR) -or $ENABLE_ALWAYS_UPDATE_JARS) { 396 | Remove-Item $MODLIST_CREATOR_JAR -Recurse -Force -ErrorAction SilentlyContinue 397 | Get-GitHubRelease -repo "ModdingX/ModListCreator" -file $MODLIST_CREATOR_JAR 398 | } 399 | 400 | Write-Host 401 | Write-Host "Generating Modlist..." 402 | Write-Host 403 | 404 | Remove-Item $MODLIST_PATH -ErrorAction SilentlyContinue 405 | java -jar $MODLIST_CREATOR_JAR modlist --output $MODLIST_PATH --detailed "$CLIENT_ZIP_NAME.zip" 406 | Copy-Item -Path $MODLIST_PATH -Destination "$INSTANCE_ROOT/MODLIST.md" 407 | } 408 | } 409 | 410 | function Remove-LeadingZero { 411 | param( 412 | [string]$text 413 | ) 414 | return [int]$text 415 | } 416 | 417 | $startLocation = Get-Location 418 | Set-Location $INSTANCE_ROOT 419 | 420 | if ($null -eq $IsWindows -or $IsWindows) { 421 | # The script is running on Windows, use curl.exe 422 | $curl = "curl.exe" 423 | } 424 | else { 425 | $curl = "curl" 426 | } 427 | 428 | Test-ForDependencies 429 | Validate-SecretsFile 430 | New-ClientFiles 431 | Push-ClientFiles 432 | if ($ENABLE_SERVER_FILE_MODULE -and -not $ENABLE_MODPACK_UPLOADER_MODULE) { 433 | New-ServerFiles 434 | } 435 | New-GitHubRelease 436 | New-Changelog 437 | Update-Modlist 438 | 439 | Write-Host "Modpack Upload Complete!" -ForegroundColor Green 440 | Set-Location $startLocation 441 | 442 | pause 443 | --------------------------------------------------------------------------------