From c8d6ca21955c2194fa482dc509765ad88ec7ff7f Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Sat, 26 Oct 2024 22:40:02 +0300 Subject: [PATCH] feat: generate-nginx.sh --- README.md | 4 ++++ generate-nginx.sh | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 generate-nginx.sh diff --git a/README.md b/README.md index 09fc91d..b099d23 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,7 @@ robots.txt generation. * arg $1 is a required path to the out file * arg $2 is an optional path to a base file +`generate-nginx.sh` is a bash script for generating an nginx if block to block +user agents at that level: + * prints out an if block with every user agent in the lists + diff --git a/generate-nginx.sh b/generate-nginx.sh new file mode 100755 index 0000000..002e4c2 --- /dev/null +++ b/generate-nginx.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +out="if (\$http_user_agent ~* \"" + +# loop lists +for filename in ./lists/*.txt; do + # line by line + while read -r line; do + # ignore empty + [ -z "$line" ] && continue + # ignore comments + [[ $line =~ ^#.* ]] && continue + + # add to out + out="$out$line|" + done < $filename +done + +out=${out::-1} +out="$out\") {\n return 403;\n}\n" + +printf "$out" -- 2.44.1