friendly-bits / geoip-shell

User-friendly and flexible geoip blocker for Linux
GNU General Public License v3.0
92 stars 3 forks source link

[v0.5.7] Installation broken on Ubuntu server 22.04 hwe #16

Closed KD-MM2 closed 1 week ago

KD-MM2 commented 2 weeks ago
$ wget https://github.com/friendly-bits/geoip-shell/archive/refs/tags/v0.5.7.zip
$ unzip v0.5.7.zip
$ cd geoip-shell-0.5.7
$ sudo sh ./geoip-shell-install.sh

Creating backup of geoip-shell ip sets... Ok.
Creating backup of the status file... Ok.
Creating backup of the config file... Ok.
Successfully created backup of geoip-shell config, ip sets and firewall rules.

install: Cleaning up previous installation (if any)...
Deleting the iplist directory '/tmp/geoip-shell'...
Removing geoip-shell firewall rules... Ok.
Removing cron jobs...
Deleting geoip-shell main scripts from /usr/bin...
Deleting the library scripts directory '/usr/lib/geoip-shell'...
Uninstall complete.

Copying scripts to /usr/bin... Ok.
Copying library scripts to /usr/lib/geoip-shell... Ok.
Existing config file found. [K]eep previous config or [f]orget the old config? [k|f] or [a] to abort setup.
k|f|a: k
manage: Error: cron is not running.
manage: The cron service needs to be enabled and started in order for persistence and automatic ip list updates to work.
manage: If you want to use geoip-shell without persistence and automatic ip list updates,
manage: install/configure geoip-shell with options '-n' '-s disable'.

Would you like geoip-shell to enable and start the cron service on this device? [y|n].
y|n: y

Attempting to enable and start cron... Failed.
install: Error: geoip-shell-manage.sh exited with error code 1.

Downgrade to v0.5.6 installation done:

$ wget https://github.com/friendly-bits/geoip-shell/archive/refs/tags/v0.5.6.zip
$ unzip v0.5.6.zip
$ cd geoip-shell-0.5.6
$ sudo sh ./geoip-shell-install.sh

install: Cleaning up previous installation (if any)...
Uninstall complete.

Copying scripts to /usr/bin... Ok.
Copying library scripts to /usr/lib/geoip-shell... Ok.

Select geoip blocking mode: [w]hitelist or [b]lacklist, or [a] to abort.
w|b|a: w

Please enter country codes to include in geoip whitelist.
Country codes (2 letters) or [a] to abort: JP VN

Please enter your country code.
It will be used to check if your geoip settings may block your own country and warn you if so.
Country code (2 letters)/Enter to skip: JP

Does this machine have dedicated WAN network interface(s)? [y|n] or [a] to abort.
For example, a router or a virtual private server may have it.
A machine connected to a LAN behind a router is unlikely to have it.
It is important to answer this question correctly.
y|n|a: n

*NOTE*: In whitelist mode, traffic from your LAN subnets will be blocked, unless you whitelist them.
You can specify LAN subnets and/or individual ip's to allow.

Detecting ipv4 LAN subnets...

Autodetected ipv4 LAN subnets: '172.21.0.0/16 172.17.0.0/20 172.17.16.0/20 172.17.32.0/20 172.17.48.0/20 172.17.64.0/20 172.17.80.0/20 172.17.96.0/20 172.17.112.0/20 172.17.128.0/20 172.17.144.0/20 172.17.160.0/20 172.17.176.0/20 172.17.192.0/20 172.17.208.0/20 172.17.224.0/20 172.17.240.0/20 172.18.0.0/20 192.168.0.0/24'.
[c]onfirm, c[h]ange, [s]kip or [a]bort?
Verify that correct LAN subnets have been detected in order to avoid accidental lockout or other problems.
c|h|s|a: c

Detecting ipv6 LAN subnets...

Autodetected ipv6 LAN subnets: 'fd48:899a:6c49::/64 fe80::/64'.
[c]onfirm, c[h]ange, [s]kip or [a]bort?
Verify that correct LAN subnets have been detected in order to avoid accidental lockout or other problems.
c|h|s|a: c

A[u]to-detect LAN subnets when updating ip lists or keep this config c[o]nstant?
u|o: u
Creating the data directory '/var/lib/geoip-shell'... Ok.
manage: Applying config...

Checking connectivity... Ok.

Checking for ip list updates on the RIPE server...

Fetching ip list for country 'JP' from RIPE...
################################################################################################################################################################# 100.0%
Fetch successful.

Parsing ip list for 'JP_ipv4'... Ok.
Validating 'JP_ipv4'... Ok.
Validated subnets for 'JP_ipv4': 4625.

Parsing ip list for 'JP_ipv6'... Ok.
Validating 'JP_ipv6'... Ok.
Validated subnets for 'JP_ipv6': 745.

Fetching ip list for country 'VN' from RIPE...
################################################################################################################################################################# 100.0%
Fetch successful.

Parsing ip list for 'VN_ipv4'... Ok.
Validating 'VN_ipv4'... Ok.
Validated subnets for 'VN_ipv4': 1434.

Parsing ip list for 'VN_ipv6'... Ok.
Validating 'VN_ipv6'... Ok.
Validated subnets for 'VN_ipv6': 751.

Adding ip set 'JP_ipv4_2024-10-07_geoip-shell'... Ok.
Adding ip set 'JP_ipv6_2024-10-07_geoip-shell'... Ok.
Adding ip set 'VN_ipv4_2024-10-07_geoip-shell'... Ok.
Adding ip set 'VN_ipv6_2024-10-07_geoip-shell'... Ok.
Assembling nftables commands... Ok.
Applying new firewall rules... Ok.

run: Successfully executed action 'add' for ip lists 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6'.

manage: Successfully applied config.
Creating backup of geoip-shell ip sets... Ok.
Creating backup of the status file... Ok.
Creating backup of the config file... Ok.
Successfully created backup of geoip-shell config, ip sets and firewall rules.

Processing cron jobs... Ok.

Ip lists in the final whitelist: 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6'.

View geoip status with 'geoip-shell status' (may require 'sudo').

Install done.

$ sudo geoip-shell status
geoip-shell status:

geoip-shell v0.5.6

Firewall backend: nftables
Geoip blocking mode: whitelist
Ip lists source: ripe
Country codes in the whitelist: JP VN ✔
IP families in firewall rules: ipv4 ipv6 ✔
Geoip rules applied to network interfaces: all

Allowed LAN ip's:
ipv4: 172.17.0.0-172.18.15.255 172.21.0.0/16 192.168.0.0/24
ipv6: fd48:899a:6c49::/64 fe80::/64
LAN subnets automatic detection: On

Protocols:
tcp: Geoip is applied to all ports
udp: Geoip is applied to all ports

Geoip firewall chain: enabled ✔
Whitelist blocking rule: ✔

nftables sets optimization policy: performance

Cron system service: ✔
Update cron job: ✔
Update schedule: '14 4 * * *'
Last successful update: Oct-07-2024 04:05:35
Persistence cron job: ✔
Automatic backup of ip lists: On

No problems detected.
friendly-bits commented 1 week ago

Hi, thanks for you report.

Please download the current source code (not the release) and test with it. If still getting the error, please run: sh ./geoip-shell-install.sh -d

This will print debug messages which may help me understand what's failing - please post the output here.

KD-MM2 commented 1 week ago

Still failed with main branch, here is the -d outputs:

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-main$ sudo sh ./geoip-shell-install.sh -d
Started *INSTALL* with args: '-d' 
Debug: install: Detected init: 'systemd'.
install: Cleaning up previous installation (if any)...
Started *UNINSTALL* with args: '-r' 
Started *UNINSTALL* with args: '-r' 
Deleting geoip-shell main scripts from /usr/bin...
Deleting the library scripts directory '/usr/lib/geoip-shell'...
Uninstall complete.

Back to *UNINSTALL*...
Back to *INSTALL*...
Copying scripts to /usr/bin... Ok.
Copying library scripts to /usr/lib/geoip-shell... Ok.
Started *MANAGE* with args: 'configure' 
Existing config file found. [K]eep previous config or [f]orget the old config? [k|f] or [a] to abort setup.
k|f|a: k
Debug: manage: check_cron: $no_persist is 'false'. $cron_rv is ''.
Debug: manage: check_cron: Checking 'crond'
Debug: manage: check_cron: Checking 'fcron'
Debug: manage: check_cron: Checking 'cron'
Debug: manage: check_cron: returning '1'
manage: Error: cron is not running.
manage: The cron service needs to be enabled and started in order for persistence and automatic ip list updates to work.
manage: If you want to use geoip-shell without persistence and automatic ip list updates,
manage: install/configure geoip-shell with options '-n' '-s disable'.

Would you like geoip-shell to enable and start the cron service on this device? [y|n].
y|n: y

Attempting to enable and start cron... Debug: manage: check_cron_compat: trying to create empty crontab
Debug: manage: check_cron: $no_persist is 'false'. $cron_rv is ''.
Debug: manage: check_cron: Checking 'crond'
Debug: manage: check_cron: Checking 'fcron'
Debug: manage: check_cron: Checking 'cron'
Debug: manage: check_cron: returning '1'
Debug: manage: check_cron_compat: initsys is 'systemd'
Debug: manage: check_cron_compat: trying 'crond'
Unit crond.service could not be found.
Debug: manage: check_cron_compat: trying 'fcron'
Unit fcron.service could not be found.
Debug: manage: check_cron_compat: trying 'cron'
Debug: manage: check_cron: $no_persist is 'false'. $cron_rv is ''.
Debug: manage: check_cron: Checking 'crond'
Debug: manage: check_cron: Checking 'fcron'
Debug: manage: check_cron: Checking 'cron'
Debug: manage: check_cron: returning '1'
Failed.
Back to *INSTALL*...
install: Error: geoip-shell-manage.sh exited with error code 1.
KD-MM2 commented 1 week ago

And here is the -d flag output of 0.5.6:

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ sudo sh ./geoip-shell-install.sh -d
Started *INSTALL* with args: '-d' 
Started *BACKUP* with args: 'create-backup' 
Creating backup of geoip-shell ip sets... backup: Error: Config/status file '/var/lib/geoip-shell/status' is missing!
backup: Error: Failed to get config from '/var/lib/geoip-shell/status'.
backup: Error: Failed to back up geoip-shell ip sets.
Back to *INSTALL*...
Deleting the data directory '/var/lib/geoip-shell'...
install: Cleaning up previous installation (if any)...
Started *UNINSTALL* with args: '-r' 
Started *UNINSTALL* with args: '-r' 
Deleting geoip-shell main scripts from /usr/bin...
Deleting the library scripts directory '/usr/lib/geoip-shell'...
Uninstall complete.

Back to *UNINSTALL*...
Back to *INSTALL*...
Copying scripts to /usr/bin... Ok.
Copying library scripts to /usr/lib/geoip-shell... Ok.
Started *MANAGE* with args: 'configure' 
Existing config file found. [K]eep previous config or [f]orget the old config? [k|f] or [a] to abort setup.
k|f|a: k

Debug: manage: config action: 'reset'
manage: Applying config... 
Started *RUN* with args: 'add' '-l' 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6' '-o' 
Started *FETCH* with args: '-l' 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6' '-p' '/tmp/geoip-shell' '-s' '/var/lib/geoip-shell/status' '-u' 'ripe' 

Checking connectivity... Ok.

Checking for ip list updates on the RIPE server...

Debug: fetch: getting listing from url 'ftp.ripe.net/pub/stats/apnic'...
Debug: fetch: Processing the listing...
Debug: fetch: Got date from RIPE for 'JP_ipv4': '20241008'.
Debug: fetch: Got date from RIPE for 'JP_ipv6': '20241008'.
Debug: fetch: Got date from RIPE for 'VN_ipv4': '20241008'.
Debug: fetch: Got date from RIPE for 'VN_ipv6': '20241008'.
Debug: fetch: Previous subnets count for 'JP_ipv4' is 0.
Debug: fetch: Previous subnets count for 'JP_ipv6' is 0.
Debug: fetch: Previous subnets count for 'VN_ipv4' is 0.
Debug: fetch: Previous subnets count for 'VN_ipv6' is 0.
Debug: fetch: Previous subnets count for 'JP_ipv4' is 0.
Fetching ip list for country 'JP' from RIPE...
Debug: fetch: fetch command: curl -L -f --fail-early --retry 5 --connect-timeout 16 --progress-bar "https://stat.ripe.net/data/country-resource-list/data.json?v4_format=prefix&resource=JP" > "/tmp/geoip-shell_fetched-JP.tmp"
######################################################################################################################################################################### 100.0%
Fetch successful.

Parsing ip list for 'JP_ipv4'... Ok.
Validating 'JP_ipv4'... Ok.
Validated subnets for 'JP_ipv4': 4625.

Debug: fetch: Updating /tmp/geoip-shell/JP_ipv4.iplist... 
Debug: fetch: Previous subnets count for 'JP_ipv6' is 0.
Parsing ip list for 'JP_ipv6'... Ok.
Validating 'JP_ipv6'... Ok.
Validated subnets for 'JP_ipv6': 745.

Debug: fetch: Updating /tmp/geoip-shell/JP_ipv6.iplist... 
Debug: fetch: Previous subnets count for 'VN_ipv4' is 0.
Fetching ip list for country 'VN' from RIPE...
Debug: fetch: fetch command: curl -L -f --fail-early --retry 5 --connect-timeout 16 --progress-bar "https://stat.ripe.net/data/country-resource-list/data.json?v4_format=prefix&resource=VN" > "/tmp/geoip-shell_fetched-VN.tmp"
######################################################################################################################################################################### 100.0%
Fetch successful.

Parsing ip list for 'VN_ipv4'... Ok.
Validating 'VN_ipv4'... Ok.
Validated subnets for 'VN_ipv4': 1434.

Debug: fetch: Updating /tmp/geoip-shell/VN_ipv4.iplist... 
Debug: fetch: Previous subnets count for 'VN_ipv6' is 0.
Parsing ip list for 'VN_ipv6'... Ok.
Validating 'VN_ipv6'... Ok.
Validated subnets for 'VN_ipv6': 751.

Debug: fetch: Updating /tmp/geoip-shell/VN_ipv6.iplist... 
Back to *RUN*...
Started *APPLY* with args: 'add' '-l' 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6' 
Debug: apply: ip lists: ''
Debug: apply: loading the nft library...
Adding ip set 'JP_ipv4_2024-10-08_geoip-shell'... 
Debug: apply: ip count in the iplist file '/tmp/geoip-shell/JP_ipv4.iplist': 4626
Ok.
Debug: apply: elements in JP_ipv4_2024-10-08_geoip-shell: 2440
Adding ip set 'JP_ipv6_2024-10-08_geoip-shell'... 
Debug: apply: ip count in the iplist file '/tmp/geoip-shell/JP_ipv6.iplist': 746
Ok.
Debug: apply: elements in JP_ipv6_2024-10-08_geoip-shell: 618
Adding ip set 'VN_ipv4_2024-10-08_geoip-shell'... 
Debug: apply: ip count in the iplist file '/tmp/geoip-shell/VN_ipv4.iplist': 1435
Ok.
Debug: apply: elements in VN_ipv4_2024-10-08_geoip-shell: 881
Adding ip set 'VN_ipv6_2024-10-08_geoip-shell'... 
Debug: apply: ip count in the iplist file '/tmp/geoip-shell/VN_ipv6.iplist': 752
Ok.
Debug: apply: elements in VN_ipv6_2024-10-08_geoip-shell: 734
Assembling nftables commands... Started *DETECT-LAN* with args: 
Back to *APPLY*...
Started *DETECT-LAN* with args: 
Back to *APPLY*...
Debug: apply: ports_exp: 'skip', ports: 'skip'
Debug: apply: ports_exp: 'skip', ports: 'skip'
Debug: apply: counter val for 'ip saddr @JP_ipv4_2024-10-08_geoip-shell accept': ''
Debug: apply: counter val for 'ip6 saddr @JP_ipv6_2024-10-08_geoip-shell accept': ''
Debug: apply: counter val for 'ip saddr @VN_ipv4_2024-10-08_geoip-shell accept': ''
Debug: apply: counter val for 'ip6 saddr @VN_ipv6_2024-10-08_geoip-shell accept': ''
Debug: apply: counter val for 'drop comment "geoip-shell_whitelist_block"': ''
Ok.
Applying new firewall rules... Ok.

Back to *RUN*...
Debug: run: Verifying ip lists coherence...
Debug: run: Successfully verified ip lists coherence.
run: Successfully executed action 'add' for ip lists 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6'.

Debug: run: Skipping backup of current firewall state.
Back to *MANAGE*...
Debug: manage: Verifying ip lists coherence...
Debug: manage: Successfully verified ip lists coherence.
manage: Successfully applied config.
Started *BACKUP* with args: 'create-backup' 
Creating backup of geoip-shell ip sets... 
Debug: backup: JP_ipv4 backup length: 1220

Debug: backup: JP_ipv6 backup length: 618

Debug: backup: VN_ipv4 backup length: 441

Debug: backup: VN_ipv6 backup length: 734
Ok.
Debug: backup: Copying '/var/lib/geoip-shell/status' to '/var/lib/geoip-shell/backup.new/status.bak'
Creating backup of the status file... Ok.
Debug: backup: Copying '/etc/geoip-shell/geoip-shell.conf' to '/var/lib/geoip-shell/backup.new/geoip-shell.conf.bak'
Creating backup of the config file... Ok.
Successfully created backup of geoip-shell config, ip sets and firewall rules.

Back to *MANAGE*...
Started *CRONSETUP* with args: 
Processing cron jobs... 
Debug: cronsetup: Validating cron schedule: '14 4 * * *'.
Debug: cronsetup: Successfully validated cron schedule: '14 4 * * *'.
Debug: cronsetup: Removing update cron job for geoip-shell... 
Debug: cronsetup: Creating update cron job with schedule '14 4 * * *'... 
Debug: cronsetup: Creating persistence cron job... 
Ok.
Back to *MANAGE*...

Ip lists in the final whitelist: 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6'.

View geoip status with 'geoip-shell status' (may require 'sudo').

Back to *INSTALL*...
Install done.
KD-MM2 commented 1 week ago

Extra infos, I'm checked the cron's type of my system is running:

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ sudo crontab -l
14 4 * * * "/usr/bin/geoip-shell-run.sh" update -a 1>/dev/null 2>/dev/null # geoip-shell-update
@reboot "/usr/bin/geoip-shell-run.sh" restore -a 1>/dev/null 2>/dev/null # geoip-shell-persistence

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ sudo systemctl status cron.service 
● cron.service - Regular background program processing daemon
     Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2024-10-07 11:54:29 UTC; 1 day 1h ago
       Docs: man:cron(8)
   Main PID: 1477 (cron)
      Tasks: 1 (limit: 154281)
     Memory: 41.6M
        CPU: 851ms
     CGroup: /system.slice/cron.service
             └─1477 /usr/sbin/cron -f -P

Oct 08 12:00:01 dpt-t5810 CRON[1780756]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Oct 08 12:00:01 dpt-t5810 CRON[1780757]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Oct 08 12:00:01 dpt-t5810 CRON[1780756]: pam_unix(cron:session): session closed for user root
Oct 08 12:17:01 dpt-t5810 CRON[1803418]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Oct 08 12:17:01 dpt-t5810 CRON[1803419]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 08 12:17:01 dpt-t5810 CRON[1803418]: pam_unix(cron:session): session closed for user root
Oct 08 13:17:01 dpt-t5810 CRON[1884539]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Oct 08 13:17:01 dpt-t5810 CRON[1884540]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 08 13:17:01 dpt-t5810 CRON[1884539]: pam_unix(cron:session): session closed for user root
Oct 08 13:48:01 dpt-t5810 cron[1477]: (root) RELOAD (crontabs/root)

EDIT: Thanks for creating such a great tools, combined with crowdsec, I feel something safe(maybe not really) while my ports are exposed to the internet.

friendly-bits commented 1 week ago

Hi, thanks for the the followup and for the heads-up. I think the pgrep utility is missing on your system but let's verify this.

Please post the output of these commands (run as root or with sudo, just to make sure that the environment is set the same way as when running geoip-shell):

awk --version 2>&1 | head -n2
pidof cron
command -v cron && ls -l "$(command -v cron)"
dpkg -S pgrep
command -v pgrep && pgrep --version 2>&1 | head -n2
/usr/bin/pgrep --version 2>&1
pgrep -a cron && pgrep -a cron | awk -F' ' 'BEGIN{rv=1} {print $2; rv=0} END{exit rv}'; echo $?
KD-MM2 commented 1 week ago

Both root and without root are the same results:

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ awk --version 2>&1 | head -n2
GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)
Copyright (C) 1989, 1991-2020 Free Software Foundation.

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ pidof cron
6706 1477

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ command -v cron && ls -l "$(command -v cron)"
/usr/sbin/cron
-rwxr-xr-x 1 root root 51792 Mar 23  2022 /usr/sbin/cron

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ dpkg -S pgrep
unzip: /usr/share/man/man1/zipgrep.1.gz
procps: /usr/share/man/de/man1/pgrep.1.gz
procps: /usr/share/man/man1/pgrep.1.gz
procps: /usr/share/man/fr/man1/pgrep.1.gz
procps: /usr/share/man/uk/man1/pgrep.1.gz
bash-completion: /usr/share/bash-completion/completions/pgrep
procps: /usr/bin/pgrep
procps: /usr/share/man/sv/man1/pgrep.1.gz
unzip: /usr/bin/zipgrep

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ command -v pgrep && pgrep --version 2>&1 | head -n2
/usr/bin/pgrep
pgrep from procps-ng 3.3.17

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ /usr/bin/pgrep --version 2>&1
pgrep from procps-ng 3.3.17

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ pgrep -a cron && pgrep -a cron | awk -F' ' 'BEGIN{rv=1} {print $2; rv=0} END{exit rv}'; echo $?
1477 /usr/sbin/cron -f -P
4940 /usr/local/bin/go-cron -s @daily -p 8080 -- /backup.sh
6706 cron -f -L 15
9291 /bin/bash /cron.sh
10638 /bin/bash /cron.sh
/usr/sbin/cron
/usr/local/bin/go-cron
cron
/bin/bash
/bin/bash
0 

With root(entered root shell so the output mixed up):

kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell-0.5.6$ sudo su
root@dpt-t5810:/home/kaotd/selfhosted/_OTHERS/geoip-shell-0.5.6# awk --version 2>&1 | head -n2
pidof cron
command -v cron && ls -l "$(command -v cron)"
dpkg -S pgrep
command -v pgrep && pgrep --version 2>&1 | head -n2
/usr/bin/pgrep --version 2>&1
pgrep -a cron && pgrep -a cron | awk -F' ' 'BEGIN{rv=1} {print $2; rv=0} END{exit rv}'; echo $?
GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)
Copyright (C) 1989, 1991-2020 Free Software Foundation.
6706 1477
/usr/sbin/cron
-rwxr-xr-x 1 root root 51792 Mar 23  2022 /usr/sbin/cron
unzip: /usr/share/man/man1/zipgrep.1.gz
procps: /usr/share/man/de/man1/pgrep.1.gz
procps: /usr/share/man/man1/pgrep.1.gz
procps: /usr/share/man/fr/man1/pgrep.1.gz
procps: /usr/share/man/uk/man1/pgrep.1.gz
bash-completion: /usr/share/bash-completion/completions/pgrep
procps: /usr/bin/pgrep
procps: /usr/share/man/sv/man1/pgrep.1.gz
unzip: /usr/bin/zipgrep
/usr/bin/pgrep
pgrep from procps-ng 3.3.17
pgrep from procps-ng 3.3.17
1477 /usr/sbin/cron -f -P
4940 /usr/local/bin/go-cron -s @daily -p 8080 -- /backup.sh
6706 cron -f -L 15
9291 /bin/bash /cron.sh
10638 /bin/bash /cron.sh
/usr/sbin/cron
/usr/local/bin/go-cron
cron
/bin/bash
/bin/bash
0
friendly-bits commented 1 week ago

Thank you for the prompt responses. I see where the issue is - will let you know when it's fixed in the main branch (should be soon). Hope you will be able to test.

KD-MM2 commented 1 week ago

Ofcourse, my pleasure.

friendly-bits commented 1 week ago

Should be fixed in current 'main' branch.

KD-MM2 commented 1 week ago

SUPER ! It's worked, thank you so much(here are some logs):

kaotd@dpt-t5810:~/selfhosted/_OTHERS$ git clone https://github.com/friendly-bits/geoip-shell
Cloning into 'geoip-shell'...
remote: Enumerating objects: 4097, done.
remote: Counting objects: 100% (1455/1455), done.
remote: Compressing objects: 100% (461/461), done.
remote: Total 4097 (delta 1038), reused 1404 (delta 994), pack-reused 2642 (from 1)
Receiving objects: 100% (4097/4097), 938.20 KiB | 12.85 MiB/s, done.
Resolving deltas: 100% (2769/2769), done.
kaotd@dpt-t5810:~/selfhosted/_OTHERS$ cd geoip-shell
kaotd@dpt-t5810:~/selfhosted/_OTHERS/geoip-shell$ sudo sh ./geoip-shell-install.sh -d
[sudo] password for kaotd: 
Started *INSTALL* with args: '-d' 
Debug: install: Detected init: 'systemd'.
Started *BACKUP* with args: 'create-backup' 
Creating backup of geoip-shell ip sets... 
Debug: backup: JP_ipv4 backup length: 1220

Debug: backup: JP_ipv6 backup length: 618

Debug: backup: VN_ipv4 backup length: 441

Debug: backup: VN_ipv6 backup length: 734
Ok.
Debug: backup: Copying '/var/lib/geoip-shell/status' to '/var/lib/geoip-shell/backup.new/status.bak'
Creating backup of the status file... Ok.
Debug: backup: Copying '/etc/geoip-shell/geoip-shell.conf' to '/var/lib/geoip-shell/backup.new/geoip-shell.conf.bak'
Creating backup of the config file... Ok.
Successfully created backup of geoip-shell config, ip sets and firewall rules.

Back to *INSTALL*...
install: Cleaning up previous installation (if any)...
Started *UNINSTALL* with args: '-r' 
Started *UNINSTALL* with args: '-r' 
Deleting the iplist directory '/tmp/geoip-shell'...
Removing geoip-shell firewall rules... Ok.
Removing cron jobs...
Deleting geoip-shell main scripts from /usr/bin...
Deleting the library scripts directory '/usr/lib/geoip-shell'...
Uninstall complete.

Back to *UNINSTALL*...
Back to *INSTALL*...
Copying scripts to /usr/bin... Ok.
Copying library scripts to /usr/lib/geoip-shell... Ok.
Started *MANAGE* with args: 'configure' 
Existing config file found. [K]eep previous config or [f]orget the old config? [k|f] or [a] to abort setup.
k|f|a: k
Debug: manage: check_cron: $no_persist is 'false'. $cron_rv is ''.
Debug: manage: check_cron: Trying with 'pidof'...
Debug: manage: Checking 'crond'
Debug: manage: pidof didn't find 'crond'
Debug: manage: Checking 'fcron'
Debug: manage: pidof didn't find 'fcron'
Debug: manage: Checking 'cron'
Debug: manage: pidof found 'cron', path: '/usr/sbin/cron'
Debug: manage: check_cron: Found real path: '/usr/sbin/cron'.
Debug: manage: Detected non-Busybox cron.
Debug: manage: check_cron: returning '0'

Debug: manage: config action: 'restore'
Started *BACKUP* with args: 'restore' '-n' 
Preparing to restore geoip-shell from backup...
Restoring ip lists from backup... 
Debug: backup: Lines count in JP_ipv4 backup: 55791

Debug: backup: Lines count in JP_ipv6 backup: 15332

Debug: backup: Lines count in VN_ipv4 backup: 20662

Debug: backup: Lines count in VN_ipv6 backup: 18925
Ok.
Started *APPLY* with args: 'add' '-l' 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6' 
Debug: apply: ip lists: ''
Debug: apply: loading the nft library...
Adding ip set 'JP_ipv4_2024-10-08_geoip-shell'... 
Debug: apply: ip count in the iplist file '/tmp/geoip-shell/JP_ipv4.iplist': 2440
Ok.
Debug: apply: elements in JP_ipv4_2024-10-08_geoip-shell: 2440
Adding ip set 'JP_ipv6_2024-10-08_geoip-shell'... 
Debug: apply: ip count in the iplist file '/tmp/geoip-shell/JP_ipv6.iplist': 618
Ok.
Debug: apply: elements in JP_ipv6_2024-10-08_geoip-shell: 618
Adding ip set 'VN_ipv4_2024-10-08_geoip-shell'... 
Debug: apply: ip count in the iplist file '/tmp/geoip-shell/VN_ipv4.iplist': 881
Ok.
Debug: apply: elements in VN_ipv4_2024-10-08_geoip-shell: 881
Adding ip set 'VN_ipv6_2024-10-08_geoip-shell'... 
Debug: apply: ip count in the iplist file '/tmp/geoip-shell/VN_ipv6.iplist': 734
Ok.
Debug: apply: elements in VN_ipv6_2024-10-08_geoip-shell: 734
Assembling nftables commands... Started *DETECT-LAN* with args: 
Back to *APPLY*...
Started *DETECT-LAN* with args: 
Back to *APPLY*...
Debug: apply: ports_exp: 'skip', ports: 'skip'
Debug: apply: ports_exp: 'skip', ports: 'skip'
Debug: apply: counter val for 'ip saddr @JP_ipv4_2024-10-08_geoip-shell accept': 'packets 71 bytes 4335'
Debug: apply: counter val for 'ip6 saddr @JP_ipv6_2024-10-08_geoip-shell accept': 'packets 254 bytes 40788'
Debug: apply: counter val for 'ip saddr @VN_ipv4_2024-10-08_geoip-shell accept': 'packets 12 bytes 720'
Debug: apply: counter val for 'ip6 saddr @VN_ipv6_2024-10-08_geoip-shell accept': 'packets 0 bytes 0'
Debug: apply: counter val for 'drop comment "geoip-shell_whitelist_block"': 'packets 24100 bytes 3539803'
Ok.
Applying new firewall rules... Ok.

Back to *BACKUP*...
Successfully completed action 'restore'.

Back to *MANAGE*...
Debug: manage: Verifying ip lists coherence...
Debug: manage: Successfully verified ip lists coherence.
Started *CRONSETUP* with args: 
Processing cron jobs... Debug: cronsetup: check_cron: $no_persist is 'false'. $cron_rv is '0'.

Debug: cronsetup: Validating cron schedule: '14 4 * * *'.
Debug: cronsetup: Successfully validated cron schedule: '14 4 * * *'.
Debug: cronsetup: Removing update cron job for geoip-shell... 
Debug: cronsetup: Creating update cron job with schedule '14 4 * * *'... 
Debug: cronsetup: Creating persistence cron job... 
Ok.
Back to *MANAGE*...

Successfully configured geoip-shell for firewall backend: nftables.

Ip lists in the final whitelist: 'JP_ipv4 JP_ipv6 VN_ipv4 VN_ipv6'.

View geoip status with 'geoip-shell status' (may require 'sudo').

Back to *INSTALL*...
Install done.
friendly-bits commented 1 week ago

Great! Thank you for reporting and helping me fix the issue. Enjoy geoip-shell.