Noah 4 anni fa
parent
commit
4561b1cb76
1 ha cambiato i file con 17 aggiunte e 19 eliminazioni
  1. 17 19
      curseforge-modpack-downloader.sh

+ 17 - 19
curseforge-modpack-downloader.sh

@@ -1,6 +1,7 @@
 #!/bin/sh
 
 # Copyright 2015-2021 Rivoreo
+# Copyright 2021 noahvogt
 #
 # Permission is hereby granted, free of charge, to any person obtaining
 # a copy of this software and associated documentation files (the
@@ -21,36 +22,33 @@
 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-if [ $# -lt 1 ]; then
+# check arguments
+if [ -z "$1" ]; then
 	echo "Usage: curseforge-modpack-downloader manifest.json"
 	exit 1
 fi
 
-# checking if jq(1) exist
-if ! command -v jq > /dev/null 2>&1; then
-	printf "jq is not detected\\n"
-	exit
-fi
-# checking if wget exist
-if ! command -v wget > /dev/null 2>&1; then
-	printf "wget is not detected\\n"
-	exit
-fi
+# check dependencies
+for prog in jq wget; do
+    if ! command -v "$prog" > /dev/null 2>&1; then
+        echo "$prog is not detected"; exit 1
+    fi
+done
 
 # creating mods/ directory
 mkdir -p mods
 
-MODS_AMOUNT="`jq '.files|length' \"$1\"`"
+MODS_AMOUNT="$(jq '.files|length' "$1")"
 echo "There are $MODS_AMOUNT mods in total."
 
 i=0
-while [ $i -lt $MODS_AMOUNT ]; do
-	if [ "`jq \".files[$i].required\" \"$1\"`" = "true" ]; then
-		projectID="`jq \".files[$i].projectID\" \"$1\"`"
-		fileID="`jq \".files[$i].fileID\" \"$1\"`"
-		API_RESULT="`wget --quiet -O - \"https://addons-ecs.forgesvc.net/api/v2/addon/$projectID/file/$fileID\"`"
-		MOD_URL="`printf %s "$API_RESULT" | jq --raw-output .downloadUrl`"
-		MOD_NAME="`printf %s "$API_RESULT" | jq --raw-output .displayName`"
+while [ $i -lt "$MODS_AMOUNT" ]; do
+	if [ "$(jq ".files[$i].required" "$1")" = "true" ]; then
+		projectID="$(jq ".files[$i].projectID" "$1")"
+		fileID="$(jq ".files[$i].fileID" "$1")"
+		API_RESULT="$(wget --quiet -O - "https://addons-ecs.forgesvc.net/api/v2/addon/$projectID/file/$fileID")"
+		MOD_URL="$(printf %s "$API_RESULT" | jq --raw-output .downloadUrl)"
+		MOD_NAME="$(printf %s "$API_RESULT" | jq --raw-output .displayName)"
 		printf %s\\n "Downloading $MOD_NAME ... $((MODS_AMOUNT-i-1)) mods remaining ..."
 		wget --show-progress --no-clobber --directory-prefix mods/ "$MOD_URL"
 # curseforge reject --continue. since we can't continue download a file, may be we should skip any existing file (assuming they are complete)