masonr / yet-another-bench-script

YABS - a simple bash script to estimate Linux server performance using fio, iperf3, & Geekbench
Do What The F*ck You Want To Public License
4.22k stars 430 forks source link

How did you implement the yabs.sh website redirect? #39

Closed TheBestPessimist closed 2 years ago

TheBestPessimist commented 2 years ago

Hey, I see that running wget -vO- yabs.sh does a redirect to the raw github link, however opening yabs.sh directly in the browser does a redirect to the repo. Running in powershell on windows also redirects to normal github repo, not the raw page.

Do you use wget's user agent as discriminator or what else? Is there a repo showing this setup?

Thanks

masonr commented 2 years ago

Hey there!

Yes -- I'm using nginx and detecting the user agent that's initiating the request. Here is the complete config, nothing fancy:

server {
        listen 80;
        server_name yabs.sh;

        if ( $http_user_agent ~ 'curl' ) {
                return 301 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/yabs.sh;
        }

        if ( $http_user_agent ~ 'Wget' ) {
                return 301 https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/yabs.sh;
        }

        return 301 https://github.com/masonr/yet-another-bench-script;
}

Let me know if you have any other questions.

Cheers, -Mason