install-mods.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #/bin/sh
  2. cd mods/
  3. clean_added_jars() {
  4. for i in *.jar.added; do
  5. mv -- "$i" "${i%%.added}"
  6. done
  7. }
  8. clean_added_jars
  9. echo "==========================="
  10. echo "Processing mods/"
  11. echo "==========================="
  12. for file in *.toml; do
  13. echo
  14. echo "Processing $file"
  15. download_mode="$(grep 'mode' < "$file" | cut -d' ' -f3)"
  16. # remove double quotes
  17. download_mode="${download_mode#\"}"
  18. download_mode="${download_mode%\"}"
  19. filename="$(grep 'filename' < "$file" | cut -d' ' -f3-)"
  20. # remove double quotes
  21. filename="${filename#\"}"
  22. filename="${filename%\"}"
  23. if [ "$download_mode" = 'metadata:curseforge' ]; then
  24. file_id="$(grep 'file-id' < "$file" | cut -d' ' -f3)"
  25. # remove double quotes
  26. file_id="${file_id#\"}"
  27. file_id="${file_id%\"}"
  28. url="https://edge.forgecdn.net/files/$(printf '%s' "$file_id" | cut -c1-4)/$(printf '%s' "$file_id" | cut -c5-7)/$filename"
  29. else
  30. url="$(grep 'url' < "$file" | cut -d' ' -f3)"
  31. # remove double quotes
  32. url="${url#\"}"
  33. url="${url%\"}"
  34. fi
  35. if [ -e "$filename" ]; then
  36. echo "$filename exists, skipping..."
  37. else
  38. echo "$filename from $url"
  39. curl -L "$url" -o "$filename"
  40. fi
  41. mv "$filename" "${filename}.added"
  42. done
  43. printf 'Processed %s .jar files and %s .pw.toml files\n' "$(ls *.jar.added | wc --lines)" "$(ls *.pw.toml | wc --lines)"
  44. echo "Unrecognized JAR files:"
  45. ls *.jar
  46. clean_added_jars