From 53bfe468bf610e270d2191395aa4adfc25063c0b Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Sun, 15 Aug 2021 21:38:26 +0000 Subject: [PATCH] Basic error checks --- gofile.io-dl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gofile.io-dl b/gofile.io-dl index 6fd071b..13c179b 100755 --- a/gofile.io-dl +++ b/gofile.io-dl @@ -1,6 +1,8 @@ #!/bin/bash set -f # No globbing set -C # No clobbering +set -e +set -o pipefail printurls= if [[ "$1" == '--urls' ]] @@ -17,7 +19,7 @@ then fi function printurl { - [[ "${printurls}" ]] && echo "$1" + if [[ "${printurls}" ]]; then echo "$1"; fi } if [[ $# -ne 1 || ( ! "$1" =~ ^https://gofile\.io/d/[0-9a-zA-Z]+$ && ! "$1" =~ ^https://gofile\.io/\?c=[0-9a-zA-Z]+$ ) ]] @@ -37,7 +39,7 @@ fi folderUrl="https://api.gofile.io/getFolder?folderId=${code}" printurl "${folderUrl}" -curl -s "${folderUrl}" | python3 -c 'import json,sys; obj = json.loads(sys.stdin.read().strip())'$'\n''for f in obj["data"]["contents"].values():'$'\n'' print(f["size"], f["md5"], f["name"], f["link"])' | \ +curl -s --fail "${folderUrl}" | python3 -c 'import json,sys; obj = json.loads(sys.stdin.read().strip())'$'\n''for f in obj["data"]["contents"].values():'$'\n'' print(f["size"], f["md5"], f["name"], f["link"])' | \ while read -r size md5 name link do if [[ "${name}" == *'/'* || "${link}" == *' '* || ! "${link}" =~ ^https://((srv-)?file[0-9]+|srv-store[0-9]+)\.gofile\.io/download/ ]]