From 8b6958162ee30feb2eb91dfd02672f618029557e Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sun, 4 Jul 2021 18:32:06 +0200 Subject: [PATCH] bin: separate and improve cleanbrowsing scripts --- .config/shell/functions | 15 --------------- .local/bin/scripts/browse-safe | 11 +++++++++++ .local/bin/scripts/browse-unsafe | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 15 deletions(-) create mode 100755 .local/bin/scripts/browse-safe create mode 100755 .local/bin/scripts/browse-unsafe diff --git a/.config/shell/functions b/.config/shell/functions index 46cfc3e..365af5d 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -145,21 +145,6 @@ alias lar='last | tac' # Listen to loopback of mic alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback' -alias browse-safe='sudo systemctl disable --now systemd-resolved && sudo rm -f /etc/resolv.conf && echo "nameserver 185.228.168.10" | sudo tee /etc/resolv.conf && sudo chattr +i /etc/resolv.conf' -browse-unsafe() { - echo "Why do you want to browse unsafe?" - while test ${#intention} -lt 10 - do read intention - done - jrnl intentions-nug "$intention" - trap 'echo Browsing safe; browse-safe' INT - sudo chattr -i /etc/resolv.conf && - sudo mv /etc/resolv.conf /etc/resolv.conf.bak && - sudo systemctl enable --now systemd-resolved && - sleep ${1:-100} - browse-safe -} - xo() { while test $# -gt 0; do xdg-open "$1" diff --git a/.local/bin/scripts/browse-safe b/.local/bin/scripts/browse-safe new file mode 100755 index 0000000..d2afd7a --- /dev/null +++ b/.local/bin/scripts/browse-safe @@ -0,0 +1,11 @@ +#!/bin/sh +# Replace systemd-resolved with the Adult Filter DNS of https://cleanbrowsing.org/filters +set -e +sudo systemctl disable --now systemd-resolved +resolvconf="/etc/resolv.conf" +dns="nameserver 185.228.168.10 +nameserver 185.228.169.11" +test "$(cat "$resolvconf" 2>/dev/null)" = "$dns" && exit 0 +test -f "$resolvconf" && sudo chattr -i "$resolvconf" && sudo rm -vf "$resolvconf" +echo "$dns" | sudo tee "$resolvconf" +sudo chattr +i "$resolvconf" diff --git a/.local/bin/scripts/browse-unsafe b/.local/bin/scripts/browse-unsafe new file mode 100755 index 0000000..a1e4222 --- /dev/null +++ b/.local/bin/scripts/browse-unsafe @@ -0,0 +1,15 @@ +#!/bin/sh +# Temporarily disable cleanbrowsing +echo "Why do you want to browse unsafe?" +while test ${#intention} -lt 10 +do read intention +done +jrnl intentions-nug "$intention" +trap 'echo Cancelling unsafe browsing && browse-safe; exit $?' INT +test -f "/etc/resolv.conf" && + sudo chattr -i /etc/resolv.conf && + sudo mv /etc/resolv.conf /etc/resolv.conf.bak +sudo systemctl enable --now systemd-resolved +sleep ${1:-100} +echo "Ending unsafe browsing" +browse-safe