2023-02-01 12:45:33 -08:00
|
|
|
{{- if eq .host.distro.family "linux" -}}
|
2023-01-27 01:28:02 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-02-01 13:09:14 -08:00
|
|
|
# jail.local hash: {{- include (joinPath .host.home ".ssh" "fail2ban" "jail.local") | sha256sum -}}
|
2023-01-27 01:28:02 -08:00
|
|
|
|
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
|
|
{{ includeTemplate "universal/logg" }}
|
|
|
|
|
|
|
|
### Restart fail2ban
|
|
|
|
function restartFail2Ban() {
|
|
|
|
if [ -d /Applications ] && [ -d /System ]; then
|
|
|
|
# macOS
|
|
|
|
logg info 'Enabling the `fail2ban` Homebrew service'
|
|
|
|
brew services start fail2ban
|
|
|
|
else
|
|
|
|
# Linux
|
|
|
|
logg info 'Enabling the `fail2ban` service'
|
|
|
|
sudo systemctl enable fail2ban
|
|
|
|
logg info 'Restarting the `fail2ban` service'
|
|
|
|
sudo systemctl restart fail2ban
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
### Update the jail.local file if environment is not WSL
|
|
|
|
if [[ ! "$(grep Microsoft /proc/version)" ]]; then
|
|
|
|
if [ -d /etc/fail2ban ]; then
|
|
|
|
logg info 'Copying ~/.ssh/fail2ban/jail.local to /etc/fail2ban/jail.local'
|
|
|
|
sudo cp -f "$HOME/.ssh/fail2ban/jail.local" /etc/fail2ban/jail.local
|
|
|
|
restartFail2Ban
|
|
|
|
elif [ -d /usr/local/etc/fail2ban ]; then
|
|
|
|
logg info 'Copying ~/.ssh/fail2ban/jail.local to /usr/local/etc/fail2ban/jail.local'
|
|
|
|
sudo cp -f "$HOME/.ssh/fail2ban/jail.local" /usr/local/etc/fail2ban/jail.local
|
|
|
|
restartFail2Ban
|
|
|
|
else
|
|
|
|
logg warn 'Both the /etc/fail2ban (Linux) and the /usr/local/etc/fail2ban (macOS) folder do not exist'
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
logg info 'Skipping sshd_config application since environment is WSL'
|
|
|
|
fi
|
|
|
|
|
|
|
|
{{ end -}}
|