SCRIPT_DIR := .
INPUT_DIR := input
OUTPUT_DIR := output
SOURCES_DIR := ../../assets/repos
MIRRORS_DIR := ../../assets/mirrors
INPUT_FILES := mirrors-alpine.txt mirrors-archlinux.txt mirrors-debian.html \
mirrors-fedora.html mirrors-openeuler.html mirrors-opensuse.html \
mirrors-ubuntu.html
INPUT_FILES_EXIST := $(wildcard $(addprefix $(INPUT_DIR)/, $(INPUT_FILES)))
YAML_FILES := $(wildcard $(SOURCES_DIR)/*.yaml)
DIRS := $(INPUT_DIR) $(OUTPUT_DIR)
STAGE1_OUT := $(OUTPUT_DIR)/official-mirrors.json
STAGE2_OUT := $(OUTPUT_DIR)/ls-mirrors.json
STAGE3_OUT := $(OUTPUT_DIR)/probe-mirrors.json $(OUTPUT_DIR)/noreach-mirrors.txt $(OUTPUT_DIR)/nocontent-mirrors.txt
STAGE4_OUT := $(MIRRORS_DIR)/mirrors.json
EPKG_RUN = epkg run
FETCH_SCRIPT := $(SCRIPT_DIR)/fetch_official_mirrors.py
LIST_SCRIPT := $(SCRIPT_DIR)/ls_mirrors.py
PROBE_SCRIPT := $(SCRIPT_DIR)/probe_dirs.py
MERGE_SCRIPT := $(SCRIPT_DIR)/merge_mirrors.py
.PHONY: help
help:
@echo "Mirror Management System Makefile"
@echo ""
@echo "Available targets:"
@echo " init - Create directories and setup epkg environment"
@echo " all - Run complete pipeline (stages 1-4)"
@echo " stage1 - Fetch new mirrors from official sources"
@echo " stage2 - List directory contents from discovered mirrors"
@echo " stage3 - Probe unknown mirrors for directory structure"
@echo " stage4 - Merge all data into final configuration"
@echo " clean-cache - Clean HTML and LFTP cache files"
@echo " clean - Clean all generated files (except input files)"
@echo " help - Show this help message"
@echo ""
@echo "Usage examples:"
@echo " make init # Create directories and setup environment"
@echo " make all # Run complete pipeline"
@echo " make stage1 # Only fetch new mirrors"
@echo " make stage2 # Only list directories"
.PHONY: init
init: $(DIRS)
@echo "Directories created: $(DIRS)"
@echo "Setting up epkg environment and installing dependencies..."
@if [ ! -d ".eenv" ]; then \
epkg env create --root ".eenv" -c debian; \
else \
echo "epkg environment already exists at .eenv, skipping creation"; \
fi
epkg install python3-pip geoip-database chromium-driver lftp
epkg run pip install -r requirements.txt
@echo "Note: Input mirror lists will be downloaded automatically when stage1 runs"
@echo "Initial setup complete"
$(DIRS):
@mkdir -p $@
.PHONY: all
all: $(STAGE4_OUT)
.PHONY: stage1 fetch
stage1 fetch: $(STAGE1_OUT)
$(STAGE1_OUT): $(FETCH_SCRIPT) $(INPUT_FILES_EXIST) $(DIRS)
@echo "Stage 1: Fetching new mirrors from official sources..."
cd $(SCRIPT_DIR) && $(EPKG_RUN) ./$(notdir $(FETCH_SCRIPT))
@echo "Stage 1 complete: $(STAGE1_OUT) generated"
.PHONY: stage2 list
stage2 list: $(STAGE2_OUT)
$(STAGE2_OUT): $(LIST_SCRIPT) $(STAGE1_OUT) $(YAML_FILES) $(DIRS)
@echo "Stage 2: Listing directory contents from discovered mirrors..."
cd $(SCRIPT_DIR) && $(EPKG_RUN) ./$(notdir $(LIST_SCRIPT))
@echo "Stage 2 complete: $(STAGE2_OUT) updated"
.PHONY: stage3 probe
stage3 probe: $(OUTPUT_DIR)/probe-mirrors.json $(OUTPUT_DIR)/noreach-mirrors.txt $(OUTPUT_DIR)/nocontent-mirrors.txt
$(OUTPUT_DIR)/probe-mirrors.json: $(PROBE_SCRIPT) $(STAGE2_OUT) $(YAML_FILES) $(DIRS)
@echo "Stage 3: Probing unknown mirrors for directory structure..."
cd $(SCRIPT_DIR) && $(EPKG_RUN) ./$(notdir $(PROBE_SCRIPT))
@echo "Stage 3 complete: probe-mirrors.json generated"
$(OUTPUT_DIR)/noreach-mirrors.txt $(OUTPUT_DIR)/nocontent-mirrors.txt: $(OUTPUT_DIR)/probe-mirrors.json
@
@if [ ! -f $(OUTPUT_DIR)/noreach-mirrors.txt ]; then \
echo "Warning: $(OUTPUT_DIR)/noreach-mirrors.txt was not created by probe_dirs.py"; \
fi
@if [ ! -f $(OUTPUT_DIR)/nocontent-mirrors.txt ]; then \
echo "Warning: $(OUTPUT_DIR)/nocontent-mirrors.txt was not created by probe_dirs.py"; \
fi
.PHONY: stage4 merge
stage4 merge: $(STAGE4_OUT)
$(STAGE4_OUT): $(MERGE_SCRIPT) $(STAGE1_OUT) $(STAGE2_OUT) $(word 1, $(STAGE3_OUT)) \
$(YAML_FILES) $(DIRS)
@echo "Stage 4: Merging all data into final configuration..."
cd $(SCRIPT_DIR) && $(EPKG_RUN) ./$(notdir $(MERGE_SCRIPT))
@echo "Stage 4 complete: $(STAGE4_OUT) generated"
.PHONY: clean-cache clean
clean-cache:
@echo "Cleaning HTML and LFTP cache files..."
-rm -f html-cache/*.html
-rm -f lftp-cache/*.lftp
@echo "Cache cleaned"
clean:
@echo "Cleaning all generated files..."
-rm -f $(STAGE1_OUT)
-rm -f $(STAGE2_OUT)
-rm -f $(STAGE3_OUT)
@echo "All generated files cleaned"
.PHONY: all stage1 stage2 stage3 stage4 fetch list probe merge help init