diff --git a/home/scripts/dns/dnsblock-norestart.sh b/home/scripts/dns/dnsblock-norestart.sh index a74f0a0..ad73e91 100755 --- a/home/scripts/dns/dnsblock-norestart.sh +++ b/home/scripts/dns/dnsblock-norestart.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash set -euo pipefail +if [[ $(id -u) -ne 0 ]]; then + echo "This script must be run as root." >&2 + exit 1 +fi OP=${1:-}; DOMAIN=${2:-} [[ $OP =~ ^(on|off)$ && -n $DOMAIN ]] || { echo "usage: dnsblock on|off "; exit 1; } @@ -7,10 +11,10 @@ OP=${1:-}; DOMAIN=${2:-} FILE="/var/lib/dnsmasq/conf.d/block-$DOMAIN.conf" if [[ $OP == on ]]; then - sudo tee "$FILE" >/dev/null </dev/null <> /home/synchronous/lol -websites=("www.reddit.com" "www.youtube.com" "www.instagram.com" "www.facebook.com" "facebook.com" "www.craigslist.org" "www.ebay.com" "www.monkeytype.com" "www.typeracer.com" "www.twitter.com" "www.linkedin.com") +if [[ "$should_block" == "false" ]]; then + exit 1 +fi + +websites=( + "www.reddit.com" + "www.youtube.com" + "www.instagram.com" + "www.facebook.com" + "facebook.com" + "www.craigslist.org" + "www.ebay.com" + "www.monkeytype.com" + "www.typeracer.com" + "www.twitter.com" + "www.linkedin.com" +) op="" if [ "$2" == "up" ]; then op="on" -elif ["$2" == "pre-down" ]; then +elif [ "$2" == "down" ]; then op="off" else - exit 1; + exit 0 fi -for website in ${websites[@]}; do - sh /etc/profiles/per-user/synchronous/bin/dnsblock-norestart "$op" "$website" - # grep -v "$website" /etc/hosts > "$tempHosts" - # mv "$tempHosts" /etc/hosts +for website in "${websites[@]}"; do + /run/current-system/sw/bin/bash /etc/profiles/per-user/synchronous/bin/dnsblock-norestart "$op" "$website" 2> /home/synchronous/lol done sudo systemctl restart dnsmasq