Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Create Makefile for churn
Put the churn update in the Makefile. As this required more previsible behavior of the certificate and cache, most of the Makefile has been rewritten.
- Loading branch information
Showing
1 changed file
with
58 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,78 @@ | ||
.PHONY: dirinfo check-password | ||
.PHONY: churn clean clean_cert clean_cache secrets_authority update_cache_churn | ||
|
||
AUTH_DIR=authority-private | ||
DIR_CACHE=directory-cache | ||
AUTH_ID=$(AUTH_DIR)/authority_identity_key | ||
AUTH_SIGN=$(AUTH_DIR)/authority_signing_key | ||
AUTH_CERT=$(AUTH_DIR)/certificate.txt | ||
AUTH_AUTH=$(AUTH_DIR)/authority.txt | ||
CACHE_DIR=directory-cache | ||
CACHE_CERT=$(CACHE_DIR)/certificate.txt | ||
CACHE_AUTH=$(CACHE_DIR)/authority.txt | ||
CACHE_CONS=$(CACHE_DIR)/consensus.txt | ||
CACHE_MICRO=$(CACHE_DIR)/microdescriptors.txt | ||
|
||
all: dirinfo | ||
all: update_cache | ||
|
||
$(AUTH_DIR): pip_install check-password | ||
clean_cert: | ||
rm -rf $(AUTH_DIR) | ||
|
||
certificates: pip_install $(AUTH_ID) $(AUTH_SIGN) $(AUTH_CERT) $(AUTH_AUTH) | ||
$(AUTH_DIR)/%: | ||
ifeq ($(DIR_AUTH_PASSWORD), ) | ||
$(error Environment variable DIR_AUTH_PASSWORD is undefined or invalid.) | ||
endif | ||
mkdir -p $(AUTH_DIR) | ||
mkdir -p $(DIR_CACHE) | ||
./gen_fresh_dirinfo.py generate-certificate \ | ||
--authority-identity-key $(AUTH_DIR)/authority_identity_key \ | ||
--authority-signing-key $(AUTH_DIR)/authority_signing_key \ | ||
--authority-certificate $(DIR_CACHE)/certificate.txt \ | ||
--authority-v3ident $(DIR_CACHE)/authority.txt | ||
--authority-identity-key $(AUTH_ID) \ | ||
--authority-signing-key $(AUTH_SIGN) \ | ||
--authority-certificate $(AUTH_CERT) \ | ||
--authority-v3ident $(AUTH_AUTH) | ||
|
||
clean_cache: | ||
rm -rf $(CACHE_DIR) | ||
|
||
update_cache: clean_cache cache | ||
|
||
dirinfo: $(AUTH_DIR) | ||
cache: $(CACHE_CERT) $(CACHE_AUTH) $(CACHE_CONS) $(CACHE_MICRO) | ||
$(CACHE_DIR)/%: certificates | ||
cp $(AUTH_CERT) $(AUTH_AUTH) $(CACHE_DIR) | ||
./gen_fresh_dirinfo.py generate-dirinfo \ | ||
--authority-signing-key $(AUTH_DIR)/authority_signing_key \ | ||
--authority-certificate $(DIR_CACHE)/certificate.txt \ | ||
--consensus $(DIR_CACHE)/consensus.txt \ | ||
--microdescriptors $(DIR_CACHE)/microdescriptors.txt | ||
--authority-signing-key $(AUTH_SIGN) \ | ||
--authority-certificate $(CACHE_CERT) \ | ||
--consensus $(CACHE_CONS) \ | ||
--microdescriptors $(CACHE_MICRO) | ||
|
||
churn: $(DIR_CACHE)/consensus.txt | ||
churn: cache | ||
./gen_fresh_dirinfo.py compute-churn \ | ||
--consensus $(DIR_CACHE)/consensus.txt \ | ||
--churn $(DIR_CACHE)/churn.txt | ||
--consensus $(CACHE_DIR)/consensus.txt \ | ||
--churn $(CACHE_DIR)/churn.txt | ||
|
||
pip_install: requirements.txt | ||
pip3 install -qr requirements.txt | ||
touch pip_install | ||
|
||
clean: | ||
rm -rf $(AUTH_DIR) $(DIR_CACHE) | ||
|
||
check-password: | ||
ifeq ($(DIR_AUTH_PASSWORD), ) | ||
$(error Environment variable DIR_AUTH_PASSWORD is undefined or invalid.) | ||
endif | ||
clean: clean_cache clean_cert | ||
|
||
secrets_authority: $(AUTH_DIR) | ||
tar cjf auth.tgz $(AUTH_DIR) $(DIR_CACHE)/{certificate.txt,authority.txt} | ||
tar cjf auth.tgz $(AUTH_DIR) $(CACHE_DIR)/{certificate.txt,authority.txt} | ||
base64 -i auth.tgz | ||
rm auth.tgz | ||
echo $$DIR_AUTH_PASSWORD | ||
|
||
# This updates the CACHE_DIR directory: | ||
# - fully every Monday or if the consensus is missing | ||
# - creating a new churn.txt on every day | ||
# It supposes that the | ||
CHURN_WEEK_FILE = $(CACHE_DIR)/churn_week | ||
CHURN_WEEK := $(shell date +%Y_%W) | ||
update_cache_churn: $(CHURN_WEEK_FILE) | ||
if grep -v $(CHURN_WEEK) $(CHURN_WEEK_FILE); then \ | ||
rm -f $(CACHE_DIR)/*; \ | ||
fi | ||
if [ $$( date +%w ) = 1 ]; then \ | ||
rm -f $(CACHE_DIR)/*; \ | ||
fi | ||
$(MAKE) churn $(CHURN_WEEK_FILE) | ||
|
||
$(CHURN_WEEK_FILE): | ||
echo $(CHURN_WEEK) > $@ |