curseforge-modpack-downloader.sh 2.2 KB

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