test: add support for caching busybox-x86_64 binary in ~/.cache
While without a working Internet connection today I ran into the issue
of not being able to run the tests.  This adds a basic caching mechanism
to setup-root.sh which saves busybox-x86_64 in ~/.cache, if available.
DEST ?= ../tenv-root
srcdir ?= ../
+CACHE ?= ~/.cache
ARCH ?= x86_64
FINITBIN ?= ./sbin/finit
@@ -79,11 +80,29 @@ $(dirs):
$(DEST)/bin/$(BBBIN).md5:
cp $(srcdir)/tenv/$(notdir $@) $@
+.PHONY: $(DEST)/bin/$(BBBIN)
$(DEST)/bin/$(BBBIN): $(DEST)/bin/$(BBBIN).md5
- wget -O $@ $(BBURL)
- chmod +x $@
+ @cd $(dir $@)
+ @if ! md5sum --status -c $(BBBIN).md5 2>/dev/null; then \
+ if [ -d $(CACHE) ]; then \
+ echo "Cannot find $(BBBIN), checking $(CACHE) ..."; \
+ cd $(CACHE); \
+ cp $(DEST)/bin/$(BBBIN).md5 .; \
+ if ! md5sum --status -c $(BBBIN).md5; then \
+ echo "No $(BBBIN) available downloading ..."; \
+ wget $(BBURL); \
+ else \
+ echo "Found valid $(BBBIN) in cache!"; \
+ fi; \
+ cp $(BBBIN) $@; \
+ else \
+ echo "Cannot find $(BBBIN), downloading ..."; \
+ wget -O $@ $(BBURL); \
+ fi; \
cd $(dir $@); \
- md5sum -c $(BBBIN).md5
+ md5sum -c $(BBBIN).md5; \
+ fi
+ @chmod +x $@
$(DEST)/bin/chrootsetup.sh:
cp $(srcdir)/tenv/$(notdir $@) $@
