Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Looking for feedback on bash scripts used for geoblocking

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
benzine
Posts: 11
Joined: 2023-05-26 19:22
Has thanked: 1 time

Looking for feedback on bash scripts used for geoblocking

#1 Post by benzine »

Hi all,

I wrote a collection of 7 scripts (3 of them I actually adopted from other sources and then modified). The idea is a simple bash implementation of an automatic geoblocker based on a whitelist that would work on my Debian server.

I am not a professional coder, so I'm looking to hear feedback on the scripts. So far they seem to do the job for me. I want them to be publicly available for other people to use as well, so I'm mainly concerned about how they will work in other environments.

Comments and testing would be appreciated.

The scripts are hosted on Github:
https://github.com/blunderful-scripts/geoblocker_bash
Last edited by benzine on 2023-05-27 05:44, edited 1 time in total.

benzine
Posts: 11
Joined: 2023-05-26 19:22
Has thanked: 1 time

Re: Looking for feedback on bash scripts used for geoblocking

#2 Post by benzine »

P.s. currently I can't reply to private messages (because I'm new to the forum), but you are more than welcome to discuss the code here.
@bw123

Aki
Global Moderator
Global Moderator
Posts: 2816
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 68 times
Been thanked: 382 times

Re: Looking for feedback on bash scripts used for geoblocking

#3 Post by Aki »

@benzine: it could be useful to check the scripts with shellcheck [1] for example:

Code: Select all

$ su -l -c "apt install shellcheck"
$ git clone https://github.com/blunderful-scripts/geoblocker_bash
$ cd geoblocker_bash
$ shellcheck *.sh
[1] https://packages.debian.org/bullseye/shellcheck;
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

benzine
Posts: 11
Joined: 2023-05-26 19:22
Has thanked: 1 time

Re: Looking for feedback on bash scripts used for geoblocking

#4 Post by benzine »

Aki wrote: 2023-05-27 14:51 @benzine: it could be useful to check the scripts with shellcheck [1] for example:

Code: Select all

$ su -l -c "apt install shellcheck"
$ git clone https://github.com/blunderful-scripts/geoblocker_bash
$ cd geoblocker_bash
$ shellcheck *.sh
[1] https://packages.debian.org/bullseye/shellcheck;
Thanks, I'll try that.

Random_Troll
Posts: 444
Joined: 2023-02-07 13:35
Been thanked: 105 times

Re: Looking for feedback on bash scripts used for geoblocking

#5 Post by Random_Troll »

Even the sid version is almost a year and a half old.

Use the web interface instead, that's always the latest version:

https://www.shellcheck.net/

The certificate has just ran out but I'm sure they'll fix that soon.
Jeder nach seinen Fähigkeiten, jedem nach seinen Bedürfnissen.

benzine
Posts: 11
Joined: 2023-05-26 19:22
Has thanked: 1 time

Re: Looking for feedback on bash scripts used for geoblocking

#6 Post by benzine »

Random_Troll wrote: 2023-05-28 09:07
Even the sid version is almost a year and a half old.

Use the web interface instead, that's always the latest version:

https://www.shellcheck.net/

The certificate has just ran out but I'm sure they'll fix that soon.
Thanks, good suggestion. The shellcheck's website pointed me to codefactor.io which allows to automatically check the whole repo with shellcheck. Actually found and fixed a few minor bugs with its help.

benzine
Posts: 11
Joined: 2023-05-26 19:22
Has thanked: 1 time

Re: Looking for feedback on bash scripts used for geoblocking

#7 Post by benzine »

Actually putting the code directly into shellcheck website interface revealed some more bugs (mostly stylistic but a couple real bugs as well) which codefactor.io didn't mention.

Aki
Global Moderator
Global Moderator
Posts: 2816
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 68 times
Been thanked: 382 times

Re: Looking for feedback on bash scripts used for geoblocking

#8 Post by Aki »

Random_Troll wrote: 2023-05-28 09:07
Even the sid version is almost a year and a half old.
@Random_Troll: the current testing and sid versions of shellcheck are the same 0.9.0-1 [1]. The git repository [2] cited in https://www.shellcheck.net/ refers to version 0.9.0 . Is there a more freshly updated version of shellcheck ?

@benzine: what is the Debian version you are running ?

---
[1] https://tracker.debian.org/pkg/shellcheck
[2] https://github.com/koalaman/shellcheck
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

Random_Troll
Posts: 444
Joined: 2023-02-07 13:35
Been thanked: 105 times

Re: Looking for feedback on bash scripts used for geoblocking

#9 Post by Random_Troll »

Aki wrote: 2023-05-30 06:30Is there a more freshly updated version of shellcheck ?
I think the website uses the latest commits from the GitHub repository rather than the release version.
Jeder nach seinen Fähigkeiten, jedem nach seinen Bedürfnissen.

benzine
Posts: 11
Joined: 2023-05-26 19:22
Has thanked: 1 time

Re: Looking for feedback on bash scripts used for geoblocking

#10 Post by benzine »

Aki wrote: 2023-05-30 06:30 @benzine: what is the Debian version you are running ?
@Aki I'm still on Stretch... why?

Aki
Global Moderator
Global Moderator
Posts: 2816
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 68 times
Been thanked: 382 times

Re: Looking for feedback on bash scripts used for geoblocking

#11 Post by Aki »

benzine wrote: 2023-06-01 00:15
Aki wrote: 2023-05-30 06:30 @benzine: what is the Debian version you are running ?
@Aki I'm still on Stretch... why?
@benzine: Debian repository hosts different version of distributed packages according to the Debian Release (for example, see https://tracker.debian.org/pkg/shellcheck). I was looking for the shellcheck version distributed with your Debian installed release that is probably much older the current Debian Testing (next Debian Stable on june 10th) release. That's probably why the on line version of shellcheck suggested more corrections or warnings.
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

Post Reply