2017-03-28 16:41:41 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
|
|
|
|
#
|
|
|
|
# \brief Simulate the download of files by copying content from a directory
|
|
|
|
# \author Norman Feske
|
|
|
|
# \date 2017-03-23
|
|
|
|
#
|
|
|
|
|
|
|
|
export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../../..)
|
|
|
|
|
|
|
|
REMOTE_DIR ?= $(GENODE_DIR)/remote
|
|
|
|
PUBLIC_DIR ?= $(GENODE_DIR)/public
|
|
|
|
DEPOT_DIR ?= $(GENODE_DIR)/depot
|
|
|
|
|
|
|
|
define HELP_MESSAGE
|
|
|
|
|
|
|
|
Simulate the download of files by copying content from a directory
|
|
|
|
|
|
|
|
usage:
|
|
|
|
|
|
|
|
$(firstword $(MAKEFILE_LIST)) <archive-path>...
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
include $(GENODE_DIR)/tool/depot/mk/front_end.inc
|
|
|
|
|
|
|
|
TARGETS := $(addprefix $(DEPOT_DIR)/,$(MAKECMDGOALS))
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Unpack after checking signature against public key as stored in the depot
|
|
|
|
#
|
|
|
|
# Unfortunately, gpg does not allow us to specify the armored public-key
|
|
|
|
# file directly as keyring for the verify operation. So we need to create a
|
|
|
|
# temporary dearmored version.
|
|
|
|
#
|
|
|
|
|
|
|
|
ARCHIVES := $(MAKECMDGOALS)
|
|
|
|
|
|
|
|
include $(GENODE_DIR)/tool/depot/mk/gpg.inc
|
|
|
|
|
2017-12-11 15:49:23 +00:00
|
|
|
$(DEPOT_DIR)/% : $(PUBLIC_DIR)/%.tar.xz $(PUBLIC_DIR)/%.tar.xz.sig
|
2017-03-28 16:41:41 +00:00
|
|
|
$(VERBOSE)pubkey_file=$(DEPOT_DIR)/$(call archive_user,$*)/pubkey; \
|
2018-09-21 11:48:33 +00:00
|
|
|
$(GPG) --yes -o $$pubkey_file.dearmored --dearmor $$pubkey_file; \
|
|
|
|
( $(GPG) --no-tty --no-default-keyring \
|
2017-03-28 16:41:41 +00:00
|
|
|
--keyring $$pubkey_file.dearmored \
|
2017-12-11 15:49:23 +00:00
|
|
|
--verify $(PUBLIC_DIR)/$*.tar.xz.sig 2> /dev/null; retval=$$?; \
|
2017-03-28 16:41:41 +00:00
|
|
|
rm -f $$pubkey_file.dearmored; \
|
|
|
|
exit $$retval \
|
|
|
|
) || ( echo -e "Error: could not verify '$*', signature does not match\n" \
|
|
|
|
" public key '$$pubkey_file'"; \
|
|
|
|
false )
|
|
|
|
$(VERBOSE)mkdir -p $(dir $@)
|
2017-12-11 15:49:23 +00:00
|
|
|
$(VERBOSE)tar xfJ $(PUBLIC_DIR)/$*.tar.xz -C $(dir $@)
|
2017-03-28 16:41:41 +00:00
|
|
|
|
2017-12-11 15:49:23 +00:00
|
|
|
DOWNLOADED_FILES := $(addprefix $(PUBLIC_DIR)/,$(MAKECMDGOALS:=.tar.xz)) \
|
|
|
|
$(addprefix $(PUBLIC_DIR)/,$(MAKECMDGOALS:=.tar.xz.sig))
|
2017-03-28 16:41:41 +00:00
|
|
|
|
|
|
|
.PRECIOUS: $(DOWNLOADED_FILES)
|
|
|
|
|
|
|
|
ifneq ($(MISSING_PUBKEY_FILES),)
|
|
|
|
$(DOWNLOADED_FILES): missing_pubkey_files
|
|
|
|
endif
|
|
|
|
|
2017-05-30 12:15:35 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Determine download URLs of all origins of the specified archives
|
|
|
|
#
|
|
|
|
# The 'ORIGINS' variable contains all users found in the arguments. The
|
|
|
|
# URL information is obtained from the despective depot/<user>/download
|
|
|
|
# file and cached in the 'URL(<user>)' variable. The 'file_url' function
|
|
|
|
# assesses the 'URL' variables to return the complete URL for a given
|
|
|
|
# relative archive (or signature file) path.
|
|
|
|
#
|
|
|
|
|
|
|
|
ORIGINS := $(sort $(foreach A,$(ARCHIVES),$(call archive_user,$A)))
|
|
|
|
|
|
|
|
quotation_sanitized = $(subst ',,$(strip $1))
|
|
|
|
|
|
|
|
$(foreach O,$(ORIGINS),\
|
|
|
|
$(eval URL($O) := \
|
|
|
|
$(call quotation_sanitized,\
|
|
|
|
$(call file_content,$(DEPOT_DIR)/$O/download))))
|
|
|
|
|
|
|
|
MISSING_DOWNLOAD_LOCATIONS := $(sort $(foreach O,$(ORIGINS),\
|
|
|
|
$(if ${URL($O)},,$(DEPOT_DIR)/$O/download)))
|
|
|
|
|
|
|
|
ifneq ($(MISSING_DOWNLOAD_LOCATIONS),)
|
|
|
|
$(DOWNLOADED_FILES): missing_download_locations
|
|
|
|
endif
|
|
|
|
|
|
|
|
missing_download_locations:
|
|
|
|
@echo "Error: missing or invalid download location:";\
|
|
|
|
for i in $(MISSING_DOWNLOAD_LOCATIONS); do echo " $$i"; done; false
|
|
|
|
|
|
|
|
file_url = '${URL($(call archive_user,$1))}/$1'
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Download rule that is invoked per file
|
|
|
|
#
|
|
|
|
|
2017-03-28 16:41:41 +00:00
|
|
|
$(PUBLIC_DIR)/%:
|
|
|
|
@$(ECHO) "$(DARK_COL)download$(DEFAULT_COL) $*"
|
|
|
|
$(VERBOSE)mkdir -p $(dir $@)
|
2017-05-30 12:15:35 +00:00
|
|
|
$(VERBOSE)wget --quiet --no-check-certificate $(call file_url,$*) -O $@ ||\
|
|
|
|
(echo "Error: failed to download $(call file_url,$*)"; rm -f $@; false)
|
2017-03-28 16:41:41 +00:00
|
|
|
|
|
|
|
$(MAKECMDGOALS): $(TARGETS)
|
|
|
|
@true
|