diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 632f473..587422d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,32 +2,8 @@ image: alpine pages: script: -# Install required packages - - apk add --no-cache curl file gawk grep libidn sed zip -# Create public folder - - mkdir ./public -# Create hosts file - - sh ./hblock -O ./public/hosts -# Create a gzipped version of hosts file - - gzip -c ./public/hosts > ./public/hosts.gz -# Create Android installer - - mkdir /tmp/hosts_android - - cp -r ./resources/android/* ./public/hosts /tmp/hosts_android - - cd /tmp/hosts_android - - zip -r "$CI_PROJECT_DIR"/public/hosts_android.zip ./ - - cd "$CI_PROJECT_DIR" -# Create Windows installer - - mkdir /tmp/hosts_windows - - cp -r ./resources/windows/* ./public/hosts /tmp/hosts_windows - - cd /tmp/hosts_windows - - unix2dos ./install.bat ./hosts - - zip -r "$CI_PROJECT_DIR"/public/hosts_windows.zip ./ - - cd "$CI_PROJECT_DIR" -# Create stats files - - ./resources/stats/suffix.sh ./public/hosts none > ./public/most_abused_tlds.txt - - ./resources/stats/suffix.sh ./public/hosts > ./public/most_abused_suffixes.txt -# Create HTML index - - ./resources/template/index.sh ./public > ./public/index.html + - apk add --no-cache curl file gawk grep libidn make sed zip + - make all artifacts: paths: - public diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..75ae741 --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +#!/usr/bin/make -f + +RESOURCES_DIR:=$(CURDIR)/resources +PUBLIC_DIR:=$(CURDIR)/public +TEMP_DIR:=$(shell mktemp -dt 'hblock.XXXXXXXX') + +HBLOCK_SCRIPT:=$(CURDIR)/hblock +STATS_SCRIPT:=$(RESOURCES_DIR)/stats/suffix.sh +TEMPLATE_SCRIPT:=$(RESOURCES_DIR)/templates/index.sh + +.PHONY: DEFAULT all \ + build build-hosts build-gz build-android build-windows \ + stats stats-tlds stats-suffixes \ + index \ + clean + +DEFAULT: all + +all: clean build stats index + +build: build-hosts build-gz build-android build-windows + +build-hosts: + mkdir -p "$(PUBLIC_DIR)" + "$(HBLOCK_SCRIPT)" -O "$(PUBLIC_DIR)"/hosts + +build-gz: build-hosts + gzip -c "$(PUBLIC_DIR)"/hosts > "$(PUBLIC_DIR)"/hosts.gz + +build-android: build-hosts + mkdir -p "$(TEMP_DIR)"/android + cp -r "$(RESOURCES_DIR)"/android/* "$(PUBLIC_DIR)"/hosts "$(TEMP_DIR)"/android + cd "$(TEMP_DIR)"/android && zip -r "$(PUBLIC_DIR)"/hosts_android.zip . + +build-windows: build-hosts + mkdir -p "$(TEMP_DIR)"/windows + cp -r "$(RESOURCES_DIR)"/windows/* "$(PUBLIC_DIR)"/hosts "$(TEMP_DIR)"/windows + unix2dos "$(TEMP_DIR)"/windows/install.bat "$(TEMP_DIR)"/windows/hosts + cd "$(TEMP_DIR)"/windows && zip -r "$(PUBLIC_DIR)"/hosts_windows.zip . + +stats: stats-tlds stats-suffixes + +stats-tlds: build-hosts + "$(STATS_SCRIPT)" "$(PUBLIC_DIR)"/hosts none > "$(PUBLIC_DIR)"/most_abused_tlds.txt + +stats-suffixes: build-hosts + "$(STATS_SCRIPT)" "$(PUBLIC_DIR)"/hosts > "$(PUBLIC_DIR)"/most_abused_suffixes.txt + +index: build-hosts + "$(TEMPLATE_SCRIPT)" "$(PUBLIC_DIR)" > "$(PUBLIC_DIR)"/index.html + +clean: + rm -rf "$(PUBLIC_DIR)" + diff --git a/resources/template/index.sh b/resources/templates/index.sh similarity index 100% rename from resources/template/index.sh rename to resources/templates/index.sh