summaryrefslogtreecommitdiffstats
path: root/tools/depends/download-files.include
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /tools/depends/download-files.include
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/depends/download-files.include')
-rw-r--r--tools/depends/download-files.include59
1 files changed, 59 insertions, 0 deletions
diff --git a/tools/depends/download-files.include b/tools/depends/download-files.include
new file mode 100644
index 0000000..3f41dfa
--- /dev/null
+++ b/tools/depends/download-files.include
@@ -0,0 +1,59 @@
+#
+HASH_FOUND = yes
+ifneq ($(SHA512),)
+ HASH_TYPE = sha512
+ HASH_TOOL ?= $(SHA512SUM)
+else ifneq ($(SHA256),)
+ HASH_TYPE = sha256
+ HASH_TOOL ?= $(SHA256SUM)
+else
+ HASH_FOUND = no
+ HASH_TYPE = sha512
+ HASH_TOOL = sha512sum
+endif
+
+SED_FLAG = -i
+ifeq ($(NATIVE_OS), osx)
+ HASH_TOOL = $(SHASUM) -a $(shell echo $(HASH_TYPE) | sed 's/^sha//')
+ SED_FLAG = -i ''
+endif
+
+# non-depends builds might not set this, use defaults
+ifeq ($(HASH_TOOL),)
+ HASH_TOOL = sha512sum
+ HASH_TOOL_FLAGS = -c --status
+endif
+
+HASH_SUM = $($(shell echo $(HASH_TYPE) | tr '[:lower:]' '[:upper:]'))
+
+.PHONY: $(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE)
+all: $(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE)
+
+$(TARBALLS_LOCATION)/$(ARCHIVE):
+ cd $(TARBALLS_LOCATION); $(RETRIEVE_TOOL) $(RETRIEVE_TOOL_FLAGS) $(BASE_URL)/$(ARCHIVE)
+
+$(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE): $(TARBALLS_LOCATION)/$(ARCHIVE)
+ifeq ($(HASH_FOUND),no)
+ cd $(TARBALLS_LOCATION); $(HASH_TOOL) $(ARCHIVE) > $(ARCHIVE).$(HASH_TYPE)
+ $(HASH_TYPE)=$$(cat $(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE) | cut -d ' ' -f 1) && \
+ sed $(SED_FLAG) -e "s/#SHA512#/SHA512=$${sha512}/" -e "s/#SHA256#/SHA256=$${sha256}/" Makefile
+endif
+ifeq ($(HASH_FOUND),yes)
+# we really need 2 spaces between sha hash and file name!
+# if the hash sum doesn't match we retry up to 3 times, add verbose curl output for diagnostics on retries
+# if we fail 3 times, cleanup anything downloaded (eg bad tar)
+ @cd $(TARBALLS_LOCATION); echo "$(HASH_SUM) $(ARCHIVE)" > $(ARCHIVE).$(HASH_TYPE) && $(HASH_TOOL) $(HASH_TOOL_FLAGS) $(ARCHIVE).$(HASH_TYPE) \
+ || {\
+ echo "Error: failed to verify hash sum of $(ARCHIVE), expected type: $(HASH_TYPE) value $(HASH_SUM), retrying.." ;\
+ tries=1 ;\
+ while [ $$tries -le 3 ]; do \
+ echo "download $(ARCHIVE) retry $$tries" ;\
+ rm $(TARBALLS_LOCATION)/$(ARCHIVE) ;\
+ sleep 3 ;\
+ $(RETRIEVE_TOOL) $(RETRIEVE_TOOL_FLAGS) -v $(BASE_URL)/$(ARCHIVE) ;\
+ $(HASH_TOOL) $(HASH_TOOL_FLAGS) $(ARCHIVE).$(HASH_TYPE) && exit 0 || tries=$$((tries + 1)) ;\
+ done ;\
+ rm $(TARBALLS_LOCATION)/$(ARCHIVE) ;\
+ exit 1 ;\
+ }
+endif