curseforge-modpack-downloader.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. # Copyright 2015-2021 Rivoreo
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining
  5. # a copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish,
  8. # distribute, sublicense, and/or sell copies of the Software, and to
  9. # permit persons to whom the Software is furnished to do so, subject to
  10. # the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. if [ $# -lt 1 ]; then
  23. echo "Usage: curseforge-modpack-downloader manifest.json"
  24. exit 1
  25. fi
  26. # checking if jq(1) exist
  27. if ! command -v jq > /dev/null 2>&1; then
  28. printf "jq is not detected\\n"
  29. exit
  30. fi
  31. # checking if wget exist
  32. if ! command -v wget > /dev/null 2>&1; then
  33. printf "wget is not detected\\n"
  34. exit
  35. fi
  36. # creating mods/ directory
  37. mkdir -p mods
  38. MODS_AMOUNT="`jq '.files|length' \"$1\"`"
  39. echo "There are $MODS_AMOUNT mods in total."
  40. i=0
  41. while [ $i -lt $MODS_AMOUNT ]; do
  42. if [ "`jq \".files[$i].required\" \"$1\"`" = "true" ]; then
  43. projectID="`jq \".files[$i].projectID\" \"$1\"`"
  44. fileID="`jq \".files[$i].fileID\" \"$1\"`"
  45. API_RESULT="`wget --quiet -O - \"https://addons-ecs.forgesvc.net/api/v2/addon/$projectID/file/$fileID\"`"
  46. MOD_URL="`printf %s "$API_RESULT" | jq --raw-output .downloadUrl`"
  47. MOD_NAME="`printf %s "$API_RESULT" | jq --raw-output .displayName`"
  48. printf %s\\n "Downloading $MOD_NAME ... $((MODS_AMOUNT-i-1)) mods remaining ..."
  49. wget --show-progress --no-clobber --directory-prefix mods/ "$MOD_URL"
  50. # curseforge reject --continue. since we can't continue download a file, may be we should skip any existing file (assuming they are complete)
  51. fi
  52. i=$((i+1))
  53. done