bin: properly use error codes

This commit is contained in:
xerus2000 2021-04-02 20:57:58 +02:00
parent e7dc791b98
commit e4f422899e
3 changed files with 19 additions and 12 deletions

View File

@ -1,3 +1,4 @@
#!/bin/sh
set -o pipefail
# interactive diff with pagination
diff --color=always --report-identical-files -U 2 "$@" | less --quit-if-one-screen

View File

@ -1,4 +1,6 @@
#!/bin/sh
set -e
dif "$(st-unarchive "$1")" "$@"
echo "y to restore"
read answer

View File

@ -1,20 +1,24 @@
#!/bin/sh
test "$EUID" -eq 0 || exec sudo "$0" "$@"
set -e
# https://askubuntu.com/a/124512 and https://blog.sleeplessbeastie.eu/2018/06/21/how-to-create-iptables-firewall-using-custom-chains/
sudo iptables --new-chain chain-times 2>/dev/null || sudo iptables --flush chain-times
iptables --new-chain chain-times 2>/dev/null || iptables --flush chain-times
# Always allow local connections - https://serverfault.com/a/550278
sudo iptables -A chain-times -m owner --uid-owner janek -d 192.168.1.0/24 -j ACCEPT
sudo iptables -A chain-times -m owner --uid-owner janek -d 127.0.0.0/8 -j ACCEPT
iptables -A chain-times -m owner --uid-owner janek -d 192.168.1.0/24 -j ACCEPT
iptables -A chain-times -m owner --uid-owner janek -d 127.0.0.0/8 -j ACCEPT
time9=$(date -u -d "$(date -d 09:00)" +%k)
sudo iptables -A chain-times -m owner --uid-owner janek -j DROP -m time \
--timestart $(date -u -d "$(date -d "${1:-15 min}")" +%k:%M) --timestop $time9:00
sudo iptables -A chain-times -m owner --uid-owner janek -j DROP -m time --weekdays 1-5 \
--timestart $time9:20 --timestop $(expr $time9 + 1):00
sudo iptables -A chain-times -m owner --uid-owner janek -j DROP -m time --weekdays 1-5 \
--timestart $(expr $time9 + 1):20 --timestop $(expr $time9 + 2):00
iptables -A chain-times -m owner --uid-owner janek -j DROP -m time \
--timestart $(date -u -d "$(date -d "${1:-15 min}")" +%k:%M) --timestop $(expr $time9 - 2):00
# Only allow periodical internet access in the morning
#iptables -A chain-times -m owner --uid-owner janek -j DROP -m time --weekdays 1-5 \
# --timestart $time9:20 --timestop $(expr $time9 + 1):00
#iptables -A chain-times -m owner --uid-owner janek -j DROP -m time --weekdays 1-5 \
# --timestart $(expr $time9 + 1):20 --timestop $(expr $time9 + 2):00
sudo iptables -L OUTPUT | grep -q "^chain-times" || sudo iptables -A OUTPUT -j chain-times
iptables -L OUTPUT | grep -q "^chain-times" || iptables -A OUTPUT -j chain-times
if test "$2" = "--save"; then
sudo iptables-save | sudo tee /etc/iptables/walli.rules
echo "@reboot root $(which iptables-restore) < /etc/iptables/walli.rules" | sudo tee /etc/cron.d/iptables-times
iptables-save | tee /etc/iptables/walli.rules
echo "@reboot root $(which iptables-restore) < /etc/iptables/walli.rules" | tee /etc/cron.d/iptables-times
fi